Skip to content

Commit 50a4185

Browse files
authored
ci: fix multi-arch manifest by building per-platform then merging (#288)
Previously each matrix job pushed the same final tags independently, so whichever job finished last silently overwrote the other — leaving only a single-arch manifest under every tag. Now each matrix job pushes a platform-specific temp tag, and a dedicated merge job uses docker buildx imagetools create to assemble the final multi-arch manifest list for both DockerHub and GHCR. Also adds packages: write permission required for GHCR pushes.
1 parent e221214 commit 50a4185

1 file changed

Lines changed: 60 additions & 17 deletions

File tree

.github/workflows/update-current-image.yml

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ concurrency:
1616

1717
env:
1818
IMAGE_NAME: node-minimal
19+
GHCR_IMAGE: ghcr.io/chorrell/node-minimal
1920

2021
permissions:
2122
contents: read
23+
packages: write
2224

2325
jobs:
2426
check_version:
@@ -53,7 +55,7 @@ jobs:
5355
echo "No new Node.js versions to build"
5456
fi
5557
56-
build_push:
58+
build:
5759
strategy:
5860
matrix:
5961
os:
@@ -126,37 +128,78 @@ jobs:
126128
username: ${{ github.repository_owner }}
127129
password: ${{ secrets.CR_PAT }}
128130

129-
- name: Build
131+
- name: Build test image
130132
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
131133
env:
132134
DOCKER_BUILD_SUMMARY: false
133135
with:
134136
context: .
135137
platforms: linux/${{ matrix.platform }}
136138
load: true
137-
tags: ${{ env.IMAGE_NAME }}-${{ needs.check_version.outputs.NODE_VERSION }}
139+
tags: ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }}
138140

139141
- name: Test Image
140142
run: docker run --rm "${IMAGE_NAME}-${NODE_VERSION}" -e "console.log('Hello from Node.js ' + process.version)"
141143

142-
- name: Docker meta
143-
id: meta
144-
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
145-
with:
146-
flavor: latest=true
147-
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}, ghcr.io/chorrell/${{ env.IMAGE_NAME }}
148-
tags: |
149-
${{ env.NODE_VERSION }}
150-
${{ env.MAJOR_VERSION }}
151-
current
152-
153-
- name: Build and push Image
144+
- name: Build and push per-platform image
154145
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
155146
with:
156147
context: .
157148
platforms: linux/${{ matrix.platform }}
158149
push: true
159150
provenance: mode=max
160151
sbom: true
161-
tags: ${{ steps.meta.outputs.tags }}
162-
labels: ${{ steps.meta.outputs.labels }}
152+
tags: |
153+
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-${{ matrix.platform }}
154+
${{ env.GHCR_IMAGE }}:build-${{ github.run_id }}-${{ matrix.platform }}
155+
156+
merge:
157+
needs: [check_version, build]
158+
runs-on: ubuntu-latest
159+
env:
160+
NODE_VERSION: ${{ needs.check_version.outputs.NODE_VERSION }}
161+
162+
steps:
163+
- name: Set up Docker Buildx
164+
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
165+
166+
- name: Login to DockerHub
167+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
168+
with:
169+
username: ${{ secrets.DOCKERHUB_USERNAME }}
170+
password: ${{ secrets.DOCKERHUB_TOKEN }}
171+
172+
- name: Login to GitHub Container Registry
173+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
174+
with:
175+
registry: ghcr.io
176+
username: ${{ github.repository_owner }}
177+
password: ${{ secrets.CR_PAT }}
178+
179+
- name: Set major version
180+
run: echo "MAJOR_VERSION=$(echo "$NODE_VERSION" | cut -d'.' -f 1)" >> $GITHUB_ENV
181+
182+
- name: Create DockerHub multi-arch manifests
183+
run: |
184+
REPO="${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}"
185+
docker buildx imagetools create \
186+
-t "${REPO}:${{ env.NODE_VERSION }}" \
187+
-t "${REPO}:${{ env.MAJOR_VERSION }}" \
188+
-t "${REPO}:current" \
189+
-t "${REPO}:latest" \
190+
"${REPO}:build-${{ github.run_id }}-amd64" \
191+
"${REPO}:build-${{ github.run_id }}-arm64"
192+
193+
- name: Create GHCR multi-arch manifests
194+
run: |
195+
docker buildx imagetools create \
196+
-t "${{ env.GHCR_IMAGE }}:${{ env.NODE_VERSION }}" \
197+
-t "${{ env.GHCR_IMAGE }}:${{ env.MAJOR_VERSION }}" \
198+
-t "${{ env.GHCR_IMAGE }}:current" \
199+
-t "${{ env.GHCR_IMAGE }}:latest" \
200+
"${{ env.GHCR_IMAGE }}:build-${{ github.run_id }}-amd64" \
201+
"${{ env.GHCR_IMAGE }}:build-${{ github.run_id }}-arm64"
202+
203+
- name: Inspect manifest
204+
run: |
205+
docker buildx imagetools inspect "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.NODE_VERSION }}"

0 commit comments

Comments
 (0)