Skip to content

Commit 25a74eb

Browse files
authored
Merge pull request #29 from patchlevel/fix-docker-publish
fix multi arch builds
2 parents 771abbd + 866636d commit 25a74eb

File tree

1 file changed

+110
-12
lines changed

1 file changed

+110
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 110 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
22

3-
name: "Continues Integration"
3+
name: "Continuous Integration"
44

55
on:
66
pull_request:
@@ -15,17 +15,28 @@ env:
1515
REGISTRY: ghcr.io
1616
IMAGE_NAME: ghcr.io/${{ github.repository }}
1717

18+
permissions:
19+
contents: read
20+
packages: write
21+
1822
jobs:
1923
build:
20-
name: Build Docker image
21-
24+
name: Build per-arch (push by digest on main)
2225
strategy:
26+
fail-fast: false
2327
matrix:
24-
platform: [ 'linux/amd64', 'linux/arm64' ]
25-
version: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]
26-
extensions: [ 'pcntl xdebug zip intl bcmath rdkafka pdo_pgsql pdo_mysql gd opentelemetry mongodb' ]
28+
platform:
29+
- platform: linux/amd64
30+
runner: ubuntu-24.04
31+
id: linux-amd64
32+
- platform: linux/arm64
33+
runner: ubuntu-24.04-arm
34+
id: linux-arm64
35+
version: [ "8.1", "8.2", "8.3", "8.4", "8.5" ]
36+
extensions:
37+
- "pcntl xdebug zip intl bcmath rdkafka pdo_pgsql pdo_mysql gd opentelemetry mongodb"
2738

28-
runs-on: ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
39+
runs-on: ${{ matrix.platform.runner }}
2940

3041
steps:
3142
- name: Check out the repo
@@ -35,29 +46,116 @@ jobs:
3546
uses: docker/setup-buildx-action@v3
3647

3748
- name: Login to GitHub Container Registry
49+
if: ${{ github.ref_name == 'main' }}
3850
uses: docker/login-action@v3
3951
with:
4052
registry: ${{ env.REGISTRY }}
4153
username: ${{ github.actor }}
4254
password: ${{ secrets.GITHUB_TOKEN }}
4355

44-
- name: Extract metadata (tags, labels) for Docker
56+
- name: Extract metadata (labels) for Docker
4557
id: meta
4658
uses: docker/metadata-action@v5
4759
with:
4860
images: ${{ env.IMAGE_NAME }}
49-
tags: ${{ matrix.version }}
61+
tags: |
62+
type=raw,value=${{ matrix.version }}
5063
51-
- name: Build and Push to GitHub Packages
64+
- name: Build (no push)
65+
if: ${{ github.ref_name != 'main' }}
5266
uses: docker/build-push-action@v6
5367
with:
54-
tags: ${{ steps.meta.outputs.tags }}
68+
context: .
69+
platforms: ${{ matrix.platform.platform }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
cache-from: |
72+
type=gha,scope=ci-cache
73+
cache-to: type=gha,mode=max,scope=ci-cache
74+
push: false
75+
build-args: |
76+
VERSION=${{ matrix.version }}
77+
EXTENSIONS=${{ matrix.extensions }}
78+
79+
- name: Build and push (main only)
80+
id: build_push
81+
if: ${{ github.ref_name == 'main' }}
82+
uses: docker/build-push-action@v6
83+
with:
84+
context: .
85+
platforms: ${{ matrix.platform.platform }}
5586
labels: ${{ steps.meta.outputs.labels }}
5687
cache-from: |
5788
type=gha,scope=ci-cache
5889
type=gha,scope=release-cache
5990
cache-to: type=gha,mode=max,scope=release-cache
60-
push: ${{ github.ref_name == 'main' }}
91+
outputs: |
92+
type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
6193
build-args: |
6294
VERSION=${{ matrix.version }}
6395
EXTENSIONS=${{ matrix.extensions }}
96+
97+
- name: Store digest (main only)
98+
if: ${{ github.ref_name == 'main' }}
99+
run: |
100+
mkdir -p /tmp/digests
101+
echo "${{ steps.build_push.outputs.digest }}" > "/tmp/digests/${{ matrix.version }}-${{ matrix.platform.id }}.txt"
102+
103+
- name: Upload digests (main only)
104+
if: ${{ github.ref_name == 'main' }}
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: digests-${{ matrix.version }}-${{ matrix.platform.id }}
108+
path: /tmp/digests/${{ matrix.version }}-${{ matrix.platform.id }}.txt
109+
if-no-files-found: error
110+
retention-days: 1
111+
112+
merge:
113+
name: Create multi-arch manifest (main only)
114+
if: ${{ github.ref_name == 'main' }}
115+
needs: build
116+
runs-on: ubuntu-24.04
117+
118+
strategy:
119+
fail-fast: false
120+
matrix:
121+
version: [ "8.1", "8.2", "8.3", "8.4", "8.5" ]
122+
123+
steps:
124+
- name: Set up Docker Buildx
125+
uses: docker/setup-buildx-action@v3
126+
127+
- name: Login to GitHub Container Registry
128+
uses: docker/login-action@v3
129+
with:
130+
registry: ${{ env.REGISTRY }}
131+
username: ${{ github.actor }}
132+
password: ${{ secrets.GITHUB_TOKEN }}
133+
134+
- name: Download digests (amd64)
135+
uses: actions/download-artifact@v4
136+
with:
137+
name: digests-${{ matrix.version }}-linux-amd64
138+
path: /tmp/digests
139+
140+
- name: Download digests (arm64)
141+
uses: actions/download-artifact@v4
142+
with:
143+
name: digests-${{ matrix.version }}-linux-arm64
144+
path: /tmp/digests
145+
146+
- name: Create and push manifest list tag
147+
run: |
148+
set -euo pipefail
149+
150+
AMD_DIGEST="$(cat /tmp/digests/${{ matrix.version }}-linux-amd64.txt)"
151+
ARM_DIGEST="$(cat /tmp/digests/${{ matrix.version }}-linux-arm64.txt)"
152+
153+
# Create a multi-arch manifest for :<version> that points to both per-arch digests
154+
docker buildx imagetools create \
155+
-t "${{ env.IMAGE_NAME }}:${{ matrix.version }}" \
156+
"${{ env.IMAGE_NAME }}@${AMD_DIGEST}" \
157+
"${{ env.IMAGE_NAME }}@${ARM_DIGEST}"
158+
159+
- name: Inspect manifest (debug)
160+
run: |
161+
docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${{ matrix.version }}"

0 commit comments

Comments
 (0)