From bfb6c707739ef2688728c10dc90b4f5f712e0176 Mon Sep 17 00:00:00 2001 From: ngovinh2k2 Date: Thu, 29 Jan 2026 10:40:18 +0700 Subject: [PATCH] fix: build multi-arch failed --- Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba813c3..9bdeb8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage -FROM golang:1.24.4-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.24.4-alpine AS builder # Install dependencies RUN apk add --no-cache git @@ -16,8 +16,16 @@ RUN go mod download # Copy source code COPY . . -# Build the binary -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/transformer +# Build args from buildx +ARG TARGETOS +ARG TARGETARCH + +# Build static binary for correct platform +RUN CGO_ENABLED=0 \ + GOOS=$TARGETOS \ + GOARCH=$TARGETARCH \ + go build -trimpath -ldflags="-s -w" \ + -o main ./cmd/transformer # Final stage FROM alpine:latest