Skip to content

Build and release Docker images 🐳 #9

Build and release Docker images 🐳

Build and release Docker images 🐳 #9

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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
cache-binary: false
- name: Extract Docker metadata
id: docker-metadata
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
with:
images: "${{ env.ZIZMOR_IMAGE }}"
- name: Login to GHCR
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.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 }}
shell: bash
- 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@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to GHCR
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.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@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
cache-binary: false
- name: Extract Docker metadata
id: docker-metadata
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.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 }}