fix(docker): build CGO images on the target platform - #60
Merged
Conversation
The builder stages were pinned to $BUILDPLATFORM while setting
GOARCH=${TARGETARCH} with CGO_ENABLED=1. Since gorm.io/driver/sqlite
depends on the cgo-based mattn/go-sqlite3, the linux/arm64 leg of the
multi-arch publish invoked the amd64 runner's native gcc for an arm64
target and failed; golang:alpine ships no cross toolchain. Only the
single-arch amd64 verification job passed, which hid the break until
the publish step.
Drop --platform=$BUILDPLATFORM so the builder runs on the target
platform under the QEMU emulation the workflow already sets up, and
scope the module/build cache mounts per GOOS/GOARCH now that both legs
compile real object code. Raise the docker-publish timeout to 60
minutes to accommodate the slower emulated arm64 build.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tta36PzgyAeGrZ6NdKiqEj
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.
Problem
The
Build and push Docker imagestep indocker-publishfails on thelinux/arm64leg:The builder stage is pinned to
--platform=$BUILDPLATFORM(amd64 on GitHub runners) while settingGOARCH=${TARGETARCH}withCGO_ENABLED=1.gorm.io/driver/sqlitepulls ingithub.com/mattn/go-sqlite3, which is C code, so the arm64 leg invokes the builder's native amd64 gcc for an arm64 target.golang:alpineships no cross toolchain, so it exits 1.The amd64 leg succeeds, which is why the single-arch
docker-verifyjob stayed green and the break only surfaced at publish time.Changes
docker/alpine,docker/pr-build,docker/alpine.debug: drop--platform=$BUILDPLATFORMfrom the builder stage so it runs on the target platform, under the QEMU emulationdocker/setup-qemu-actionalready installs. CGO then uses a matching native toolchain.id=...-${TARGETOS}-${TARGETARCH}. Both platform legs now compile real object code and would otherwise share and thrash a single/go/pkg/modand/root/.cache/go-build..github/workflows/ci.yml: raise thedocker-publishtimeout from 30 to 60 minutes, since the emulated arm64 build is substantially slower than the cross-compile it replaces.docker/goreleaserandrelease.ymlare unaffected — that path copies prebuilt amd64 binaries rather than compiling in the image.Verification
docker build -f docker/alpine .succeeds locally (builder step ~65s). The arm64 leg was not built locally: this machine has no QEMU binfmt handlers registered and installing them changes host state, so that leg is left to CI.Alternative considered
Keeping the amd64 builder and adding a cross toolchain (e.g.
zig cc) would build faster but adds a non-trivial dependency. The emulated build is the lower-risk change and matches theCGO_ENABLED=1assumption already baked into.goreleaser.yaml.🤖 Generated with Claude Code
https://claude.ai/code/session_01Tta36PzgyAeGrZ6NdKiqEj