1- name : Build and push to DockerHub
1+ name : " Build and push to DockerHub"
22
33on :
44 push :
77
88env :
99 REGISTRY : docker.io
10- IMAGE_NAME : ${{ github.repository }}
10+ REGISTRY_IMAGE : ${{ github.repository }}
1111
1212jobs :
13- build-deploy :
13+ build :
1414 runs-on : ubuntu-latest
15+ strategy :
16+ fail-fast : false
17+ matrix :
18+ platform :
19+ - linux/amd64
20+ - linux/arm/v6
21+ - linux/arm/v7
22+ - linux/arm64
23+
1524 if : startsWith(github.event.ref, 'refs/tags/v')
1625 steps :
26+ - name : " Prepare"
27+ run : |
28+ platform=${{ matrix.platform }}
29+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
30+
1731 - name : " Check out"
1832 uses : actions/checkout@v4
1933
@@ -31,18 +45,66 @@ jobs:
3145 uses : docker/metadata-action@v5
3246 with :
3347 images : |
34- ${{ env.IMAGE_NAME }}
48+ ${{ env.REGISTRY_IMAGE }}
3549 tags : |
3650 type=semver,pattern={{version}}
3751
38- - name : " Test Docker image"
39- run : |
40- docker run --rm -d ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
41-
42- - name : " Build and push"
52+ - name : Build and push by digest
53+ id : build
4354 uses : docker/build-push-action@v6
4455 with :
45- context : .
46- push : true
47- tags : ${{ steps.meta.outputs.tags }}
56+ platforms : ${{ matrix.platform }}
4857 labels : ${{ steps.meta.outputs.labels }}
58+ outputs : type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
59+
60+
61+ - name : " Export digest"
62+ run : |
63+ mkdir -p /tmp/digests
64+ digest="${{ steps.build.outputs.digest }}"
65+ touch "/tmp/digests/${digest#sha256:}"
66+
67+ - name : " Upload digest"
68+ uses : actions/upload-artifact@v4
69+ with :
70+ name : digests-${{ env.PLATFORM_PAIR }}
71+ path : /tmp/digests/*
72+ if-no-files-found : error
73+ retention-days : 1
74+
75+ merge-push :
76+ runs-on : ubuntu-latest
77+ needs :
78+ - build
79+ steps :
80+ - name : " Download digests"
81+ uses : actions/download-artifact@v4
82+ with :
83+ path : /tmp/digests
84+ pattern : digests-*
85+ merge-multiple : true
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 : ${{ env.REGISTRY_IMAGE }}
95+
96+ - name : " Login to Docker Hub"
97+ uses : docker/login-action@v3
98+ with :
99+ username : ${{ secrets.DOCKERHUB_USERNAME }}
100+ password : ${{ secrets.DOCKERHUB_TOKEN }}
101+
102+ - name : " Create manifest list and push"
103+ working-directory : /tmp/digests
104+ run : |
105+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
106+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
107+
108+ - name : " Inspect image"
109+ run : |
110+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments