Skip to content

Commit

Permalink
Use Go's native cross-compile support instead of emulation
Browse files Browse the repository at this point in the history
Signed-off-by: Nic Cope <[email protected]>
  • Loading branch information
negz committed Oct 22, 2023
1 parent 9d90092 commit 8488f68
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8488f68

Please sign in to comment.