The builder stage runs on the build platform and cross-compiles Rust, with GCC cross compilers for bundled SQLite, so only the small runtime stage runs under QEMU. The workflow sets up QEMU via the Docker Hub mirror and pushes all three platforms under the same tags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.4 KiB
YAML
92 lines
3.4 KiB
YAML
name: Docker publish
|
|
|
|
# Builds the image and pushes it to a Gitea Container Registry.
|
|
#
|
|
# Configure the repository by adding these secrets / variables:
|
|
# Secrets:
|
|
# REGISTRY_TOKEN - Gitea PAT with `write:package` (and `read:repository`) scope.
|
|
# Optional variables (Settings -> Actions); defaults come from the repository:
|
|
# REGISTRY_HOST - the Gitea registry host (default: host of this Gitea instance)
|
|
# REGISTRY_OWNER - owner/namespace of the image (default: repository owner)
|
|
# REGISTRY_REPO - image name (default: repository name)
|
|
# REGISTRY_USER - the username owning the token (default: user who pushed the tag)
|
|
# DOCKERHUB_MIRROR - Docker Hub mirror for base images (default: mirror.gcr.io)
|
|
#
|
|
# NOTE: variable/secret names must NOT start with GITEA_ or GITHUB_.
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*.*.*"
|
|
- "v*"
|
|
|
|
env:
|
|
REGISTRY_HOST: ${{ vars.REGISTRY_HOST }}
|
|
REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER || github.repository_owner }}
|
|
REGISTRY_REPO: ${{ vars.REGISTRY_REPO || github.event.repository.name }}
|
|
REGISTRY_USER: ${{ vars.REGISTRY_USER || github.actor }}
|
|
|
|
jobs:
|
|
publish:
|
|
name: Build and push image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
packages: write
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Compute tags
|
|
id: meta
|
|
env:
|
|
VERSION: ${{ github.ref_name }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
run: |
|
|
# Keep only semver body so "v1.2.3" -> "1.2.3".
|
|
tag="${VERSION#v}"
|
|
echo "version_tagname=$tag" >> "$GITHUB_OUTPUT"
|
|
# The Gitea registry lives on the same host as the instance itself.
|
|
host="${REGISTRY_HOST:-${SERVER_URL#*://}}"
|
|
host="${host%%/*}"
|
|
echo "host=$host" >> "$GITHUB_OUTPUT"
|
|
# Image references must be lowercase ("BalanceServer" -> "balanceserver").
|
|
image="$host/${REGISTRY_OWNER,,}/${REGISTRY_REPO,,}"
|
|
echo "image=$image" >> "$GITHUB_OUTPUT"
|
|
echo "Publishing $image:$tag as $REGISTRY_USER"
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
# Only the runtime stage runs emulated; Rust is cross-compiled natively.
|
|
image: ${{ vars.DOCKERHUB_MIRROR || 'mirror.gcr.io' }}/tonistiigi/binfmt:latest
|
|
platforms: arm64,arm
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
# BuildKit runs in its own container and ignores the host daemon's
|
|
# registry-mirrors, so Docker Hub base images go through a mirror here.
|
|
buildkitd-config-inline: |
|
|
[registry."docker.io"]
|
|
mirrors = ["${{ vars.DOCKERHUB_MIRROR || 'mirror.gcr.io' }}"]
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ steps.meta.outputs.host }}
|
|
username: ${{ env.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
push: true
|
|
tags: |
|
|
${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.version_tagname }}
|
|
${{ steps.meta.outputs.image }}:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max,ignore-error=true
|