1111 required : true
1212 type : string
1313 description : ' name of the container build file to use'
14+ ref :
15+ required : false
16+ type : string
17+ description : ' git ref to checkout (defaults to version)'
1418 workflow_dispatch :
1519 inputs :
1620 version :
2125 required : true
2226 type : string
2327 description : ' name of the container build file to use'
28+ ref :
29+ required : false
30+ type : string
31+ description : ' git ref to checkout (defaults to version)'
2432
2533env :
2634 REGISTRY : ghcr.io
2735
2836jobs :
29- build-and-push-image :
30- name : " 🐳 Build and push image"
31- runs-on : ubuntu-latest
37+ build :
38+ name : " 🐳 Build (${{ matrix.platform }})"
39+ runs-on : ${{ matrix.runner }}
40+ strategy :
41+ fail-fast : false
42+ matrix :
43+ include :
44+ - platform : linux/amd64
45+ runner : ubuntu-latest
46+ - platform : linux/arm64
47+ runner : ubuntu-24.04-arm
3248 permissions :
3349 contents : read
3450 packages : write
3551
3652 steps :
53+ - name : " 🔧 Prepare"
54+ id : prepare
55+ run : |
56+ platform=${{ matrix.platform }}
57+ echo "pair=${platform//\//-}" >> $GITHUB_OUTPUT
58+ slug=$(echo "${{ inputs.buildfilename }}" | sed 's|[^a-zA-Z0-9]|-|g; s/^-*//; s/-*$//')
59+ echo "slug=${slug}" >> $GITHUB_OUTPUT
60+
3761 - name : " 🛍️ Checkout repository"
3862 uses : actions/checkout@v4
3963 with :
40- ref : ${{ inputs.version }}
41- fetch-depth : 0
42-
43- - name : " 🎛 Set up QEMU"
44- uses : docker/setup-qemu-action@v3
64+ ref : ${{ inputs.ref || inputs.version }}
4565
4666 - name : " 👷 Set up Docker Buildx"
47- id : buildx
4867 uses : docker/setup-buildx-action@v3
4968
5069 - name : " 🏷 Prepare OCI annotations"
@@ -68,23 +87,11 @@ jobs:
6887 export nameonly="${filename%.*}"
6988 if [ ${nameonly} == ${filename} ]; then echo "SUFFIX=" >> $GITHUB_ENV ; else echo "SUFFIX=-${nameonly}" >> $GITHUB_ENV; fi
7089
71- - name : " 🏷 Get SDK version from latest tag"
72- id : sdkversion
73- run : |
74- export version=$(git describe --tags --abbrev=0)
75- echo "CLAMS_VERSION=${version}" >> $GITHUB_OUTPUT
76-
77- - name : " 🏷 Prepare docker tags, labels"
90+ - name : " 🏷 Prepare docker labels"
7891 id : meta
7992 uses : docker/metadata-action@v5
80- env :
81- CLAMS_VERSION : ${{ steps.sdkversion.outputs.CLAMS_VERSION }}
8293 with :
8394 images : ${{ env.REGISTRY }}/${{ github.repository }}${{ env.SUFFIX }}
84- tags : |
85- type=pep440,pattern={{version}},value=${{ env.CLAMS_VERSION }}
86- type=ref,event=tag
87- type=ref,event=pr
8895 labels : |
8996 ${{ env.EXISTING_LABELS }}
9097
@@ -95,18 +102,84 @@ jobs:
95102 username : ${{ github.actor }}
96103 password : ${{ secrets.GITHUB_TOKEN }}
97104
98- - name : " 🏗 Build and push image"
99- uses : docker/build-push-action@v5
100- env :
101- CLAMS_VERSION : ${{ steps.sdkversion.outputs.CLAMS_VERSION }}
105+ - name : " 🏗 Build and push by digest"
106+ id : build
107+ uses : docker/build-push-action@v6
102108 with :
103109 context : ${{ env.CONTEXT }}
104- platforms : linux/amd64,linux/arm64
110+ platforms : ${{ matrix.platform }}
105111 file : ${{ inputs.buildfilename }}
106- tags : ${{ steps.meta.outputs.tags }}
107- # using {{ steps.meta.outputs.labels }} doesn't work with multi-line variable ($EXISTING_LABLES)
108112 labels : ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
109113 build-args : |
110- clams_version=${{ env.CLAMS_VERSION }}
111- push : true
114+ clams_version=${{ inputs.version }}
115+ outputs : type=image,"name=${{ env.REGISTRY }}/${{ github.repository }}${{ env.SUFFIX }}",push-by-digest=true,name-canonical=true,push=true
116+
117+ - name : " 📤 Export digest"
118+ run : |
119+ mkdir -p /tmp/digests
120+ digest="${{ steps.build.outputs.digest }}"
121+ touch "/tmp/digests/${digest#sha256:}"
112122
123+ - name : " 📦 Upload digest"
124+ uses : actions/upload-artifact@v4
125+ with :
126+ name : digests-${{ steps.prepare.outputs.slug }}-${{ steps.prepare.outputs.pair }}
127+ path : /tmp/digests/*
128+ if-no-files-found : error
129+ retention-days : 1
130+
131+ merge :
132+ name : " 🔗 Create multi-platform manifest"
133+ runs-on : ubuntu-latest
134+ needs : build
135+ permissions :
136+ contents : read
137+ packages : write
138+
139+ steps :
140+ - name : " 🔧 Prepare"
141+ id : prepare
142+ run : |
143+ slug=$(echo "${{ inputs.buildfilename }}" | sed 's|[^a-zA-Z0-9]|-|g; s/^-*//; s/-*$//')
144+ echo "slug=${slug}" >> $GITHUB_OUTPUT
145+
146+ - name : " 🏷 Get image name suffix"
147+ id : getsuffix
148+ run : |
149+ export filename=$(basename ${{ inputs.buildfilename }})
150+ export nameonly="${filename%.*}"
151+ if [ ${nameonly} == ${filename} ]; then echo "SUFFIX=" >> $GITHUB_ENV ; else echo "SUFFIX=-${nameonly}" >> $GITHUB_ENV; fi
152+
153+ - name : " 📥 Download digests"
154+ uses : actions/download-artifact@v4
155+ with :
156+ path : /tmp/digests
157+ pattern : digests-${{ steps.prepare.outputs.slug }}-*
158+ merge-multiple : true
159+
160+ - name : " 👷 Set up Docker Buildx"
161+ uses : docker/setup-buildx-action@v3
162+
163+ - name : " 🏷 Prepare docker tags"
164+ id : meta
165+ uses : docker/metadata-action@v5
166+ with :
167+ images : ${{ env.REGISTRY }}/${{ github.repository }}${{ env.SUFFIX }}
168+ tags : |
169+ type=pep440,pattern={{version}},value=${{ inputs.version }}
170+ type=ref,event=tag
171+ type=ref,event=pr
172+
173+ - name : " 🔏 Log in to registry"
174+ uses : docker/login-action@v3
175+ with :
176+ registry : ${{ env.REGISTRY }}
177+ username : ${{ github.actor }}
178+ password : ${{ secrets.GITHUB_TOKEN }}
179+
180+ - name : " 🔗 Create manifest list and push"
181+ working-directory : /tmp/digests
182+ run : |
183+ docker buildx imagetools create \
184+ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
185+ $(printf '${{ env.REGISTRY }}/${{ github.repository }}${{ env.SUFFIX }}@sha256:%s ' *)
0 commit comments