Skip to content

build: cross-compile images from $BUILDPLATFORM#242

Open
gecube wants to merge 1 commit into
kaasops:mainfrom
gecube:chore/dockerfile-cross-compile
Open

build: cross-compile images from $BUILDPLATFORM#242
gecube wants to merge 1 commit into
kaasops:mainfrom
gecube:chore/dockerfile-cross-compile

Conversation

@gecube

@gecube gecube commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Pin the builder stage of all three Dockerfiles to the native build platform:

-FROM golang:1.26 AS builder
+FROM --platform=$BUILDPLATFORM golang:1.26 AS builder

The build already sets GOARCH=${TARGETARCH} (and GOOS=${TARGETOS:-linux}), so with the builder running on $BUILDPLATFORM the Go toolchain cross-compiles natively for each target arch instead of running under QEMU emulation for the non-native one. Same resulting images, much faster multi-arch builds.

Proof

docker buildx build --platform linux/amd64,linux/arm64 (builder stage rebuilt from scratch, --no-cache-filter builder) — all three build cleanly for both architectures:

manager:           OK (amd64+arm64) in 87s
event-collector:   OK (amd64+arm64) in 40s
checkpoint-merger: OK (amd64+arm64) in 17s

No functional change to the images.

Pin the builder stage to the native build platform
(FROM --platform=$BUILDPLATFORM) so multi-arch builds cross-compile via
the already-parametrised GOARCH=$TARGETARCH instead of running the Go
toolchain under QEMU emulation for the non-native architecture. Same
resulting images, significantly faster multi-arch builds in CI.

Signed-off-by: Gaál György <gb12335@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant