Skip to content

Commit 16ef2b7

Browse files
committed
ci: Fixed multi-platform images push overrides by merging the results (based on docker/docs#21854)
1 parent bf85168 commit 16ef2b7

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

.github/workflows/build-and-push.yaml

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
# Daily
99
- cron: '0 0 * * *'
1010

11+
env:
12+
DOCKERHUB_REPO: frolvlad/alpine-glibc
13+
1114
jobs:
1215
build:
1316
strategy:
@@ -20,6 +23,18 @@ jobs:
2023
os: ubuntu-24.04-arm
2124
runs-on: ${{ matrix.os }}
2225
steps:
26+
- name: Prepare
27+
run: |
28+
platform=${{ matrix.platform }}
29+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
30+
31+
- name: Docker meta
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: |
36+
${{ env.DOCKERHUB_REPO }}
37+
2338
- name: Login to Docker Hub
2439
uses: docker/login-action@v3
2540
with:
@@ -34,8 +49,62 @@ jobs:
3449
uses: docker/build-push-action@v6
3550
with:
3651
platforms: ${{ matrix.platform }}
37-
pull: true
38-
push: true
39-
tags: frolvlad/alpine-glibc:latest,frolvlad/alpine-glibc:alpine-3.21_glibc-2.41,frolvlad/alpine-glibc:alpine-3_glibc-2.41,frolvlad/alpine-glibc:alpine-3.21,frolvlad/alpine-glibc:alpine-3,frolvlad/alpine-glibc:glibc-2.41
40-
cache-from: type=registry,ref=frolvlad/alpine-glibc:latest
41-
cache-to: type=inline
52+
labels: ${{ steps.meta.outputs.labels }}
53+
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }}",push-by-digest=true,name-canonical=true,push=true
54+
55+
- name: Export digest
56+
run: |
57+
mkdir -p ${{ runner.temp }}/digests
58+
digest="${{ steps.build.outputs.digest }}"
59+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
60+
61+
- name: Upload digest
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: digests-${{ env.PLATFORM_PAIR }}
65+
path: ${{ runner.temp }}/digests/*
66+
if-no-files-found: error
67+
retention-days: 1
68+
69+
merge:
70+
runs-on: ubuntu-latest
71+
needs:
72+
- build
73+
steps:
74+
- name: Download digests
75+
uses: actions/download-artifact@v4
76+
with:
77+
path: ${{ runner.temp }}/digests
78+
pattern: digests-*
79+
merge-multiple: true
80+
81+
- name: Login to Docker Hub
82+
uses: docker/login-action@v3
83+
with:
84+
username: ${{ secrets.DOCKERHUB_USERNAME }}
85+
password: ${{ secrets.DOCKERHUB_TOKEN }}
86+
87+
- name: Set up Docker Buildx
88+
uses: docker/setup-buildx-action@v3
89+
90+
- name: Docker meta
91+
id: meta
92+
uses: docker/metadata-action@v5
93+
with:
94+
images: |
95+
${{ env.DOCKERHUB_REPO }}
96+
tags: |
97+
type=ref,event=branch
98+
type=ref,event=pr
99+
type=semver,pattern={{version}}
100+
type=semver,pattern={{major}}.{{minor}}
101+
102+
- name: Create manifest list and push
103+
working-directory: ${{ runner.temp }}/digests
104+
run: |
105+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
106+
$(printf '${{ env.DOCKERHUB_REPO }}@sha256:%s ' *)
107+
108+
- name: Inspect image
109+
run: |
110+
docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)