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
|
# Build stage — pinned to the build host's arch so cross-compilation
|
||||||
FROM golang:1.25-alpine AS builder
|
# 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
|
# Build arguments
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
@@ -29,9 +34,7 @@ COPY . .
|
|||||||
# Generate protobuf code
|
# Generate protobuf code
|
||||||
RUN make proto-gen
|
RUN make proto-gen
|
||||||
|
|
||||||
# Build binary with version information
|
# Build binary with version information, cross-compiling to the target arch.
|
||||||
ARG TARGETOS=linux
|
|
||||||
ARG TARGETARCH=amd64
|
|
||||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo \
|
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}" \
|
-ldflags "-X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.BuildTime=${BUILD_TIME} ${BUILD_FLAGS}" \
|
||||||
-o server ./cmd/server
|
-o server ./cmd/server
|
||||||
@@ -66,5 +69,5 @@ USER notifier
|
|||||||
EXPOSE 8080 50051 9090 8081
|
EXPOSE 8080 50051 9090 8081
|
||||||
|
|
||||||
# Run server (defaults to both REST and gRPC)
|
# 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"]
|
CMD ["/app/server"]
|
||||||
|
|||||||
Reference in New Issue
Block a user