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 <noreply@anthropic.com>
This commit is contained in:
+9
-6
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user