Docker #172
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: Docker | |
# Based on GitHub actions starter workflow for Docker publishing: | |
# https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
schedule: | |
# every day at 16:15 UTC | |
- cron: '15 16 * * *' | |
push: | |
branches: | |
- 'main' | |
# Publish calver or semver tags as releases. | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
- '[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' | |
pull_request: | |
branches: | |
- 'main' | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
# Allow to build longer than 6 hours, but this is only possible | |
# with self-hosted runners. 1440 min = 24 h. For details, see: | |
# https://github.com/orgs/community/discussions/26679 | |
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions | |
# https://docs.github.com/en/actions/administering-github-actions/usage-limits-billing-and-administration | |
timeout-minutes: 1440 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Free Disk Space on Ubuntu runners, clear up to 35 GB disk space | |
# https://github.com/jlumbroso/free-disk-space | |
- name: Free disk space | |
uses: jlumbroso/free-disk-space@v1.3.1 | |
with: | |
# Tool cache: Saved 8.3GiB | |
tool-cache: true | |
# Android library: Saved 7.5GiB | |
android: true | |
# .NET runtime: Saved 1.6GiB | |
dotnet: true | |
# Haskell runtime: Saved 5.4GiB | |
haskell: true | |
# Large misc. packages: Saved 4.8GiB | |
large-packages: true | |
# Docker images: Saved 3.2GiB | |
docker-images: true | |
# Swap storage: Saved 4.0GiB | |
swap-storage: true | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@v3 | |
with: | |
cosign-release: 'v2.4.0' | |
- name: Check cosign installation | |
if: github.event_name != 'pull_request' | |
run: cosign version | |
# Install QEMU static binaries for multi-arch image build | |
# https://github.com/docker/setup-qemu-action | |
# https://docs.docker.com/build/ci/github-actions/multi-platform | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# Set up BuildKit Docker container builder to be able to build | |
# multi-platform images and export cache | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
# https://docs.docker.com/build/ci/github-actions/cache | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
# HOTFIX: reduce build time to beeing under standard limit of | |
# 6 hours runtime ("timeout-minutes") on GitHub hosted runners. | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# Sign the resulting Docker image digest except on PRs. | |
# This will only write to the public Rekor transparency log when the Docker | |
# repository is public to avoid leaking data. If you would like to publish | |
# transparency data even for private images, pass --force to cosign below. | |
# https://github.com/sigstore/cosign | |
- name: Sign the published Docker image | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
TAGS: ${{ steps.meta.outputs.tags }} | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
# This step uses the identity token to provision an ephemeral certificate | |
# against the sigstore community Fulcio instance. | |
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |