chainguard-dev / melange

build APKs from source code
Apache License 2.0
412 stars 95 forks source link

armv7 simple-hello fails with `chroot: can't execute '/bin/busybox': Exec format error` #127

Open benmoss opened 1 year ago

benmoss commented 1 year ago

Running from https://github.com/chainguard-dev/melange/tree/9e7b082649e3e36b81dfb84514c733e89ae8b494/examples/simple-hello

docker run --privileged --rm -v "${PWD}":/work   cgr.dev/chainguard/melange build melange.yaml   --arch armv7   --signing-key melange.rsa
2022/09/28 14:13:02 building for [arm/v7]
2022/09/28 14:13:02 melange (hello/armv7): melange is building:
2022/09/28 14:13:02 melange (hello/armv7):   configuration file: melange.yaml
2022/09/28 14:13:02 melange (hello/armv7):   workspace dir: /tmp/melange-workspace-2193273048
2022/09/28 14:13:02 melange (hello/armv7): evaluating pipelines for package requirements
2022/09/28 14:13:02 melange (hello/armv7):   adding package "make" for pipeline "Run autoconf make"
2022/09/28 14:13:02 melange (hello/armv7):   adding package "make" for pipeline "Run autoconf make install"
2022/09/28 14:13:02 melange (hello/armv7):   adding package "binutils" for pipeline "Strip binaries"
2022/09/28 14:13:02 melange (hello/armv7):   adding package "scanelf" for pipeline "Strip binaries"
2022/09/28 14:13:02 melange (hello/armv7): building workspace in '/tmp/melange-guest-3090450258' with apko
Sep 28 14:13:02.480 [INFO] [arch:armv7] build context:
Sep 28 14:13:02.480 [INFO] [arch:armv7]   working directory: /tmp/melange-guest-3090450258
Sep 28 14:13:02.480 [INFO] [arch:armv7]   tarball path: 
Sep 28 14:13:02.480 [INFO] [arch:armv7]   use proot: false
Sep 28 14:13:02.480 [INFO] [arch:armv7]   source date: 0001-01-01 00:00:00 +0000 UTC
Sep 28 14:13:02.480 [INFO] [arch:armv7]   Docker mediatypes: false
Sep 28 14:13:02.480 [INFO] [arch:armv7]   SBOM output path: 
Sep 28 14:13:02.480 [INFO] [arch:armv7]   arch: armv7
Sep 28 14:13:02.480 [INFO] [arch:armv7] image configuration:
Sep 28 14:13:02.480 [INFO] [arch:armv7]   contents:
Sep 28 14:13:02.480 [INFO] [arch:armv7]     repositories: [https://dl-cdn.alpinelinux.org/alpine/edge/main]
Sep 28 14:13:02.480 [INFO] [arch:armv7]     keyring:      []
Sep 28 14:13:02.480 [INFO] [arch:armv7]     packages:     [alpine-baselayout-data binutils build-base busybox ca-certificates-bundle make scanelf ssl_client]
Sep 28 14:13:02.480 [INFO] [arch:armv7]   accounts:
Sep 28 14:13:02.480 [INFO] [arch:armv7]     runas:  
Sep 28 14:13:02.480 [INFO] [arch:armv7]     users:
Sep 28 14:13:02.480 [INFO] [arch:armv7]       - uid=1000(build) gid=1000
Sep 28 14:13:02.480 [INFO] [arch:armv7]     groups:
Sep 28 14:13:02.480 [INFO] [arch:armv7]       - gid=1000(build) members=[build]
Sep 28 14:13:02.480 [INFO] [arch:armv7] doing pre-flight checks
Sep 28 14:13:02.480 [INFO] [arch:armv7] building image fileystem in /tmp/melange-guest-3090450258
Sep 28 14:13:02.480 [INFO] [arch:armv7] initializing apk database
Sep 28 14:13:02.480 [INFO] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] running: /sbin/apk add --initdb --arch armv7 --root /tmp/melange-guest-3090450258
Sep 28 14:13:02.483 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] OK: 0 MiB in 0 packages
Sep 28 14:13:02.484 [INFO] [arch:armv7] initializing apk world
Sep 28 14:13:02.484 [INFO] [arch:armv7] initializing apk keyring
Sep 28 14:13:02.484 [DEBUG] [arch:armv7] installing key /usr/share/apk/keys/armv7/alpine-devel@lists.alpinelinux.org-616adfeb.rsa.pub
Sep 28 14:13:02.484 [INFO] [arch:armv7] initializing apk repositories
Sep 28 14:13:02.484 [DEBUG] [arch:armv7] installing key /usr/share/apk/keys/armv7/alpine-devel@lists.alpinelinux.org-524d27bb.rsa.pub
Sep 28 14:13:02.484 [INFO] [arch:armv7] synchronizing with desired apk world
Sep 28 14:13:02.484 [INFO] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] running: /sbin/apk fix --root /tmp/melange-guest-3090450258 --no-scripts --no-cache --update-cache --arch armv7
Sep 28 14:13:02.487 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] fetch https://dl-cdn.alpinelinux.org/alpine/edge/main/armv7/APKINDEX.tar.gz
Sep 28 14:13:02.947 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (1/29) Installing alpine-baselayout-data (3.3.0-r2)
Sep 28 14:13:02.981 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (2/29) Installing musl (1.2.3-r1)
Sep 28 14:13:03.045 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (3/29) Installing libgcc (12.1.1_git20220630-r6)
Sep 28 14:13:03.066 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (4/29) Installing libstdc++ (12.1.1_git20220630-r6)
Sep 28 14:13:03.191 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (5/29) Installing zlib (1.2.12-r3)
Sep 28 14:13:03.218 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (6/29) Installing binutils (2.39-r2)
Sep 28 14:13:03.455 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (7/29) Installing libmagic (5.42-r0)
Sep 28 14:13:03.519 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (8/29) Installing file (5.42-r0)
Sep 28 14:13:03.543 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (9/29) Installing libgomp (12.1.1_git20220630-r6)
Sep 28 14:13:03.576 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (10/29) Installing libatomic (12.1.1_git20220630-r6)
Sep 28 14:13:03.599 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (11/29) Installing gmp (6.2.1-r2)
Sep 28 14:13:03.660 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (12/29) Installing isl25 (0.25-r0)
Sep 28 14:13:03.805 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (13/29) Installing mpfr4 (4.1.0-r0)
Sep 28 14:13:03.855 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (14/29) Installing mpc1 (1.2.1-r1)
Sep 28 14:13:03.881 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (15/29) Installing gcc (12.1.1_git20220630-r6)
Sep 28 14:13:07.321 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (16/29) Installing libstdc++-dev (12.1.1_git20220630-r6)
Sep 28 14:13:08.662 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (17/29) Installing musl-dev (1.2.3-r1)
Sep 28 14:13:08.892 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (18/29) Installing libc-dev (0.7.2-r3)
Sep 28 14:13:08.910 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (19/29) Installing g++ (12.1.1_git20220630-r6)
Sep 28 14:13:09.988 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (20/29) Installing make (4.3-r0)
Sep 28 14:13:10.039 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (21/29) Installing fortify-headers (1.1-r1)
Sep 28 14:13:10.069 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (22/29) Installing patch (2.7.6-r7)
Sep 28 14:13:10.105 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (23/29) Installing build-base (0.5-r3)
Sep 28 14:13:10.135 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (24/29) Installing busybox (1.35.0-r25)
Sep 28 14:13:10.218 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (25/29) Installing ca-certificates-bundle (20220614-r2)
Sep 28 14:13:10.265 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (26/29) Installing scanelf (1.3.5-r1)
Sep 28 14:13:10.296 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (27/29) Installing libcrypto3 (3.0.5-r2)
Sep 28 14:13:10.471 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (28/29) Installing libssl3 (3.0.5-r2)
Sep 28 14:13:10.517 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] (29/29) Installing ssl_client (1.35.0-r25)
Sep 28 14:13:10.538 [DEBUG] [arch:armv7] [cmd:apk] [use-proot:false] [use-qemu:] OK: 164 MiB in 29 packages
Sep 28 14:13:10.548 [INFO] [arch:armv7] creating user 1000(build)
Sep 28 14:13:10.549 [INFO] [arch:armv7] creating group 1000(build)
Sep 28 14:13:10.550 [INFO] [arch:armv7] [cmd:/bin/busybox] [use-proot:false] [use-qemu:] running: /usr/sbin/chroot /tmp/melange-guest-3090450258 /bin/busybox --install -s
Sep 28 14:13:10.554 [DEBUG] [arch:armv7] [cmd:/bin/busybox] [use-proot:false] [use-qemu:] chroot: can't execute '/bin/busybox': Exec format error
2022/09/28 14:13:10 ERROR: failed to build package. the build environment has been preserved:
2022/09/28 14:13:10 melange (hello/armv7):   workspace dir: /tmp/melange-workspace-2193273048
2022/09/28 14:13:10 melange (hello/armv7):   guest dir: /tmp/melange-guest-3090450258
Error: failed to build package: unable to build workspace: unable to generate image: failed to install busybox symlinks: failed to install busybox symlinks: exit status 126
2022/09/28 14:13:10 error during command execution: failed to build package: unable to build workspace: unable to generate image: failed to install busybox symlinks: failed to install busybox symlinks: exit status 126
benmoss commented 1 year ago

Guessing this is me missing qemu emulation packages?

amouat commented 1 year ago

Could be, could you try the recommendation here? https://edu.chainguard.dev/open-source/melange/troubleshooting/#missing-qemu-user-space-emulation-packages

benmoss commented 1 year ago
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
Unable to find image 'multiarch/qemu-user-static:latest' locally
latest: Pulling from multiarch/qemu-user-static
f5b7ce95afea: Pull complete
22ee763f0af7: Pull complete
30abb83a18eb: Pull complete
0657daef200b: Pull complete
998118dcc3de: Pull complete
Digest: sha256:16abbe859db6a7d142d90125f3260008f698a224ccd0e776d554cfc46fd025b6
Status: Downloaded newer image for multiarch/qemu-user-static:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error while loading /qemu-binfmt-conf.sh: Exec format error

Looks like that image only comes in amd64 :/

benmoss commented 1 year ago

Seems to work in an amd64 environment though