Fix armhf image build: stop pinning BUILDPLATFORM to linux/amd64 - #3453
Open
axl89 wants to merge 1 commit into
Open
Fix armhf image build: stop pinning BUILDPLATFORM to linux/amd64#3453axl89 wants to merge 1 commit into
axl89 wants to merge 1 commit into
Conversation
`ARG BUILDPLATFORM=linux/amd64` overrode the value BuildKit injects, so every
`FROM --platform=${BUILDPLATFORM}` stage was pinned to amd64 no matter where the
build ran. Building natively on an armhf host pulled the amd64 golang image and
died on the first RUN of the base stage:
=> ERROR [base 3/10] RUN apk --update add git g++ findutils
exec /bin/sh: exec format error
Removing the declaration restores the built-in value. Also adds build-armhf.sh
(checks for the QEMU binfmt handler needed when cross building, creates a
container-driver builder, passes VERSION/COMMIT/CREATED) and doc/build-armhf.md.
Verified: `docker buildx build --platform=linux/arm/v7 --target=build` completes
on an amd64 host and produces an "ELF 32-bit LSB executable, ARM, EABI5" binary.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The problem
Building the image natively on a 32-bit ARM host fails immediately:
The cause
The toolchain stages are pinned to the build platform, which is correct:
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${GO_ALPINE_VERSION} AS baseBut the Dockerfile also declared that built-in argument with a default:
ARG BUILDPLATFORM=linux/amd64A declared default takes precedence over the value BuildKit injects, so every
FROM --platform=${BUILDPLATFORM}stage was pinned tolinux/amd64regardless of where thebuild actually ran. On an armhf host that pulls the amd64
golangimage, and the firstRUNinside it dies with
exec format error.This is invisible in CI, because CI builds on amd64 and the hardcoded value happens to match
the real build platform there. It only bites people building natively on arm.
Minimal reproduction on an amd64 host, which fails in the same way with the platforms mirrored:
The change
ARG BUILDPLATFORM=linux/amd64declaration, restoring the built-in value, andleave a comment so it does not come back. This is the only functional change.
build-armhf.sh, which creates adocker-containerdriver builder (the defaultdockerdriver cannot build for another platform), passes
VERSION/COMMIT/CREATED, and checks forthe QEMU binfmt handler up front rather than failing halfway through the build.
PLATFORM,TAGandPUSHare configurable.doc/build-armhf.mdcovering the diagnosis, thelinux/arm/v7versuslinux/arm/v6naming confusion, and the QEMU setup needed for cross builds.
Nothing else about the build changes: all the auxiliary images (
xcputranslate, bothbinpotimages,
golang-alpine andalpine) already publishlinux/arm/v6andlinux/arm/v7manifests, so a native armhf build has everything it needs.
Verification
On an amd64 host,
docker buildx build --platform=linux/arm/v7 --target=buildnow completes —[base 3/10]passes and the resulting binary isELF 32-bit LSB executable, ARM, EABI5.The final
alpinestage runsapk addon the target architecture, so whilst cross building itstill needs the QEMU binfmt handlers (
docker run --privileged --rm tonistiigi/binfmt --install arm),exactly as CI's
docker/setup-qemu-actionprovides. That stage is untouched by this PR, and anative build on the ARM host needs no emulation at all.