From 7057b579aaae76d4e4cde355f61034152668ffac Mon Sep 17 00:00:00 2001 From: Robert Moucha Date: Thu, 12 Feb 2026 14:47:12 +0100 Subject: [PATCH] feat(docker): cross-compile binary for building multi-platform images it's more efficient and faster to use golang cross-compiler instead of running native build in cpu emulator --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e69e6f8..cb31c7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # Stage 1: Build the Go app -FROM 020413372491.dkr.ecr.us-east-1.amazonaws.com/pullthrough/docker.io/library/golang:1.25.6-alpine AS builder +FROM --platform=$BUILDPLATFORM 020413372491.dkr.ecr.us-east-1.amazonaws.com/pullthrough/docker.io/library/golang:1.25.6-alpine AS builder +ARG TARGETOS TARGETARCH RUN apk add --no-cache git bash sed findutils WORKDIR /app @@ -9,7 +10,7 @@ RUN bash vendor-tsgo.sh RUN go mod tidy # Build the Go application -RUN CGO_ENABLED=0 GOOS=linux go build -o goodchanges . +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o goodchanges . # Stage 2: Run the app FROM 020413372491.dkr.ecr.us-east-1.amazonaws.com/pullthrough/docker.io/library/alpine:3.23