95 lines
2.8 KiB
YAML
95 lines
2.8 KiB
YAML
name: Docker Build and Publish
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: gitea.example.com
|
|
IMAGE_NAME: realesrgan-api
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
strategy:
|
|
matrix:
|
|
variant: [cpu, gpu]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.GITEA_USERNAME }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Generate image tags
|
|
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
|
|
|
|
- name: Build and push Docker image (${{ matrix.variant }})
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: ${{ github.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
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.12'
|
|
|
|
- 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: 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: Type check with mypy
|
|
run: |
|
|
pip install mypy
|
|
mypy app --ignore-missing-imports || true
|
|
|
|
- name: Run tests
|
|
run: |
|
|
pytest tests/ -v || true
|