Skip to content

Commit 23732dd

Browse files
authored
feat: add multi-arch build for docker image (#233)
1 parent eecd8fb commit 23732dd

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.github/workflows/action-docker-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ jobs:
1919
username: ${{ github.repository_owner }}
2020
password: ${{ secrets.GITHUB_TOKEN }}
2121

22+
- name: Set up Docker Buildx
23+
uses: docker/[email protected]
24+
with:
25+
use: true
26+
platforms: linux/arm64,linux/amd64
27+
2228
- name: build and push
2329
uses: docker/build-push-action@v6
2430
with:
2531
push: true
32+
platforms: linux/arm64,linux/amd64
2633
build-args: |
2734
VERSION=dev
2835
tags: |
@@ -39,6 +46,9 @@ jobs:
3946
name: test
4047
runs-on: ubuntu-latest
4148
needs: build-dev-image
49+
strategy:
50+
matrix:
51+
os: [ ubuntu-latest, ubuntu-24.04-arm ]
4252

4353
steps:
4454
- name: checkout

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ jobs:
4040
username: ${{ github.repository_owner }}
4141
password: ${{ secrets.GITHUB_TOKEN }}
4242

43+
- name: Set up Docker Buildx
44+
uses: docker/[email protected]
45+
with:
46+
use: true
47+
platforms: linux/arm64,linux/amd64
48+
4349
- name: build and push
4450
uses: docker/build-push-action@v6
4551
with:
4652
push: true
4753
build-args: |
4854
VERSION=${{ env.RELEASE_VERSION }}
55+
platforms: linux/arm64,linux/amd64
4956
tags: |
5057
ghcr.io/vladopajic/go-test-coverage:${{ env.RELEASE_VERSION }}
5158
ghcr.io/vladopajic/go-test-coverage:${{ steps.majorver.outputs.major-tag }}

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# GO_VERSION: automatically update to most recent via dependabot
2-
FROM golang:1.25.3 AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.25.3 AS builder
3+
34
WORKDIR /workspace
45

56
COPY go.mod go.mod
@@ -10,10 +11,13 @@ RUN go mod download all
1011
COPY ./ ./
1112

1213
ARG VERSION
13-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
14+
ARG TARGETOS
15+
ARG TARGETARCH
16+
17+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
1418
go build -o go-test-coverage .
1519

16-
FROM gcr.io/distroless/base:latest
20+
FROM --platform=$BUILDPLATFORM gcr.io/distroless/base:latest
1721
WORKDIR /
1822
COPY --from=builder /workspace/go-test-coverage .
1923
COPY --from=builder /usr/local/go/bin/go /usr/local/go/bin/go

0 commit comments

Comments
 (0)