RAS-1976: Fix cross-building Docker images - #180
Merged
Merged
Conversation
The final stage was pinned to --platform=$BUILDPLATFORM and go build never set GOARCH, so every pass built for amd64 and BuildKit labelled it arm64. Add ARG TARGETARCH + GOOS/GOARCH, unpin the final stage. Also swap the runtime image to alpine:3.24 (~250MB -> ~10MB), adding the ca-certificates and CGO_ENABLED=0 that golang:*-alpine gave us implicitly.
warrenbaileyons
approved these changes
Sep 28, 2026
Contributor
|
/gcbrun |
arroyoAle
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why?
The final stage was pinned to --platform=$BUILDPLATFORM and go build never set GOARCH, so build of the arm64 image in CI/CD built for amd64 and labelled it arm64 nevertheless - and it failed to run with an "exec format error". Add ARG TARGETARCH + GOOS/GOARCH, unpin the final stage.
(If you built on a Mac, then you'd get arm64 for both instead, so the code seemed to work.)
Nicely, it means that the build stage will cross-compile on the native compiler without emulation, so the build stage for both arm64 and amd64 should take roughly the same time, no matter the architecture of the build machine.
Also swap the runtime image to alpine:3.24 (~250MB -> ~10MB), adding the ca-certificates and CGO_ENABLED=0 that were implicit in golang:*-alpine.
How to test?
It should say
b7 00for arm64, and3e 00for x86-64 (as it did for both before).Jira
https://officefornationalstatistics.atlassian.net/browse/RAS-1976