This commit is contained in:
Andras Schmelczer 2026-05-13 12:11:54 +01:00
parent a08b5d2ae0
commit b98f0e3904
38 changed files with 3732 additions and 483 deletions

View file

@ -6,10 +6,6 @@ on:
tags: ["v*"]
workflow_dispatch:
env:
REGISTRY: ${{ gitea.server_url }}
IMAGE_NAME: ${{ gitea.repository }}
jobs:
build-and-push:
runs-on: docker
@ -27,54 +23,64 @@ jobs:
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: Resolve registry vars
id: registry
run: |
host="${{ gitea.server_url }}"
host="${host#https://}"
host="${host#http://}"
repo=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
{
echo "host=${host}"
echo "image=${host}/${repo}"
echo "screenshot_image=${host}/${repo}-screenshot"
} >> "$GITHUB_OUTPUT"
- name: Log in to Forgejo Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
registry: ${{ steps.registry.outputs.host }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
- name: Determine image tags
id: tags
run: |
REPO=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
SHA_SHORT=$(echo "${{ gitea.sha }}" | cut -c1-7)
TAGS="${{ env.REGISTRY }}/${REPO}:sha-${SHA_SHORT}"
- name: Extract metadata (main)
id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: ${{ steps.registry.outputs.image }}
tags: |
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Add latest tag on default branch
if [ "${{ gitea.ref }}" = "refs/heads/main" ]; then
TAGS="${TAGS},${{ env.REGISTRY }}/${REPO}:latest"
fi
# Add version tags for semver tags
REF="${{ gitea.ref }}"
if [[ "$REF" =~ ^refs/tags/v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
MINOR="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
TAGS="${TAGS},${{ env.REGISTRY }}/${REPO}:${VERSION}"
TAGS="${TAGS},${{ env.REGISTRY }}/${REPO}:${MINOR}"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
echo "repo=${REPO}" >> "$GITHUB_OUTPUT"
echo "sha_short=${SHA_SHORT}" >> "$GITHUB_OUTPUT"
- name: Build and push
- name: Build and push (main)
uses: https://github.com/docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}:buildcache,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.registry.outputs.image }}:buildcache
cache-to: type=registry,ref=${{ steps.registry.outputs.image }}:buildcache,mode=max
- name: Build and push screenshot service
- name: Extract metadata (screenshot)
id: meta-screenshot
uses: https://github.com/docker/metadata-action@v5
with:
images: ${{ steps.registry.outputs.screenshot_image }}
tags: |
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push (screenshot)
uses: https://github.com/docker/build-push-action@v6
with:
context: ./screenshot
push: true
tags: |
${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}-screenshot:latest
${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}-screenshot:sha-${{ steps.tags.outputs.sha_short }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}-screenshot:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ steps.tags.outputs.repo }}-screenshot:buildcache,mode=max
tags: ${{ steps.meta-screenshot.outputs.tags }}
labels: ${{ steps.meta-screenshot.outputs.labels }}
cache-from: type=registry,ref=${{ steps.registry.outputs.screenshot_image }}:buildcache
cache-to: type=registry,ref=${{ steps.registry.outputs.screenshot_image }}:buildcache,mode=max