Fix containers platforms and metadata #417
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Redis 🐳 Mirror" | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 22 * * *" | |
push: | |
branches: | |
- '*' | |
paths: | |
- containers.yml | |
- '.github/workflows/redis-containers.yml' | |
- 'mirrors/redis/*' | |
pull_request: | |
paths: | |
- containers.yml | |
- '.github/workflows/redis-containers.yml' | |
- 'mirrors/redis/*' | |
env: | |
PATH_IN_REPO: mirrors/redis | |
concurrency: | |
# New builds always cancel previous, still running, builds | |
group: mirrors/redis-${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
matrix-generator: | |
name: Generate Matrix | |
runs-on: ubuntu-latest | |
outputs: | |
tags: ${{ steps.set-matrix.outputs.tags }} | |
name: ${{ steps.set-matrix.outputs.name }} | |
dockerinfo: ${{ steps.set-matrix.outputs.dockerinfo }} | |
steps: | |
- name: "Throttle Builds" | |
run: | | |
t="$(shuf -i 5-30 -n 1)"; echo "Sleeping $t seconds"; sleep "$t" | |
- name: "Fetching Repository Contents" | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install Requirements | |
run: | | |
python -m pip install -r requirements.txt | |
- name: "Docker QEMU" | |
uses: docker/setup-qemu-action@v3 | |
- name: "Docker BuildX" | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: "Generate Matrix Data" | |
id: set-matrix | |
run: | | |
inv containers.matrix --from-workflow ${{ env.PATH_IN_REPO }} | |
build: | |
runs-on: ubuntu-latest | |
needs: matrix-generator | |
name: "Build ${{ matrix.dockerinfo.name }}:${{ matrix.dockerinfo.tag }}${{ matrix.dockerinfo.platform && format(' ({0})', matrix.dockerinfo.platform) || ''}}" | |
strategy: | |
fail-fast: false | |
max-parallel: 10 | |
matrix: | |
dockerinfo: ${{ fromJson(needs.matrix-generator.outputs.dockerinfo) }} | |
permissions: | |
actions: read | |
checks: write | |
issues: read | |
packages: write | |
pull-requests: read | |
repository-projects: read | |
statuses: read | |
steps: | |
- name: "Fetching Repository Contents" | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install Requirements | |
run: | | |
python -m pip install -r requirements.txt | |
- name: "Throttle concurrent pushes" | |
run: | | |
t="$(shuf -i 5-30 -n 1)"; echo "Sleeping $t seconds"; sleep "$t" | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository }}/${{ matrix.dockerinfo.name }} | |
tags: | | |
type=raw,value=${{ matrix.dockerinfo.tag }} | |
flavor: | | |
latest=false | |
- name: "Docker QEMU" | |
uses: docker/setup-qemu-action@v3 | |
- name: "Docker BuildX" | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: "Log into GitHub Container Registry" | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Build & Publish" | |
uses: docker/build-push-action@v5 | |
id: build | |
with: | |
file: ${{ matrix.dockerinfo.file }} | |
context: ${{ env.PATH_IN_REPO }} | |
platforms: ${{ matrix.dockerinfo.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=ghcr.io/${{ github.repository }}/${{ matrix.dockerinfo.name }}:${{ steps.meta.outputs.version }},push-by-digest=true,name-canonical=true,push=true | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v3 | |
with: | |
name: digests-${{ matrix.dockerinfo.name }}-${{ matrix.dockerinfo.tag }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-latest | |
name: "Merge ${{ needs.matrix-generator.outputs.name }}:${{ matrix.tag }}" | |
strategy: | |
fail-fast: false | |
max-parallel: 10 | |
matrix: | |
tag: ${{ fromJson(needs.matrix-generator.outputs.tags) }} | |
needs: | |
- matrix-generator | |
- build | |
permissions: | |
actions: read | |
checks: write | |
issues: read | |
packages: write | |
pull-requests: read | |
repository-projects: read | |
statuses: read | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v3 | |
with: | |
name: digests-${{ needs.matrix-generator.outputs.name }}-${{ matrix.tag }} | |
path: /tmp/digests | |
- name: Show digests | |
run: | | |
tree -a /tmp/digest | |
cat /tmp/digests/* | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }} | |
tags: | | |
type=raw,value=${{ matrix.tag }} | |
flavor: | | |
latest=false | |
- name: "Log into GitHub Container Registry" | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create "$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")" \ | |
"$(printf 'ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }}@sha256:%s ' *)" | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ghcr.io/${{ github.repository }}/${{ needs.matrix-generator.outputs.name }}:${{ steps.meta.outputs.version }} |