1+ # Recipe based on: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
12name : Publish tutorial docker image
23on :
34 push :
2930 - name : Checkout repository
3031 uses : actions/checkout@v4
3132
32- - name : Set up QEMU
33- uses : docker/setup-qemu-action@v3
33+ # - name: Set up QEMU
34+ # uses: docker/setup-qemu-action@v3
3435
3536 - name : Set up Docker Buildx
3637 uses : docker/setup-buildx-action@v3
4142 registry : ${{ env.REGISTRY }}
4243 username : ${{ github.actor }}
4344 password : ${{ secrets.GITHUB_TOKEN }}
45+ - name : Extract metadata (tags, labels) for Docker
46+ id : meta
47+ uses : docker/metadata-action@v5
48+ with :
49+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4450
4551 - name : Set architecture tag (amd64)
4652 if : ${{ matrix.os == 'ubuntu-24.04' }}
@@ -56,37 +62,97 @@ jobs:
5662 with :
5763 images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5864
59- - name : Build Docker image
65+
66+ - name : Build and push by digest
67+ id : build
6068 uses : docker/build-push-action@v6
6169 with :
62- context : .
63- load : true
64- push : false
65- file : docker/Dockerfile
66- platforms : linux/${{ env.ARCH_TAG }}
67- tags : ${{ steps.meta.outputs.tags }}
70+ platforms : ${{ matrix.os }}
6871 labels : ${{ steps.meta.outputs.labels }}
69- outputs : type=docker, dest=${{ runner.temp }}/image.tar
72+ outputs : type=image,"name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}",push-by-digest=true,name-canonical=true,push=true
73+
74+ - name : Export digest
75+ run : |
76+ mkdir -p ${{ runner.temp }}/digests
77+ digest="${{ steps.build.outputs.digest }}"
78+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
7079
71- - name : Upload artifact
80+ - name : Upload digest
7281 uses : actions/upload-artifact@v4
7382 with :
74- name : ${{ matrix.os}}.tar
75- path : ${{ runner.temp }}/image.tar
83+ name : digests-${{ matrix.os }}
84+ path : ${{ runner.temp }}/digests/*
85+ if-no-files-found : error
7686 retention-days : 1
77-
78- push :
87+
88+ merge :
7989 runs-on : ubuntu-latest
80- needs : build
90+ needs :
91+ - build
8192 steps :
82- - name : Download artifacts
93+ - name : Download digests
8394 uses : actions/download-artifact@v4
8495 with :
85- pattern : " ubuntu-*.tar"
86- path : images
96+ path : ${{ runner.temp }}/digests
97+ pattern : digests-*
98+ merge-multiple : true
8799
88- - name : Load image (arm)
100+ - name : Log in to the Container registry
101+ uses : docker/login-action@v3
102+ with :
103+ registry : ${{ env.REGISTRY }}
104+ username : ${{ github.actor }}
105+ password : ${{ secrets.GITHUB_TOKEN }}
106+
107+ - name : Extract metadata (tags, labels) for Docker
108+ id : meta
109+ uses : docker/metadata-action@v5
110+ with :
111+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
112+
113+
114+ - name : Create manifest list and push
115+ working-directory : ${{ runner.temp }}/digests
116+ run : |
117+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
118+ $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}@sha256:%s ' *)
119+
120+ - name : Inspect image
89121 run : |
90- docker load --input images/ubuntu-24.04-arm.tar
91- docker load --input images/ubuntu-24.04.tar
92- docker image ls -a
122+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:${{ steps.meta.outputs.version }}
123+
124+ # - name: Build Docker image
125+ # uses: docker/build-push-action@v6
126+ # with:
127+ # context: .
128+ # load: true
129+ # push: false
130+ # file: docker/Dockerfile
131+ # platforms: linux/${{ env.ARCH_TAG }}
132+ # tags: ${{ steps.meta.outputs.tags }}
133+ # labels: ${{ steps.meta.outputs.labels }}
134+ # outputs: type=docker, dest=${{ runner.temp }}/image.tar
135+
136+ # - name: Upload artifact
137+ # uses: actions/upload-artifact@v4
138+ # with:
139+ # name: ${{ matrix.os}}
140+ # path: ${{ runner.temp }}/image.tar
141+ # retention-days: 1
142+
143+ # push:
144+ # runs-on: ubuntu-latest
145+ # needs: build
146+ # steps:
147+ # - name: Download artifacts
148+ # uses: actions/download-artifact@v4
149+ # with:
150+ # pattern: "ubuntu-*.tar"
151+ # path: images
152+
153+ # - name: Load image (arm)
154+ # run: |
155+ # ls -l images/
156+ # # docker load --input images/ubuntu-24.04-arm.tar
157+ # # docker load --input images/ubuntu-24.04.tar
158+ # # docker image ls -a
0 commit comments