Skip to content

Cross-compile the images instead of building arm64 under QEMU - #14

Merged
zhanghaohit merged 1 commit into
mainfrom
build/cross-compile
Oct 28, 2026
Merged

zhanghaohit merged 1 commit into
mainfrom
build/cross-compile

Conversation

@zhanghaohit

Copy link
Copy Markdown
Collaborator

The build stage of the three Dockerfiles had no --platform, so for linux/arm64 buildx ran the Go toolchain itself under QEMU -- go mod download and go build emulated, three images in a row. The release took 20-30 minutes, and so did the arm64 leg of image-check on every pull request (22 minutes on #13).

The binary is pure Go (CGO_ENABLED=0) and GOARCH already follows TARGETARCH (#11), so the build stage now runs on the builder's own platform (FROM --platform=$BUILDPLATFORM) and Go cross-compiles. The runtime stage only copies the binary and runs nothing, so it needs no emulation either.

Check: image-check on this PR builds all three images for both platforms and fails unless each binary's ELF machine matches its platform -- the same check that caught the amd64 binary in the arm64 image -- and its arm64 run time shows the speed-up.

The build stage had no --platform, so for linux/arm64 buildx ran the Go
toolchain itself under QEMU: go mod download and go build emulated,
three images in a row, 20-30 minutes per release and per image-check
run. The binary is pure Go (CGO_ENABLED=0) and GOARCH already follows
TARGETARCH, so run the build stage on the builder's platform and let Go
cross-compile; the runtime stage only copies the binary.
@zhanghaohit
zhanghaohit merged commit 1a0e3c4 into main Oct 28, 2026
2 checks passed
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