Skip to content

Build and release Docker images 🐳 #3

Build and release Docker images 🐳

Build and release Docker images 🐳 #3

name: Build and release Docker images 🐳
on:
workflow_dispatch:
inputs:
version:
description: 'The version of zizmor to build against'
required: true
latest:
description: 'Whether to tag the image as latest'
required: false
default: true
type: boolean
permissions: {}
env:
ZIZMOR_IMAGE: ghcr.io/zizmorcore/zizmor
jobs:
build:
strategy:
fail-fast: false
matrix:
image:
- runner: ubuntu-latest
platform: linux/amd64
platform-pair: linux-amd64
- runner: ubuntu-24.04-arm
platform: linux/arm64
platform-pair: linux-arm64
name: Build and publish Docker image (${{ matrix.image.runner }})
runs-on: ${{ matrix.image.runner }}
environment:
name: docker
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
with:
cache-binary: false
- name: Extract Docker metadata
id: docker-metadata
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: "${{ env.ZIZMOR_IMAGE }}"
- name: Login to GHCR
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: github.repository_owner == 'zizmorcore'
with:
registry: ghcr.io
username: "${{ github.repository_owner }}"
password: "${{ secrets.GITHUB_TOKEN }}"
- name: Build and push by digest
id: build
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
platforms: ${{ matrix.image.platform }}
labels: ${{ steps.docker-metadata.outputs.labels }}
outputs: type=image,"name=${{ env.ZIZMOR_IMAGE }}",push-by-digest=true,name-canonical=true,push=true
build-args: |
ZIZMOR_VERSION=${{ github.event.inputs.version }}
- name: Export digest
run: |
mkdir -p "${RUNNER_TEMP}/digests"
digest="${DIGEST}"
touch "${RUNNER_TEMP}/digests/${digest#sha256:}"
env:
DIGEST: ${{ steps.build.outputs.digest }}
- name: Upload digest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: digests-${{ matrix.image.platform-pair }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge image builds
needs: build
runs-on: ubuntu-latest
environment:
name: docker
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to GHCR
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: github.repository_owner == 'zizmorcore'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
with:
cache-binary: false
- name: Extract Docker metadata
id: docker-metadata
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: index
with:
images: "${{ env.ZIZMOR_IMAGE }}"
tags: |
type=raw,value=${{ github.event.inputs.version }}
typw=raw,value=latest,enable=${{ github.event.inputs.latest }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
# NOTE: annotation technique adapted from Ruff's build-docker.yml,
# see: https://github.com/astral-sh/ruff/blob/6e34f74c16/.github/workflows/build-docker.yml
run: |
readarray -t lines <<< "$DOCKER_METADATA_OUTPUT_ANNOTATIONS"
annotations=()
for line in "${lines[@]}"; do
annotations+=(--annotation "$line")
done
docker buildx imagetools create \
"${annotations[@]}" \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf "${ZIZMOR_IMAGE}@sha256:%s " *)
- name: Inspect image
run: |
docker buildx imagetools inspect "${ZIZMOR_IMAGE}:${VERSION}"
env:
VERSION: ${{ steps.docker-metadata.outputs.version }}