name: Docker
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Git tag to build (e.g. v1.13.5). Required for backfill runs.'
required: true
type: string
permissions:
contents: read
packages: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Resolve ref to build
id: ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
platform="${{ matrix.platform }}"
echo "slug=${platform//\//-}" >> "$GITHUB_OUTPUT"
# A Docker ref must be lowercase and the owner is "HelgeSverre".
# metadata-action lowercases for us in `merge`; the raw ref below doesn't.
owner="${{ github.repository_owner }}"
echo "owner=${owner,,}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.ref }}
fetch-depth: 0
- name: Overlay Dockerfile from main (backfill runs)
if: github.event_name == 'workflow_dispatch'
run: |
git fetch origin main --depth=1
git checkout origin/main -- Dockerfile .dockerignore
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
outputs: type=image,"name=docker.io/${{ secrets.DOCKERHUB_USERNAME }}/sql-splitter,ghcr.io/${{ steps.ref.outputs.owner }}/sql-splitter",push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ steps.ref.outputs.slug }}
cache-to: type=gha,mode=max,scope=${{ steps.ref.outputs.slug }}
- 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-${{ steps.ref.outputs.slug }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
needs: build
runs-on: ubuntu-latest
steps:
- name: Resolve ref
id: ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/sql-splitter
ghcr.io/${{ github.repository_owner }}/sql-splitter
tags: |
type=semver,pattern={{version}},value=${{ steps.ref.outputs.ref }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.ref.outputs.ref }}
type=semver,pattern={{major}},value=${{ steps.ref.outputs.ref }}
type=raw,value=${{ steps.ref.outputs.ref }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
# SC2046 is deliberate: both substitutions must word-split, into
# `-t <tag>` pairs and into one argument per digest.
# shellcheck disable=SC2046
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'docker.io/${{ secrets.DOCKERHUB_USERNAME }}/sql-splitter@sha256:%s ' *)
- name: Inspect published manifest
run: |
docker buildx imagetools inspect \
"docker.io/${{ secrets.DOCKERHUB_USERNAME }}/sql-splitter:${{ steps.ref.outputs.ref }}"