perfect-postcode/.forgejo/workflows/docker-publish.yml
Andras Schmelczer 349a6c1d53
Some checks failed
CI / Python (lint + test) (push) Failing after 3m38s
CI / Rust (lint + test) (push) Failing after 3m32s
CI / Frontend (lint + typecheck) (push) Failing after 4m12s
Build and publish Docker image / build-and-push (push) Failing after 4m48s
Fun changes
2026-04-04 22:59:44 +01:00

87 lines
3.2 KiB
YAML

name: Build and publish Docker image
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
env:
REGISTRY: ${{ gitea.server_url }}
IMAGE_NAME: ${{ gitea.repository }}
jobs:
build-and-push:
runs-on: docker
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Download map assets (fonts, sprites, twemoji)
run: uv run python -m pipeline.download.map_assets --output frontend/public/assets
- name: Install Docker CLI
run: |
ARCH=$(uname -m)
curl -fsSL "https://download.docker.com/linux/static/stable/${ARCH}/docker-27.5.1.tgz" \
| tar xz --strip-components=1 -C /usr/local/bin docker/docker
docker --version
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: Log in to Forgejo Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
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}"
# 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
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
- name: Build and push screenshot service
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