Description
What is the issue?
Directory.dockerBuild(platform: ...) returns a container whose platform is the engine's own platform whenever the Dockerfile's final stage is FROM scratch. The contents are built for the requested platform (TARGETARCH is passed correctly), only the declared platform is wrong.
Publishing a multi-platform image from such builds (container.publish(addr, { platformVariants: [amd64Build, arm64Build] })) then pushes a single-platform image instead of an index, labelled with the engine's platform. In our case an arm64 engine published x86-64 binaries labelled linux/arm64, which downstream consumers (Foundries.io compose-publish) rejected.
Dockerfiles whose final stage is a real base image are not affected.
Dagger version
dagger v1.0.0-beta.28 (856a3da), engine linux/arm64 (Docker on macOS arm64). Also seen on earlier 1.0 betas in CI.
Steps to reproduce
Dockerfile:
FROM --platform=$BUILDPLATFORM docker.io/library/alpine:3 AS s
ARG TARGETARCH
RUN echo "target=$TARGETARCH" > /x
FROM scratch
COPY --from=s /x /xdagger -M -c '
for p in linux/amd64 linux/arm64; do
.echo "requested $p: "
host | directory . | docker-build --platform $p | platform
host | directory . | docker-build --platform $p | file /x | contents
done'Output on an arm64 engine (the shell prints platform without a trailing newline):
requested linux/amd64: linux/arm64target=amd64
requested linux/arm64: linux/arm64target=arm64
Expected: linux/amd64 for the first build.
Variations we tried:
FROM scratchwith onlyCOPY f /ffrom the build context (no other stages): same result, soscratchalone triggers it.FROM --platform=$TARGETPLATFORM scratch: same result.- Final stage
FROM docker.io/library/alpine:3instead ofscratch: the requested platform is honoured. dag.container({ platform }).import_(build.asTarball()): keeps the wrong platform from the tarball.dag.container({ platform }).withRootfs(build.rootfs()): correct platform, but entrypoint, cmd, user and labels are lost.
Log output
No response
Activity