Repository navigation
[Docker] Install Go toolchain matching the image architecture - #41203
ayush-builds-stuff wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves #20983 by replacing the hardcoded linux-amd64 Go toolchain download in dev-support/docker/Dockerfile with dynamic architecture detection via BuildKit's TARGETARCH (falling back to dpkg --print-architecture). It also cleans up the downloaded tarball in the same layer and adds a build-time go version sanity check.
🔍 General Feedback
- The implementation is idiomatic, defensive (
set -eux), and properly supports both BuildKit and legacy Docker builders acrossamd64andarm64platforms. - Removing
/tmp/go.tar.gzin the sameRUNinstruction is a good improvement that reduces final image layer size.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping added as fallback since no labels match configuration Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
The Go download was hardcoded to linux-amd64 while the image is built from multi-arch ubuntu:24.04, so arm64 hosts ended up with a toolchain that could not run natively (silently emulated where binfmt is registered, failing with "ld-linux-x86-64.so.2: cannot open shared object file" where it is not). Take the architecture from BuildKit's TARGETARCH, falling back to dpkg --print-architecture, and assert `go version` in the same layer so a mismatch fails the build instead of producing a broken image. Fixes apache#20983
af6ce29 to
b20de36
Compare
Summary
The dev build environment image is built
FROM ubuntu:24.04, which is multi-arch, so onarm64 hosts the image is arm64 — but the Go toolchain installed into it was always
linux-amd64. The result is an image carrying a toolchain that does not match the image itlives in:
gosilently runs emulated:go env GOARCHreportsamd64inside anarm64container, and every Go step is slow./lib64/ld-linux-x86-64.so.2: cannot open shared object file, as reported in [Bug]: local-env-setup.sh fails on M1 mac #20983.This derives the Go download from the architecture of the image being built, and asserts
go versionin the same layer so a future arch mismatch fails the build instead ofproducing a silently broken image.
fixes #20983
Implementation
archcomes from BuildKit'sTARGETARCH(valuesamd64/arm64, the same naming Go uses),with
dpkg --print-architectureas the fallback for legacy-builder builds whereTARGETARCHis unset.golang.org/dl(which 301s togo.dev) togo.dev/dl, and thetarball is removed from the layer after extraction.
dev-support/: this was the only hardcodedamd64left.Testing
Both platforms were built end-to-end from this Dockerfile on an M-series Mac, and both
produce a toolchain that matches the image:
In both images a trivial program compiles and runs with the matching architecture
(
go build && ./prog→ok arm64/ok amd64).Architecture selection was also probed directly on both platforms:
Not exercised: the
dpkg --print-architecturefallback used whenTARGETARCHis unset(legacy builder,
DOCKER_BUILDKIT=0). BuildKit is the default, and the fallback resolves tothe same value as
TARGETARCHon both architectures above.Also note the
LegacyKeyValueFormatbuild warnings are pre-existing, on untouchedENVlines.No
CHANGES.mdentry: internal build tooling, no user-facing behavior change.AI disclosure
Investigated, implemented and tested with an AI coding agent (Pi-Bolt). The account owner
reviewed the change, owns the content, and is responsible for it.
Credit to @rokadepiyush49-rgb for the diagnosis in #20983.