Login failed with "Username required" because REGISTRY_OWNER was not set. Default the registry host to this Gitea instance, the owner to the repository owner and the user to the tag pusher, lowercase the image name, and keep a failed GHA cache export from failing the build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.6 KiB
YAML
77 lines
2.6 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)
|
|
#
|
|
# 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 Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- 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: .
|
|
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
|