name: Docker
on:
push:
tags:
- 'v*'
pull_request:
paths:
- 'Dockerfile'
- '.dockerignore'
- '.github/workflows/docker.yml'
- 'Cargo.toml'
- 'Cargo.lock'
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:
runs-on: ubuntu-latest
steps:
- name: Resolve ref to build
id: ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
# PR validation: build the PR head, don't push
echo "ref=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "push=false" >> "$GITHUB_OUTPUT"
else
echo "push=true" >> "$GITHUB_OUTPUT"
fi
- 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 QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: steps.ref.outputs.push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
if: steps.ref.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image metadata
id: meta
if: steps.ref.outputs.push == 'true'
uses: docker/metadata-action@v5
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: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ steps.ref.outputs.push == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: ${{ steps.ref.outputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max