Skip to content

Commit c22819b

Browse files
committed
Split publish workflow to native runners
This sets up a build matrix so that both amd64 and arm64 images are built on native GH runners instead of in QEMU
1 parent 5a24aa6 commit c22819b

1 file changed

Lines changed: 89 additions & 7 deletions

File tree

.github/workflows/publish.yml

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,112 @@ on:
88
types:
99
- completed
1010

11+
env:
12+
REGISTRY_IMAGE: ghcr.io/memoryleek/party-api
13+
1114
jobs:
1215
build:
1316
runs-on: ubuntu-latest
1417
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
platform:
22+
- linux/amd64
23+
- linux/arm64
24+
include:
25+
- platform: linux/amd64
26+
runner: ubuntu-24.04
27+
- platform: linux/arm64
28+
runner: ubuntu-24.04-arm
1529
steps:
1630
- name: Checkout
1731
uses: actions/checkout@v5
1832

19-
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v3
33+
- name: Prepare
34+
run: |
35+
platform=${{ matrix.platform }}
36+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
37+
38+
- name: Docker meta
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ env.REGISTRY_IMAGE }}
43+
tags: latest
44+
45+
- name: Login to GitHub Container Registry
46+
uses: docker/login-action@v3
47+
with:
48+
registry: ghcr.io
49+
username: "${{ github.actor }}"
50+
password: "${{ secrets.GITHUB_TOKEN }}"
2151

2252
- name: Set up Docker Buildx
2353
uses: docker/setup-buildx-action@v3
2454

55+
- name: Build and push by digest
56+
id: build
57+
uses: docker/build-push-action@v6
58+
with:
59+
platforms: ${{ matrix.platform }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
tags: ${{ env.REGISTRY_IMAGE }}
62+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
63+
64+
- name: Export digest
65+
run: |
66+
mkdir -p ${{ runner.temp }}/digests
67+
digest="${{ steps.build.outputs.digest }}"
68+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
69+
70+
- name: Upload digest
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: digests-${{ env.PLATFORM_PAIR }}
74+
path: ${{ runner.temp }}/digests/*
75+
if-no-files-found: error
76+
retention-days: 1
77+
78+
merge:
79+
runs-on: ubuntu-latest
80+
needs:
81+
- build
82+
steps:
83+
- name: Download digests
84+
uses: actions/download-artifact@v4
85+
with:
86+
path: ${{ runner.temp }}/digests
87+
pattern: digests-*
88+
merge-multiple: true
89+
2590
- name: Login to GitHub Container Registry
2691
uses: docker/login-action@v3
2792
with:
2893
registry: ghcr.io
2994
username: "${{ github.actor }}"
3095
password: "${{ secrets.GITHUB_TOKEN }}"
3196

32-
- name: Build and push
33-
uses: docker/build-push-action@v6
97+
- name: Set up Docker Buildx
98+
uses: docker/setup-buildx-action@v3
99+
100+
- name: Docker meta
101+
id: meta
102+
uses: docker/metadata-action@v5
34103
with:
35-
platforms: linux/amd64,linux/arm64
36-
push: true
37-
tags: "ghcr.io/memoryleek/party-api:latest"
104+
images: ${{ env.REGISTRY_IMAGE }}
105+
tags: |
106+
type=ref,event=branch
107+
type=ref,event=pr
108+
type=semver,pattern={{version}}
109+
type=semver,pattern={{major}}.{{minor}}
110+
111+
- name: Create manifest list and push
112+
working-directory: ${{ runner.temp }}/digests
113+
run: |
114+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
115+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
116+
117+
- name: Inspect image
118+
run: |
119+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)