Skip to content

Commit 24bc24a

Browse files
committed
feat: matrix ci
1 parent 5d4a075 commit 24bc24a

File tree

3 files changed

+197
-38
lines changed

3 files changed

+197
-38
lines changed

.github/workflows/docker-image-alpha.yml

Lines changed: 101 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,135 @@ on:
1111
required: false
1212

1313
jobs:
14-
push_to_registries:
15-
name: Push Docker image to multiple registries
16-
runs-on: ubuntu-latest
14+
build_single_arch:
15+
name: Build & push (${{ matrix.arch }}) [native]
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- arch: amd64
21+
platform: linux/amd64
22+
runner: ubuntu-latest
23+
- arch: arm64
24+
platform: linux/arm64
25+
runner: ubuntu-24.04-arm64
26+
runs-on: ${{ matrix.runner }}
1727
permissions:
1828
packages: write
1929
contents: read
2030
steps:
21-
- name: Check out the repo
31+
- name: Check out (shallow)
2232
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 1
2335

24-
- name: Save version info
36+
- name: Determine alpha version
37+
id: version
2538
run: |
26-
echo "alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" > VERSION
39+
VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
40+
echo "$VERSION" > VERSION
41+
echo "value=$VERSION" >> $GITHUB_OUTPUT
42+
echo "VERSION=$VERSION" >> $GITHUB_ENV
43+
echo "Publishing version: $VERSION for ${{ matrix.arch }}"
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
2747

2848
- name: Log in to Docker Hub
2949
uses: docker/login-action@v3
3050
with:
3151
username: ${{ secrets.DOCKERHUB_USERNAME }}
3252
password: ${{ secrets.DOCKERHUB_TOKEN }}
3353

34-
- name: Log in to the Container registry
54+
- name: Log in to GHCR
3555
uses: docker/login-action@v3
3656
with:
3757
registry: ghcr.io
3858
username: ${{ github.actor }}
3959
password: ${{ secrets.GITHUB_TOKEN }}
4060

41-
- name: Set up Docker Buildx
42-
uses: docker/setup-buildx-action@v3
43-
44-
- name: Extract metadata (tags, labels) for Docker
61+
- name: Extract metadata (labels)
4562
id: meta
4663
uses: docker/metadata-action@v5
4764
with:
4865
images: |
4966
calciumion/new-api
5067
ghcr.io/${{ github.repository }}
51-
tags: |
52-
type=raw,value=alpha
53-
type=raw,value=alpha-{{date 'YYYYMMDD'}}-{{sha}}
5468
55-
- name: Build and push Docker images
56-
uses: docker/build-push-action@v5
69+
- name: Build & push single-arch (to both registries)
70+
uses: docker/build-push-action@v6
5771
with:
5872
context: .
59-
platforms: linux/amd64,linux/arm64
73+
platforms: ${{ matrix.platform }}
6074
push: true
61-
tags: ${{ steps.meta.outputs.tags }}
75+
tags: |
76+
calciumion/new-api:alpha-${{ matrix.arch }}
77+
calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }}
78+
ghcr.io/${{ github.repository }}:alpha-${{ matrix.arch }}
79+
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.value }}-${{ matrix.arch }}
6280
labels: ${{ steps.meta.outputs.labels }}
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
provenance: false
84+
sbom: false
85+
86+
create_manifests:
87+
name: Create multi-arch manifests (Docker Hub + GHCR)
88+
needs: [build_single_arch]
89+
runs-on: ubuntu-latest
90+
permissions:
91+
packages: write
92+
contents: read
93+
steps:
94+
- name: Check out (shallow)
95+
uses: actions/checkout@v4
96+
with:
97+
fetch-depth: 1
98+
99+
- name: Determine alpha version
100+
id: version
101+
run: |
102+
VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
103+
echo "value=$VERSION" >> $GITHUB_OUTPUT
104+
echo "VERSION=$VERSION" >> $GITHUB_ENV
105+
106+
- name: Log in to Docker Hub
107+
uses: docker/login-action@v3
108+
with:
109+
username: ${{ secrets.DOCKERHUB_USERNAME }}
110+
password: ${{ secrets.DOCKERHUB_TOKEN }}
111+
112+
- name: Create & push manifest (Docker Hub - alpha)
113+
run: |
114+
docker buildx imagetools create \
115+
-t calciumion/new-api:alpha \
116+
calciumion/new-api:alpha-amd64 \
117+
calciumion/new-api:alpha-arm64
118+
119+
- name: Create & push manifest (Docker Hub - versioned alpha)
120+
run: |
121+
docker buildx imagetools create \
122+
-t calciumion/new-api:${VERSION} \
123+
calciumion/new-api:${VERSION}-amd64 \
124+
calciumion/new-api:${VERSION}-arm64
125+
126+
- name: Log in to GHCR
127+
uses: docker/login-action@v3
128+
with:
129+
registry: ghcr.io
130+
username: ${{ github.actor }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
132+
133+
- name: Create & push manifest (GHCR - alpha)
134+
run: |
135+
docker buildx imagetools create \
136+
-t ghcr.io/${GITHUB_REPOSITORY}:alpha \
137+
ghcr.io/${GITHUB_REPOSITORY}:alpha-amd64 \
138+
ghcr.io/${GITHUB_REPOSITORY}:alpha-arm64
139+
140+
- name: Create & push manifest (GHCR - versioned alpha)
141+
run: |
142+
docker buildx imagetools create \
143+
-t ghcr.io/${GITHUB_REPOSITORY}:${VERSION} \
144+
ghcr.io/${GITHUB_REPOSITORY}:${VERSION}-amd64 \
145+
ghcr.io/${GITHUB_REPOSITORY}:${VERSION}-arm64
Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
1-
name: Publish Docker image (Multi Registries)
1+
name: Publish Docker image (Multi Registries, native amd64+arm64)
22

33
on:
44
push:
55
tags:
66
- '*'
7+
78
jobs:
8-
push_to_registries:
9-
name: Push Docker image to multiple registries
10-
runs-on: ubuntu-latest
9+
build_single_arch:
10+
name: Build & push (${{ matrix.arch }}) [native]
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- arch: amd64
16+
platform: linux/amd64
17+
runner: ubuntu-latest
18+
- arch: arm64
19+
platform: linux/arm64
20+
runner: ubuntu-24.04-arm64
21+
runs-on: ${{ matrix.runner }}
22+
1123
permissions:
1224
packages: write
1325
contents: read
26+
1427
steps:
15-
- name: Check out the repo
28+
- name: Check out (shallow)
1629
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
1732

18-
- name: Save version info
33+
- name: Resolve tag & write VERSION
1934
run: |
20-
git describe --tags > VERSION
21-
22-
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v3
35+
git fetch --tags --force --depth=1
36+
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
37+
echo "$TAG" > VERSION
38+
echo "Building tag: $TAG for ${{ matrix.arch }}"
2439
2540
- name: Set up Docker Buildx
2641
uses: docker/setup-buildx-action@v3
@@ -31,26 +46,85 @@ jobs:
3146
username: ${{ secrets.DOCKERHUB_USERNAME }}
3247
password: ${{ secrets.DOCKERHUB_TOKEN }}
3348

34-
- name: Log in to the Container registry
49+
- name: Log in to GHCR
3550
uses: docker/login-action@v3
3651
with:
3752
registry: ghcr.io
3853
username: ${{ github.actor }}
3954
password: ${{ secrets.GITHUB_TOKEN }}
4055

41-
- name: Extract metadata (tags, labels) for Docker
56+
- name: Extract metadata (labels)
4257
id: meta
4358
uses: docker/metadata-action@v5
4459
with:
4560
images: |
4661
calciumion/new-api
4762
ghcr.io/${{ github.repository }}
4863
49-
- name: Build and push Docker images
50-
uses: docker/build-push-action@v5
64+
- name: Build & push single-arch (to both registries)
65+
uses: docker/build-push-action@v6
5166
with:
5267
context: .
53-
platforms: linux/amd64,linux/arm64
68+
platforms: ${{ matrix.platform }}
5469
push: true
55-
tags: ${{ steps.meta.outputs.tags }}
56-
labels: ${{ steps.meta.outputs.labels }}
70+
tags: |
71+
calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}
72+
calciumion/new-api:latest-${{ matrix.arch }}
73+
ghcr.io/${{ github.repository }}:${{ env.TAG }}-${{ matrix.arch }}
74+
ghcr.io/${{ github.repository }}:latest-${{ matrix.arch }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max
78+
provenance: false
79+
sbom: false
80+
81+
create_manifests:
82+
name: Create multi-arch manifests (Docker Hub + GHCR)
83+
needs: [build_single_arch]
84+
runs-on: ubuntu-latest
85+
if: startsWith(github.ref, 'refs/tags/')
86+
steps:
87+
- name: Extract tag
88+
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
89+
90+
- name: Log in to Docker Hub
91+
uses: docker/login-action@v3
92+
with:
93+
username: ${{ secrets.DOCKERHUB_USERNAME }}
94+
password: ${{ secrets.DOCKERHUB_TOKEN }}
95+
96+
- name: Create & push manifest (Docker Hub - version)
97+
run: |
98+
docker buildx imagetools create \
99+
-t calciumion/new-api:${TAG} \
100+
calciumion/new-api:${TAG}-amd64 \
101+
calciumion/new-api:${TAG}-arm64
102+
103+
- name: Create & push manifest (Docker Hub - latest)
104+
run: |
105+
docker buildx imagetools create \
106+
-t calciumion/new-api:latest \
107+
calciumion/new-api:latest-amd64 \
108+
calciumion/new-api:latest-arm64
109+
110+
# ---- GHCR ----
111+
- name: Log in to GHCR
112+
uses: docker/login-action@v3
113+
with:
114+
registry: ghcr.io
115+
username: ${{ github.actor }}
116+
password: ${{ secrets.GITHUB_TOKEN }}
117+
118+
- name: Create & push manifest (GHCR - version)
119+
run: |
120+
docker buildx imagetools create \
121+
-t ghcr.io/${GITHUB_REPOSITORY}:${TAG} \
122+
ghcr.io/${GITHUB_REPOSITORY}:${TAG}-amd64 \
123+
ghcr.io/${GITHUB_REPOSITORY}:${TAG}-arm64
124+
125+
- name: Create & push manifest (GHCR - latest)
126+
run: |
127+
docker buildx imagetools create \
128+
-t ghcr.io/${GITHUB_REPOSITORY}:latest \
129+
ghcr.io/${GITHUB_REPOSITORY}:latest-amd64 \
130+
ghcr.io/${GITHUB_REPOSITORY}:latest-arm64

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ COPY ./VERSION .
99
RUN DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) bun run build
1010

1111
FROM golang:alpine AS builder2
12+
ENV GO111MODULE=on CGO_ENABLED=0
13+
14+
ARG TARGETOS
15+
ARG TARGETARCH
16+
ENV GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64}
1217

13-
ENV GO111MODULE=on \
14-
CGO_ENABLED=0 \
15-
GOOS=linux
1618

1719
WORKDIR /build
1820

0 commit comments

Comments
 (0)