mirror of
https://github.com/dockersrc/go
synced 2026-06-24 14:01:08 -04:00
⚡ Cross-compile go install tools to eliminate QEMU build hang ⚡
The arm64 build was stuck for 12+ hours compiling gopls, dlv, and other Go tools from source under QEMU user-mode emulation. QEMU makes Go compilation 20-50× slower than native; gopls alone can take hours. Fix: add a --platform=$BUILDPLATFORM go-tools stage in the Dockerfile that cross-compiles all go install tools natively on amd64 using Go's built-in cross-compilation (GOOS=linux GOARCH=$TARGETARCH). The binaries are then COPYed into the main build stage before 05-custom.sh runs. No QEMU is involved for any compilation step. - Dockerfile: add go-tools stage using --platform=$BUILDPLATFORM with golang:alpine; cross-compiles goimports, stringer, gopls, govulncheck, dlv, gops, benchstat, wire, mockgen, protoc-gen-go, protoc-gen-go-grpc; COPY /go/bin/ → /usr/local/bin/ before the 05-custom.sh RUN layer - rootfs/root/docker/setup/05-custom.sh: remove all go install commands (11 tools now provided by the Dockerfile stage); keep go clean -modcache/-cache cleanup Dockerfile rootfs/root/docker/setup/05-custom.sh
This commit is contained in:
@@ -191,45 +191,10 @@ _install_bin \
|
||||
"https://github.com/pressly/goose/releases/download/${_GOOSE_VER}/goose_linux_${_ARCH_GLIBC}" \
|
||||
"goose"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# go install for tools without standalone release binaries
|
||||
|
||||
echo "Installing Go tooling via go install"
|
||||
|
||||
# Import organiser — superset of gofmt that also manages import groups
|
||||
go install golang.org/x/tools/cmd/goimports@latest
|
||||
|
||||
# Generate String() methods for iota-based types
|
||||
go install golang.org/x/tools/cmd/stringer@latest
|
||||
|
||||
# Official Go language server (no binary releases; must compile)
|
||||
go install golang.org/x/tools/gopls@latest
|
||||
|
||||
# Vulnerability scanner against the Go vulnerability database
|
||||
go install golang.org/x/vuln/cmd/govulncheck@latest
|
||||
|
||||
# Source-level debugger
|
||||
go install github.com/go-delve/delve/cmd/dlv@latest
|
||||
|
||||
# Live process diagnostics: list Go processes, dump stacks, force GC
|
||||
go install github.com/google/gops@latest
|
||||
|
||||
# Benchmark comparison — statistically sound diff of pprof benchmark runs
|
||||
go install golang.org/x/perf/cmd/benchstat@latest
|
||||
|
||||
# Compile-time dependency injection code generator
|
||||
go install github.com/google/wire/cmd/wire@latest
|
||||
|
||||
# Mock generator for interfaces (Uber fork of golang/mock)
|
||||
go install go.uber.org/mock/mockgen@latest
|
||||
|
||||
# protobuf Go code generator
|
||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
|
||||
# gRPC Go code generator
|
||||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||
|
||||
echo "Go tooling installed"
|
||||
# go install tools (goimports, stringer, gopls, govulncheck, dlv, gops, benchstat,
|
||||
# wire, mockgen, protoc-gen-go, protoc-gen-go-grpc) are cross-compiled natively on
|
||||
# the build platform in the Dockerfile go-tools stage and copied to /usr/local/bin
|
||||
# before this script runs — no QEMU-emulated compilation needed here.
|
||||
|
||||
# Strip the module download cache and ephemeral build cache from this layer
|
||||
go clean -modcache
|
||||
|
||||
Reference in New Issue
Block a user