-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate that all combinations of BUILDPLATFORM, TARGETPLATFORM, Dockerfile, and host CPU architecture produce correct executable #8
Comments
this is the example Ioannis sent me yesterday, but I have not tried it yet # syntax=docker/dockerfile-upstream:1.5.0-rc2-labs
#FROM --platform=$BUILDPLATFORM jsfakian/eve-rust:1.80.1 AS rust-host
#ARG TARGETARCH
FROM jsfakian/eve-rust:1.80.1 AS rust
# map Docker's $TARGETARCH to Rust target
#FROM rust-host AS target-amd64
#ENV CARGO_BUILD_TARGET="x86_64-unknown-linux-musl"
#FROM rust-host AS target-arm64
#ENV CARGO_BUILD_TARGET="aarch64-unknown-linux-musl"
#FROM rust-host AS target-riscv64
#ENV CARGO_BUILD_TARGET="riscv64gc-unknown-linux-gnu"
#FROM target-$TARGETARCH AS rust
WORKDIR /usr/local/my-installer
COPY . .
# Add the vendor tar file
RUN tar xvf /usr/local/my-installer/vendor.tar.gz \
&& rm vendor.tar.gz
# tools already in place
RUN cargo build --release --verbose
RUN cargo sbom > sbom.spdx.json
RUN cp /usr/local/my-installer/target/$CARGO_BUILD_TARGET/release/installer /usr/local/my-installer/target/installer
FROM lfedge/eve-alpine:1f7685f95a475c6bbe682f0b976f12180b6c8726 AS build
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
ENV PKGS ncurses-dev smartmontools mtools strace util-linux e2fsprogs e2fsprogs-extra jq
RUN eve-alpine-deploy.sh
COPY --from=rust /usr/local/my-installer/target/installer /out/sbin/installer
COPY --from=rust /usr/local/my-installer/sbom.spdx.json /out/sbin/sbom.spdx.json
FROM scratch
COPY --from=build /out/ /
ENV RUST_BACKTRACE full
COPY run-installer.sh /sbin/run-installer.sh
WORKDIR /
ENTRYPOINT ["/sbin/run-installer.sh"] and the error message
|
What platform was he running it on? How did he call it? And in what scenario does it work? |
both x86 linux and Mac. @jsfakian , I think I know why it failed for you. Did you build a multiplatfrom image for eve-rust and push it to your dockerhub or you built only a single platfrom? |
I was running on x86 Linux and Mac. I built a multiplatform image for eve-rust and pushed it to my docker hub. |
@jsfakian and I did a test. If you do a simple build, it fails. If you set the env var (like the Dockerfile), it fails. It fails on building Success with env var
Failure without env var:
The only differences between the lines are:
Same success if we do We do not understand why explicitly setting @rucoder thoughts? |
More information. On failure, the linker says it is unable to find
E.g.: /usr/local/my-installer # ls -l /usr/local/rustup/toolchains/1.80.1-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/
total 6084
-rw-rw-rw- 1 root root 3688 Aug 8 20:02 Scrt1.o
-rw-rw-rw- 1 root root 3688 Aug 8 20:02 crt1.o
-rw-rw-rw- 1 root root 3624 Aug 8 20:02 crtbegin.o
-rw-rw-rw- 1 root root 3624 Aug 8 20:02 crtbeginS.o
-rw-rw-rw- 1 root root 1056 Aug 8 20:02 crtend.o
-rw-rw-rw- 1 root root 1056 Aug 8 20:02 crtendS.o
-rw-rw-rw- 1 root root 2656 Aug 8 20:02 crti.o
-rw-rw-rw- 1 root root 2600 Aug 8 20:02 crtn.o
-rw-rw-rw- 1 root root 5982382 Aug 8 20:02 libc.a
-rw-rw-rw- 1 root root 204164 Aug 8 20:02 libunwind.a
-rw-rw-rw- 1 root root 4864 Aug 8 20:02 rcrt1.o It looks like the linker is not finding these libraries to link, except when |
@deitch I think CARGO_BUILD_TARGET IS set but it is not -unknow-linux-musl because how would cargo know you want to build for musl? maybe try setting default toolchain via rustup? e.g. FROM tools-host AS target-arm64
RUN rustup default aarch64-unknown-linux-musl
ENV CARGO_BUILD_TARGET="aarch64-unknown-linux-musl" UPDARE: no, toolchain has nothing todo with target. we MUST specify --target or CARGO_BUILD_TARGET to override the default target which matches the BUILD platform |
@rucoder can you explain that? The command that fails is:
That looks like it is building for the local target. But who knows? I think it is fine if our default target is local platform, and we set it. So maybe the dockerfile to build should include that cross-stuff, so it always sets the default target, and you can override it? We already do it for building the cargo tools, maybe we should leave the |
@rucoder I think we can close this now? |
So we are not going to add tests/exaples ? 😉 |
Ok, fine. |
With some combinations of BUILDPLATFORM, TARGETPLATFORM, Dockerfile, and host CPU architecture downstream rust applications are built for incorrect CPU architecture.
The text was updated successfully, but these errors were encountered: