Skip to content

Commit 665f67e

Browse files
committed
fix: cross-compile binaries for the requested target platform
All published platform variants (386, arm/v6, arm/v7, arm64, ppc64le) contained the same amd64 binary: the builder stage runs on BUILDPLATFORM but go build never set GOOS/GOARCH, so images only worked where emulation (e.g. Rosetta) was available. Build with explicit GOOS/GOARCH/GOARM from BuildKit platform args and add an xx-verify --static guard so any future cross-compile regression fails the build instead of publishing wrong-arch images. Also split go.mod/go.sum into their own layer for module cache reuse and add a .dockerignore to keep the build context minimal. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
1 parent 6c497d1 commit 665f67e

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎.dockerignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.github
2+
.idea
3+
.claude
4+
CLAUDE.md
5+
README.md
6+
LICENSE
7+
Dockerfile
8+
docker-bake.hcl

‎Dockerfile‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
FROM --platform=${BUILDPLATFORM} tonistiigi/xx:1.9.0 AS xx
2+
13
FROM --platform=${BUILDPLATFORM} golang:1.24.5 AS builder
4+
COPY --from=xx / /
5+
RUN xx-verify --setup
26
WORKDIR $GOPATH/src/github.com/docker/compose-bridge-transformer
7+
COPY go.mod go.sum ./
8+
RUN go mod download
39
COPY . .
4-
RUN go build -o /go/bin/transform
10+
ARG TARGETOS TARGETARCH TARGETVARIANT
11+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} \
12+
go build -o /go/bin/transform && \
13+
xx-verify --static /go/bin/transform
514

615
FROM scratch AS transformer
716
LABEL com.docker.compose.bridge=transformation

0 commit comments

Comments
 (0)