Skip to content

Commit

Permalink
Update Dockerfile for cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
minpeter committed Mar 13, 2024
1 parent b0ddee1 commit 8c53b1e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8c53b1e

Please sign in to comment.