Skip to content

RAS-1976: Fix cross-building Docker images - #67

Merged
arroyoAle merged 3 commits into
mainfrom
fix-arm64-cross-compile
Oct 1, 2026
Merged

arroyoAle merged 3 commits into
mainfrom
fix-arm64-cross-compile

Conversation

@prem-buczkowski-ons

Copy link
Copy Markdown
Contributor

What and why?

On our amd64 CI builder, go build used the builder's architecture, so the arm64-targeted image contained an amd64 binary and failed with an "exec format error". An Apple Silicon builder could mask the issue for arm64 builds. Add TARGETOS/TARGETARCH and set GOOS/GOARCH, and unpin the final stage so the image and binary target the requested platform.

This cross-compiles the Go build stage without emulating the Go compiler. RUN commands in the final target-platform stage may still require emulation on a non-native builder.

Switch the runtime stage from the Go image to alpine:3.24, install ca-certificates, and build with CGO_ENABLED=0 to keep the runtime image small and the binary static.

How to test?

Check the binary's ELF architecture in the built root filesystem. The binary is at opt/print-file/print-file. The arm64 check should print b7 00; repeat with linux/amd64, which should print 3e 00.

set -o pipefail
docker buildx build --platform linux/arm64 --output type=tar,dest=- \
  -f _infra/docker/Dockerfile . \
  | tar -xOf - opt/print-file/print-file \
  | { dd bs=1 skip=18 count=2 2>/dev/null; cat >/dev/null; } \
  | od -An -tx1

Jira

https://officefornationalstatistics.atlassian.net/browse/RAS-1976

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.
@prem-buczkowski-ons
prem-buczkowski-ons requested a review from a team as a code owner September 25, 2026 14:46
@prem-buczkowski-ons prem-buczkowski-ons added the bug Something isn't working label Sep 25, 2026

@warrenbaileyons warrenbaileyons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just needs the chart version updating

@arroyoAle

Copy link
Copy Markdown
Contributor

/gcbrun

@arroyoAle

Copy link
Copy Markdown
Contributor

/gcbrun

@arroyoAle
arroyoAle merged commit be955b0 into main Oct 1, 2026
6 checks passed
@arroyoAle
arroyoAle deleted the fix-arm64-cross-compile branch October 1, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants