FROM scratch and multarch buildx build using BUILDPLATFORM arg bug #5691
-
Hello everyone, I have a trouble using multistage multiarch build when using It does not work with moby 26.1.3 in GH Action. I think it might be a bug in moby. I have Dockerfile like: FROM --platform=$BUILDPLATFORM scratch AS builder
ARG BUILDPLATFORM
ARG BUILDARCH
ARG TARGETARCH
ADD .artifacts/alpine-minirootfs-$BUILDARCH.tar.gz /
COPY .artifacts/go.tar.gz /tmp/go.tar.gz
RUN tar -C /usr/local -xzf /tmp/go.tar.gz ### THIS FAILS
ENV PATH="/usr/local/go/bin:$PATH"
WORKDIR /workspace
COPY go.mod go.sum ./
RUN go mod download -x
COPY . .
RUN GOARCH=$TARGETARCH go build -o func-util -trimpath -ldflags '-w -s' ./cmd/func-util
#########################
FROM scratch
ARG TARGETARCH
ADD .artifacts/alpine-minirootfs-$TARGETARCH.tar.gz /
COPY --from=builder /workspace/func-util /usr/local/bin/
RUN apk add --no-cache tar ### THIS WORKS The issues is that execution of any binary in the builder stage causes an error:
That's really strange since builder should be native and no emulation should be involved at all. IMO there is a bug with platform and Most importantly: why it works with older moby and podman? Also note that the emulation works as expected for the final stage. The |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
I suspect that moby might look into declared architecture of base image and |
Beta Was this translation helpful? Give feedback.
-
It looks like moby tries to run qemu emulation on native binaries for some reason. |
Beta Was this translation helpful? Give feedback.
-
Let me transfer this to the BuildKit repository, which is where the builder is maintained Possibly related (?) |
Beta Was this translation helpful? Give feedback.
-
Yes, it looks related. |
Beta Was this translation helpful? Give feedback.
-
I fixed this issue in my GH Action by using |
Beta Was this translation helpful? Give feedback.
Let me transfer this to the BuildKit repository, which is where the builder is maintained
Possibly related (?)