From 1c97983116fd542b06b8b63badcc558179220c34 Mon Sep 17 00:00:00 2001 From: zhanghao Date: Wed, 28 Oct 2026 17:37:29 +0800 Subject: [PATCH] Cross-compile the images instead of building arm64 under QEMU The build stage had no --platform, so for linux/arm64 buildx ran the Go toolchain itself under QEMU: go mod download and go build emulated, three images in a row, 20-30 minutes per release and per image-check run. The binary is pure Go (CGO_ENABLED=0) and GOARCH already follows TARGETARCH, so run the build stage on the builder's platform and let Go cross-compile; the runtime stage only copies the binary. --- Dockerfile | 5 ++++- Dockerfile.hagate | 5 ++++- Dockerfile.reload | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8904ea2..9c04266 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,10 @@ ARG GO_BASE=golang:1.23.3-alpine3.20 ARG RUNTIME_BASE=python:3.12-alpine ARG GOPROXY=https://proxy.golang.org,direct -FROM ${GO_BASE} AS build +# The build stage runs on the builder's own platform and cross-compiles (CGO is off, GOARCH comes +# from TARGETARCH below). Without --platform the arm64 build ran the Go toolchain under QEMU, which +# took 20-30 minutes for the three images; the runtime stage only copies the binary. +FROM --platform=$BUILDPLATFORM ${GO_BASE} AS build ARG GOPROXY # TARGETARCH is set by buildx to the platform being built, so a multi-platform build # compiles each image for its own arch. It was hardcoded to amd64, which put an amd64 diff --git a/Dockerfile.hagate b/Dockerfile.hagate index e44b1fe..f66f96a 100644 --- a/Dockerfile.hagate +++ b/Dockerfile.hagate @@ -8,7 +8,10 @@ ARG GO_BASE=golang:1.23.3-alpine3.20 ARG RUNTIME_BASE=python:3.12-alpine ARG GOPROXY=https://proxy.golang.org,direct -FROM ${GO_BASE} AS build +# The build stage runs on the builder's own platform and cross-compiles (CGO is off, GOARCH comes +# from TARGETARCH below). Without --platform the arm64 build ran the Go toolchain under QEMU, which +# took 20-30 minutes for the three images; the runtime stage only copies the binary. +FROM --platform=$BUILDPLATFORM ${GO_BASE} AS build ARG GOPROXY # TARGETARCH is set by buildx to the platform being built, so a multi-platform build # compiles each image for its own arch. It was hardcoded to amd64, which put an amd64 diff --git a/Dockerfile.reload b/Dockerfile.reload index f0806d6..6b1453e 100644 --- a/Dockerfile.reload +++ b/Dockerfile.reload @@ -7,7 +7,10 @@ ARG GO_BASE=golang:1.23.3-alpine3.20 ARG RUNTIME_BASE=python:3.12-alpine ARG GOPROXY=https://proxy.golang.org,direct -FROM ${GO_BASE} AS build +# The build stage runs on the builder's own platform and cross-compiles (CGO is off, GOARCH comes +# from TARGETARCH below). Without --platform the arm64 build ran the Go toolchain under QEMU, which +# took 20-30 minutes for the three images; the runtime stage only copies the binary. +FROM --platform=$BUILDPLATFORM ${GO_BASE} AS build ARG GOPROXY # TARGETARCH is set by buildx to the platform being built, so a multi-platform build # compiles each image for its own arch. It was hardcoded to amd64, which put an amd64