From 8488f68190c5aaaa3e67fcf1f0b058d21312e054 Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Sat, 21 Oct 2023 18:20:01 -0700 Subject: [PATCH] Use Go's native cross-compile support instead of emulation Signed-off-by: Nic Cope --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b4def2..6ae4d7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,23 +2,24 @@ # We use the latest Go 1.x version unless asked to use something else. ARG GO_VERSION=1 +ARG TARGETOS +ARG TARGETARCH # Setup the base environment. -FROM golang:${GO_VERSION} AS base +FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base WORKDIR /fn ENV CGO_ENABLED=0 COPY go.mod go.sum ./ -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download +RUN --mount=type=cache,target=/go/pkg/mod go mod download # Build the Function. FROM base AS build RUN --mount=target=. \ --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ - go build -o /function . + GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /function . # Produce the Function image. FROM gcr.io/distroless/base-debian11 AS image