Skip to content

Commit

Permalink
feat: add docker publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmorley committed Sep 24, 2024
1 parent f408e47 commit a6c2274
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release Docker image to GHCR

on:
# TODO: wire into release process
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
default: 'latest'

env:
REGISTRY: ghcr.io

jobs:
build:
permissions:
contents: read
packages: write
strategy:
matrix:
runner:
- ubuntu-22.04-medium-arm64
- ubuntu-22.04
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image by digest
uses: docker/build-push-action@v6
id: build
with:
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.source=${{ github.repositoryUrl }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ github.repository }},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@v4
with:
name: digests-${{ runner.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs: [build]
permissions:
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
-t ${{ env.REGISTRY }}/${{ github.repository }}:${{ inputs.version }} \
$(printf '${{ env.REGISTRY }}/${{ github.repository }}@sha256:%s ' *)

0 comments on commit a6c2274

Please sign in to comment.