Skip to content

Commit d536219

Browse files
committed
Fix containers platforms and metadata (Add actionlint too)
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
1 parent 8fd5e81 commit d536219

39 files changed

Lines changed: 3291 additions & 453 deletions

.github/actionlint.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
self-hosted-runner:
2+
# Labels of self-hosted runner in array of string
3+
labels:
4+
- bastion
5+
- x86_64
6+
- arm64
7+
- aarch64
8+
- amd64
9+
- repo-nightly
10+
- repo-staging
11+
- repo-release
12+
- medium
13+
- large

.github/actions/action.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: setup-actionlint
3+
description: Setup actionlint
4+
inputs:
5+
version:
6+
description: The version of actionlint
7+
default: 1.6.24
8+
cache-seed:
9+
required: true
10+
type: string
11+
description: Seed used to invalidate caches
12+
13+
runs:
14+
using: composite
15+
steps:
16+
17+
- name: Cache actionlint Binary
18+
uses: actions/cache@v3
19+
with:
20+
path: /usr/local/bin/actionlint
21+
key: ${{ inputs.cache-seed }}|${{ runner.os }}|${{ runner.arch }}|actionlint|${{ inputs.version }}
22+
23+
- name: Setup actionlint
24+
shell: bash
25+
run: |
26+
if ! command -v actionlint; then
27+
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) ${{ inputs.version }}
28+
mv ./actionlint /usr/local/bin/actionlint
29+
fi
30+
- name: Show actionlint Version
31+
shell: bash
32+
run: |
33+
actionlint --version
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: setup-actionlint
3+
description: Setup actionlint
4+
inputs:
5+
version:
6+
description: The version of actionlint
7+
default: 1.6.24
8+
cache-seed:
9+
required: true
10+
type: string
11+
description: Seed used to invalidate caches
12+
13+
runs:
14+
using: composite
15+
steps:
16+
17+
- name: Cache actionlint Binary
18+
uses: actions/cache@v3
19+
with:
20+
path: /usr/local/bin/actionlint
21+
key: ${{ inputs.cache-seed }}|${{ runner.os }}|${{ runner.arch }}|actionlint|${{ inputs.version }}
22+
23+
- name: Setup actionlint
24+
shell: bash
25+
run: |
26+
if ! command -v actionlint; then
27+
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) ${{ inputs.version }}
28+
mv ./actionlint /usr/local/bin/actionlint
29+
fi
30+
- name: Show actionlint Version
31+
shell: bash
32+
run: |
33+
actionlint --version
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: setup-shellcheck
3+
description: Setup shellcheck
4+
inputs:
5+
version:
6+
description: The version of shellcheck
7+
default: v0.9.0
8+
cache-seed:
9+
required: true
10+
type: string
11+
description: Seed used to invalidate caches
12+
13+
runs:
14+
using: composite
15+
steps:
16+
17+
- name: Cache shellcheck Binary
18+
uses: actions/cache@v3
19+
with:
20+
path: /usr/local/bin/shellcheck
21+
key: ${{ inputs.cache-seed }}|${{ runner.os }}|${{ runner.arch }}|shellcheck|${{ inputs.version }}
22+
23+
- name: Setup shellcheck
24+
shell: bash
25+
run: |
26+
if ! command -v shellcheck; then
27+
wget https://github.com/koalaman/shellcheck/releases/download/${{ inputs.version }}/shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz
28+
tar xf shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz
29+
mv shellcheck-${{ inputs.version }}/shellcheck /usr/local/bin/shellcheck
30+
rm -rf shellcheck-${{ inputs.version }}.${{ runner.os }}.x86_64.tar.xz shellcheck-${{ inputs.version }}
31+
fi
32+
- name: Show shellcheck Version
33+
shell: bash
34+
run: |
35+
shellcheck --version

.github/workflows/.container.template.j2

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ concurrency:
2828

2929
jobs:
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

Comments
 (0)