@@ -28,14 +28,16 @@ concurrency:
2828
2929jobs:
3030 matrix-generator:
31- name: "Mirror Matrix Generator"
31+ name: Generate Matrix
3232 runs-on: ubuntu-latest
3333 outputs:
34+ tags: ${{ steps.set-matrix.outputs.tags }}
35+ name: ${{ steps.set-matrix.outputs.name }}
3436 dockerinfo: ${{ steps.set-matrix.outputs.dockerinfo }}
3537 steps:
3638 - name: "Throttle Builds"
3739 run: |
38- t=$(shuf -i 5-30 -n 1); echo "Sleeping $t seconds"; sleep $t
40+ t=" $(shuf -i 5-30 -n 1)" ; echo "Sleeping $t seconds"; sleep "$t"
3941
4042 - name: "Fetching Repository Contents"
4143 uses: actions/checkout@v4
@@ -61,10 +63,10 @@ jobs:
6163 run: |
6264 inv containers.matrix --from-workflow ${{ env.PATH_IN_REPO }}
6365
64- mirror-image :
66+ build :
6567 runs-on: ubuntu-latest
6668 needs: matrix-generator
67- name: "${{ matrix.dockerinfo.name }}${{ matrix.dockerinfo.platform && format(' ({0})', matrix.dockerinfo.platform) || ''}}"
69+ name: "Build ${{ matrix.dockerinfo.name }}:${{ matrix.dockerinfo.tag }}${{ matrix.dockerinfo.platform && format(' ({0})', matrix.dockerinfo.platform) || ''}}"
6870 strategy:
6971 fail-fast: false
7072 max-parallel: 10
@@ -95,16 +97,18 @@ jobs:
9597
9698 - name: "Throttle concurrent pushes"
9799 run: |
98- t=$(shuf -i 5-30 -n 1); echo "Sleeping $t seconds"; sleep $t
100+ t=" $(shuf -i 5-30 -n 1)" ; echo "Sleeping $t seconds"; sleep "$t"
99101
100- - name: "Setup DockerFile"
101- run: |
102- echo " " >> ./${{matrix.dockerinfo.file}}
103- echo "LABEL org.opencontainers.image.source=\"https://github.com/${GITHUB_REPOSITORY}/\"" >> ${{matrix.dockerinfo.file}}
104- echo "LABEL org.opencontainers.image.url=\"https://github.com/${GITHUB_REPOSITORY}/\"" >> ${{matrix.dockerinfo.file}}
105- echo "LABEL org.opencontainers.image.documentation=\"https://github.com/${GITHUB_REPOSITORY}/\"" >> ${{matrix.dockerinfo.file}}
106- echo "LABEL org.opencontainers.image.vendor=\"Unofficial Docker Hub Mirror\"" >> ${{matrix.dockerinfo.file}}
107- cat ./${{matrix.dockerinfo.file}}
102+ - name: Docker meta
103+ id: meta
104+ uses: docker/metadata-action@v5
105+ with:
106+ images: |
107+ ghcr.io/${{ github.repository }}/${{ matrix.dockerinfo.name }}
108+ tags: |
109+ type=raw,value=${{ matrix.dockerinfo.tag }}
110+ flavor: |
111+ latest=false
108112
109113 - name: "Docker QEMU"
110114 uses: docker/setup-qemu-action@v3
@@ -130,10 +134,94 @@ jobs:
130134
131135 - name: "Build & Publish"
132136 uses: docker/build-push-action@v5
137+ id: build
133138 with:
134139 file: ${{ matrix.dockerinfo.file }}
135140 context: ${{ env.PATH_IN_REPO }}
136141 platforms: ${{ matrix.dockerinfo.platform }}
137- push: ${{ github.repository == 'saltstack/salt-ci-containers' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) }}
142+ labels: ${{ steps.meta.outputs.labels }}
143+ outputs: type=image,name=ghcr.io/${{ github.repository }}/${{ matrix.dockerinfo.name }},push-by-digest=true,name-canonical=true,push=${{
144+ github.repository == 'saltstack/salt-ci-containers' && contains(fromJSON('["push", "schedule", "workflow_dispatch"] '), github.event_name) }}
145+
146+ - name: Export digest
147+ if: ${{ github.repository == 'saltstack/salt-ci-containers' && contains(fromJSON('["push", "schedule", "workflow_dispatch"] '), github.event_name) }}
148+ run: |
149+ mkdir -p /tmp/digests
150+ touch /tmp/digests/$(echo ${{ steps.build.outputs.digest }} | cut -d ":" -f 2)
151+ ls -lah /tmp/digests
152+
153+ - name: Upload digest
154+ if: ${{ github.repository == 'saltstack/salt-ci-containers' && contains(fromJSON('["push", "schedule", "workflow_dispatch"] '), github.event_name) }}
155+ uses: actions/upload-artifact@v3
156+ with:
157+ name: digests-${{ matrix.dockerinfo.name }}-${{ matrix.dockerinfo.tag }}
158+ path: /tmp/digests/*
159+ if-no-files-found: error
160+ retention-days: 1
161+
162+ merge:
163+ runs-on: ubuntu-latest
164+ name: "Merge ${{ needs.matrix-generator.outputs.name }}:${{ matrix.tag }}"
165+ if: ${{ github.repository == 'saltstack/salt-ci-containers' && contains(fromJSON('["push", "schedule", "workflow_dispatch"] '), github.event_name) }}
166+
167+ strategy:
168+ fail-fast: false
169+ max-parallel: 10
170+ matrix:
171+ tag: ${{ fromJson(needs.matrix-generator.outputs.tags) }}
172+
173+ needs:
174+ - matrix-generator
175+ - build
176+
177+ permissions:
178+ actions: read
179+ checks: write
180+ issues: read
181+ packages: write
182+ pull-requests: read
183+ repository-projects: read
184+ statuses: read
185+
186+ steps:
187+ - name: Download digests
188+ uses: actions/download-artifact@v3
189+ with:
190+ name: digests-${{ needs.matrix-generator.outputs.name }}-${{ matrix.tag }}
191+ path: /tmp/digests
192+
193+ - name: Show digests
194+ run: |
195+ tree -a /tmp/digests
196+ cat /tmp/digests/*
197+
198+ - name: Set up Docker Buildx
199+ uses: docker/setup-buildx-action@v3
200+
201+ - name: Docker meta
202+ id: meta
203+ uses: docker/metadata-action@v5
204+ with:
205+ images: |
206+ ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }}
138207 tags: |
139- ghcr.io/${{ github.repository }}/${{ matrix.dockerinfo.name }}
208+ type=raw,value=${{ matrix.tag }}
209+ flavor: |
210+ latest=false
211+
212+ - name: "Log into GitHub Container Registry"
213+ uses: docker/login-action@v3
214+ with:
215+ registry: ghcr.io
216+ username: ${{ github.repository_owner }}
217+ password: ${{ secrets.GITHUB_TOKEN }}
218+
219+ - name: Create manifest list and push
220+ working-directory: /tmp/digests
221+ run: | # shellcheck disable=SC2046
222+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
223+ $(printf 'ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }}@sha256:%s ' *)
224+
225+ - name: Inspect image
226+ run: |
227+ docker buildx imagetools inspect ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }}:${{ steps.meta.outputs.version }}
0 commit comments