From 3e84b9c3addd71d9f0a40313995aa4724064450e Mon Sep 17 00:00:00 2001 From: Ivan Godwin Date: Mon, 29 Jun 2026 14:19:56 -0700 Subject: [PATCH] build(notifier): support multi-arch image builds Build on the native host arch (--platform=$BUILDPLATFORM) and cross-compile the static binary per target via buildx-provided TARGETOS/TARGETARCH, so `make docker-build` with REGISTRY set produces linux/amd64 + linux/arm64 images without emulating the Go toolchain under QEMU. Also correct the CMD comment to the real env var (NOTIFIER_SERVER_MODE). Co-Authored-By: Claude Opus 4.8 --- Dockerfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c70077..1d4bb08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,10 @@ -# Build stage -FROM golang:1.25-alpine AS builder +# Build stage — pinned to the build host's arch so cross-compilation +# via GOOS/GOARCH is fast and avoids QEMU emulation of the toolchain. +FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS builder + +# Platform args populated by buildx for each target in a multi-platform build. +ARG TARGETOS +ARG TARGETARCH # Build arguments ARG VERSION=dev @@ -29,9 +34,7 @@ COPY . . # Generate protobuf code RUN make proto-gen -# Build binary with version information -ARG TARGETOS=linux -ARG TARGETARCH=amd64 +# Build binary with version information, cross-compiling to the target arch. RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo \ -ldflags "-X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildTime=${BUILD_TIME} ${BUILD_FLAGS}" \ -o server ./cmd/server @@ -66,5 +69,5 @@ USER notifier EXPOSE 8080 50051 9090 8081 # Run server (defaults to both REST and gRPC) -# Override mode with environment variable: -e SERVER_MODE=rest or -e SERVER_MODE=grpc +# Override mode with environment variable: -e NOTIFIER_SERVER_MODE=rest or -e NOTIFIER_SERVER_MODE=grpc CMD ["/app/server"]