refactor: Update to match facefusion-api gitea workflow, remove test jobs

This commit is contained in:
Developer
2026-02-16 20:00:14 +01:00
parent 0e59652575
commit a5e7c73379

View File

@@ -1,94 +1,141 @@
name: Docker Build and Publish
name: Build and Push Docker Image
on:
push:
branches:
- main
- develop
tags:
- 'v*.*.*'
pull_request:
branches:
- main
workflow_dispatch:
inputs:
tag:
description: 'Custom tag for the image'
required: false
default: 'manual'
env:
REGISTRY: gitea.example.com
IMAGE_NAME: realesrgan-api
REGISTRY: dev.pivoine.art
IMAGE_NAME: valknar/realesrgan-api
jobs:
build:
build-gpu:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
variant: [cpu, gpu]
steps:
- name: Checkout code
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Log in to Gitea Registry
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GITEA_USERNAME }}
password: ${{ secrets.GITEA_TOKEN }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Generate image tags
- name: Extract metadata (GPU)
id: meta
run: |
COMMIT_SHA=${{ github.sha }}
BRANCH=${{ github.ref_name }}
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${COMMIT_SHA:0:7}-${{ matrix.variant }}"
TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${{ matrix.variant }}"
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-${{ matrix.variant }}"
TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix={{branch}}-
type=raw,value=${{ gitea.event.inputs.tag }},enable=${{ gitea.event_name == 'workflow_dispatch' }}
labels: |
org.opencontainers.image.title=realesrgan-api
org.opencontainers.image.description=REST API for Real-ESRGAN image upscaling (GPU)
org.opencontainers.image.vendor=valknar
- name: Build and push Docker image (${{ matrix.variant }})
- name: Build and push GPU image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
push: ${{ gitea.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
VARIANT=${{ matrix.variant }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.variant }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.variant }},mode=max
labels: ${{ steps.meta.outputs.labels }}
build-args: VARIANT=gpu
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-gpu
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-gpu,mode=max
test:
- name: Summary
if: gitea.event_name != 'pull_request'
run: |
echo "### GPU Image Published" >> $GITEA_STEP_SUMMARY
echo "**Tags:**" >> $GITEA_STEP_SUMMARY
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITEA_STEP_SUMMARY
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
build-cpu:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
submodules: recursive
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-cpu.txt
pip install pytest pytest-asyncio httpx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
- name: Lint with flake8
run: |
pip install flake8
flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 app --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Type check with mypy
run: |
pip install mypy
mypy app --ignore-missing-imports || true
- name: Extract metadata (CPU)
id: meta-cpu
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: suffix=-cpu
tags: |
type=raw,value=latest-cpu,enable={{is_default_branch}}
type=ref,event=branch,suffix=-cpu
type=ref,event=pr,suffix=-cpu
type=semver,pattern={{version}},suffix=-cpu
type=sha,prefix={{branch}}-,suffix=-cpu
labels: |
org.opencontainers.image.title=realesrgan-api
org.opencontainers.image.description=REST API for Real-ESRGAN image upscaling (CPU)
org.opencontainers.image.vendor=valknar
- name: Run tests
- name: Build and push CPU image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: ${{ gitea.event_name != 'pull_request' }}
tags: ${{ steps.meta-cpu.outputs.tags }}
labels: ${{ steps.meta-cpu.outputs.labels }}
build-args: VARIANT=cpu
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-cpu
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-cpu,mode=max
- name: Summary
if: gitea.event_name != 'pull_request'
run: |
pytest tests/ -v || true
echo "### CPU Image Published" >> $GITEA_STEP_SUMMARY
echo "**Tags:**" >> $GITEA_STEP_SUMMARY
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
echo "${{ steps.meta-cpu.outputs.tags }}" >> $GITEA_STEP_SUMMARY
echo "\`\`\`" >> $GITEA_STEP_SUMMARY