chainguard-dev/rules_apko

Can't build simple image on my Mac M1

Closed this issue · 4 comments

farcop commented

alpine.yaml

contents:
  repositories:
    - https://dl-cdn.alpinelinux.org/alpine/edge/main
    - https://dl-cdn.alpinelinux.org/alpine/edge/community
  packages:
    - ca-certificates 
    - libc6-compat 
    - git 
    - less 
    - openssh 
    - jq 
    - unzip 
    - curl 
    - cdrkit 
    - ethtool 
    - openssl

archs:
  - arm64
  - amd64

WORKSPACE

http_archive(
    name = "rules_apko",
    sha256 = "6ddc0bf6ba395c3aa7138cdb8726b1aa816ed0ae208a317edfadbfe1f9f10642",
    strip_prefix = "rules_apko-main",
    urls = ["https://github.com/chainguard-dev/rules_apko/archive/refs/heads/main.zip"],
)

load("@rules_apko//apko:repositories.bzl", "apko_register_toolchains")

apko_register_toolchains(name = "apko")

BUILD file

load("@rules_apko//apko:defs.bzl", "apko_image")

apko_image(
    name = "base",
    config = "alpine.yaml",
    tag = "alpine:latest",
)

bazel build fails with some strange cache folders structure

ℹ️  x86_64    | image configuration:
ℹ️  x86_64    |   contents:
ℹ️  x86_64    |     repositories: [https://dl-cdn.alpinelinux.org/alpine/edge/main https://dl-cdn.alpinelinux.org/alpine/edge/community]
ℹ️  x86_64    |     keyring:      []
ℹ️  x86_64    |     packages:     [ca-certificates libc6-compat git less openssh jq unzip curl cdrkit ethtool openssl]
ℹ️  x86_64    | synchronizing with desired apk world
ℹ️  x86_64    | determining desired apk world
Error: failed to build layer image for "arm64": installing apk packages: error getting package dependencies: error getting repository indexes: unable to get repository index at https://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz: Get "https://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz": listing "bazel-out/darwin_arm64-fastbuild/bin/images/alpine/cache_base/https%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fcommunity/aarch64/APKINDEX" for offline cache: open bazel-out/darwin_arm64-fastbuild/bin/images/alpine/cache_base/https%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fcommunity/aarch64/APKINDEX: no such file or directory
2023/09/15 12:15:43 error during command execution: failed to build layer image for "arm64": installing apk packages: error getting package dependencies: error getting repository indexes: unable to get repository index at https://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz: Get "https://dl-cdn.alpinelinux.org/alpine/edge/community/aarch64/APKINDEX.tar.gz": listing "bazel-out/darwin_arm64-fastbuild/bin/images/alpine/cache_base/https%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fcommunity/aarch64/APKINDEX" for offline cache: open bazel-out/darwin_arm64-fastbuild/bin/images/alpine/cache_base/https%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fcommunity/aarch64/APKINDEX: no such file or directory
Target //images/alpine:base failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.833s, Critical Path: 0.76s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

Yeah, you are not passing the prefetched contents to apko_image. Basically, a lockfile, that is passed to translate_lock extension like this

In order to generate the lock file you need apko resolve command which is not yet implemented. you can use this hacky bash script instead but it will only generate entries for packages, you still need to add contents.repositories manually.

apko.lock.json.zip
this is the lockfile you need based on your apko.yaml file.

farcop commented

@thesayyn Thank you for the clarification!
With this lock-file I get error with checksum:

INFO: Repository alpine_lock_libbz2_aarch64_1.0.8-r6 instantiated at:
  /Users/farcop/Sources/kublr/WORKSPACE:408:18: in <toplevel>
  /private/var/tmp/_bazel_farcop/e66529431dbede3bc951f821053136ab/external/alpine_lock/repositories.bzl:76:15: in apko_repositories
Repository rule apk_import defined at:
  /private/var/tmp/_bazel_farcop/e66529431dbede3bc951f821053136ab/external/rules_apko/apko/private/apk.bzl:57:29: in <toplevel>
WARNING: Download from https://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/libbz2-1.0.8-r6.apk#_apk_range_bytes_0-662 failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Checksum was 387613963132acce64d6210bf5a88b0c1522740d13e80060404f091260088038 but wanted 64383a82b0f4692eb49558cbc27f6641098a02429b3f36efe9ca7cd27f78f0d6