Skip to content

Separate digests by image name #16

Separate digests by image name

Separate digests by image name #16

Workflow file for this run

name: Publish
on:
push:
branches: [main]
tags: ['v*.*.*']
pull_request:
branches: [main]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
jobs:
build:
name: "Build: ${{ matrix.image.name }} (${{ matrix.platform }})"
runs-on: ubuntu-latest
strategy:
matrix:
image:
- name: ${{ github.repository }}
file: .docker/app/Dockerfile
- name: ${{ github.repository }}-nginx
file: .docker/nginx/Dockerfile
- name: ${{ github.repository }}-certbot
file: .docker/certbot/Dockerfile
platform:
- linux/amd64
- linux/arm64
steps:
- name: Set environment variables
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
image="${{ env.REGISTRY }}/${{ matrix.image.name }}"
echo "IMAGE_NAME=${image,,}" >> $GITHUB_ENV
- name: Checkout repository
id: checkout
uses: actions/checkout@v4
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.image.name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "Login to container registry: ${{ env.REGISTRY }}"
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build image by digest
id: build
uses: docker/build-push-action@v6
with:
file: ${{ matrix.image.file }}
platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/digests/${{ env.IMAGE_NAME }}
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${{ env.IMAGE_NAME }}/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/${{ env.IMAGE_NAME }}/*
if-no-files-found: error
retention-days: 1
merge:
name: "Merge: ${{ matrix.image.name }}"
runs-on: ubuntu-latest
needs:
- build
strategy:
matrix:
image:
- name: ${{ github.repository }}
file: .docker/app/Dockerfile
- name: ${{ github.repository }}-nginx
file: .docker/nginx/Dockerfile
- name: ${{ github.repository }}-certbot
file: .docker/certbot/Dockerfile
steps:
- name: Set environment variables
run: |
image="${{ env.REGISTRY }}/${{ matrix.image.name }}"
echo "IMAGE_NAME=${image,,}" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests/${{ env.IMAGE_NAME }}
pattern: digests-*
merge-multiple: true
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.image.name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "Login to container registry: ${{ env.REGISTRY }}"
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Create manifest list and push
working-directory: /tmp/digests/${{ env.IMAGE_NAME }}
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}