Skip to content

Commit b1aa08b

Browse files
committed
Add multi-platform Docker build support
- Enable building for linux/amd64 and linux/arm64 platforms - Use build-time platform variables in Dockerfile - Optimize Go build with CGO disabled and trimmed binaries
1 parent 892a1cc commit b1aa08b

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

.github/workflows/docker-build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ jobs:
4747
push: true
4848
tags: ${{ steps.meta.outputs.tags }}
4949
labels: ${{ steps.meta.outputs.labels }}
50+
platforms: linux/amd64,linux/arm64
5051
cache-from: type=gha
5152
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
FROM docker.io/library/golang:alpine AS builder
1+
FROM --platform=$BUILDPLATFORM docker.io/library/golang:alpine AS builder
22

33
WORKDIR /app
44
COPY go.mod go.sum ./
55
RUN go mod download
66
COPY ./ /app
7-
RUN go build -o bin/main .
7+
8+
ARG TARGETARCH
9+
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH go build -trimpath -ldflags '-w -s' -o bin/main .
810

911
FROM docker.io/library/alpine:latest
1012

0 commit comments

Comments
 (0)