Skip to content

Commit 84901f0

Browse files
committed
ci: add multiple docker image arch
1 parent 296d4e4 commit 84901f0

2 files changed

Lines changed: 61 additions & 8 deletions

File tree

.github/workflows/docker.yml

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ env:
1313

1414
jobs:
1515
build:
16-
runs-on: ubuntu-latest
16+
name: Build ${{ matrix.platform }}
17+
runs-on: ${{ matrix.runner }}
1718
permissions:
1819
contents: read
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- arch: amd64
25+
platform: linux/amd64
26+
runner: ubuntu-latest
27+
- arch: arm64
28+
platform: linux/arm64
29+
runner: ubuntu-24.04-arm
1930
steps:
2031
- name: Checkout
2132
uses: actions/checkout@v4
@@ -36,15 +47,55 @@ jobs:
3647
images: ${{ env.IMAGE_NAME }}
3748
tags: |
3849
type=ref,event=tag
39-
type=ref,event=branch
50+
type=raw,value=latest,enable={{is_default_branch}}
4051
type=sha
52+
flavor: |
53+
suffix=-${{ matrix.arch }}
4154
42-
- name: Build and push
55+
- name: Build and push (${{ matrix.platform }})
4356
uses: docker/build-push-action@v6
4457
with:
4558
context: .
4659
file: ./Dockerfile
4760
push: true
48-
platforms: linux/amd64
61+
platforms: ${{ matrix.platform }}
4962
tags: ${{ steps.meta.outputs.tags }}
5063
labels: ${{ steps.meta.outputs.labels }}
64+
65+
manifest:
66+
name: Publish multi-arch manifests
67+
runs-on: ubuntu-latest
68+
needs: build
69+
permissions:
70+
contents: read
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v4
74+
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v3
77+
78+
- name: Log in to Docker Hub
79+
uses: docker/login-action@v3
80+
with:
81+
username: ${{ secrets.DOCKERHUB_USERNAME }}
82+
password: ${{ secrets.DOCKERHUB_TOKEN }}
83+
84+
- name: Docker metadata
85+
id: meta
86+
uses: docker/metadata-action@v5
87+
with:
88+
images: ${{ env.IMAGE_NAME }}
89+
tags: |
90+
type=ref,event=tag
91+
type=raw,value=latest,enable={{is_default_branch}}
92+
type=sha
93+
94+
- name: Create multi-arch manifests
95+
run: |
96+
while IFS= read -r tag; do
97+
docker buildx imagetools create \
98+
-t "$tag" \
99+
"$tag-amd64" \
100+
"$tag-arm64"
101+
done <<< "${{ steps.meta.outputs.tags }}"

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
ARG NODE_VERSION=22
22
ARG GO_VERSION=1.24
33

4-
FROM node:${NODE_VERSION}-alpine AS frontend
4+
FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-alpine AS frontend
55
WORKDIR /app
66
COPY web/package.json web/package-lock.json ./web/
77
RUN cd web && npm ci
88
COPY web ./web
99
RUN cd web && npm run build
1010

11-
FROM golang:${GO_VERSION}-alpine AS backend
11+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS backend
12+
ARG TARGETOS
13+
ARG TARGETARCH
1214
WORKDIR /app
1315
RUN apk add --no-cache git ca-certificates
1416
COPY go.mod go.sum ./
@@ -21,9 +23,9 @@ COPY web/tailwind.config.cjs web/postcss.config.cjs web/vite.config.ts web/tscon
2123
COPY web/src ./web/src
2224
COPY --from=frontend /app/web/dist ./web/dist
2325
RUN mkdir -p internal/static && rm -rf internal/static/dist && cp -r web/dist internal/static/dist
24-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /dashboard ./cmd/dashboard
26+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /dashboard ./cmd/dashboard
2527

26-
FROM gcr.io/distroless/base-debian12:nonroot
28+
FROM --platform=$TARGETPLATFORM gcr.io/distroless/base-debian12:nonroot
2729
WORKDIR /app
2830
COPY --from=backend /dashboard /app/dashboard
2931
ENV LISTEN_ADDR=:9090

0 commit comments

Comments
 (0)