Skip to content

Directory.dockerBuild ignores platform when the final stage is FROM scratch #15264

Backlog

Description

@ZarkoRunjevac

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 /x
dagger -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 scratch with only COPY f /f from the build context (no other stages): same result, so scratch alone triggers it.
  • FROM --platform=$TARGETPLATFORM scratch: same result.
  • Final stage FROM docker.io/library/alpine:3 instead of scratch: 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions