From 8c53b1e125e313150a3ef5ffad3852ff3c5c6797 Mon Sep 17 00:00:00 2001 From: minpeter Date: Wed, 13 Mar 2024 13:09:43 +0900 Subject: [PATCH] Update Dockerfile for cross-compilation --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 01689ff..831ca8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ # Step 1: Modules caching -FROM golang:latest as modules +FROM --platform=$BUILDPLATFORM golang:latest as modules COPY go.mod go.sum /modules/ WORKDIR /modules RUN go mod download -# Step 2: Builder -FROM golang:latest AS builder +# Step 2: Builder, with cross compile +FROM --platform=$BUILDPLATFORM golang:latest AS builder COPY --from=modules /go/pkg /go/pkg COPY . /app -ARG TARGETPLATFORM +ARG TARGETOS TARGETARCH ENV CGO_ENABLED=0 WORKDIR /app -RUN go build -o /bin/app . +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /bin/app . # GOPATH for scratch images is / FROM scratch