From 7bbbbc23097896311151c5484a35cfcbf692510f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Mon, 14 Apr 2025 20:56:49 +0200 Subject: [PATCH] Refactor Docker publish workflow; add multi-architecture support; cache build layers --- .gitea/workflows/docker-publish.yml | 60 ++++++++++++++++++++--------- Dockerfile | 2 +- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/docker-publish.yml b/.gitea/workflows/docker-publish.yml index 84f84cc..c97c62f 100644 --- a/.gitea/workflows/docker-publish.yml +++ b/.gitea/workflows/docker-publish.yml @@ -23,25 +23,6 @@ jobs: OPENAI_TOKEN: "0" if: gitea.event_name != 'pull_request' steps: - - uses: https://github.com/actions/checkout@v4 - - uses: https://github.com/docker/setup-qemu-action@v3 - - uses: https://github.com/docker/setup-buildx-action@v3 - - uses: https://github.com/astral-sh/ruff-action@v3 - - - run: docker build --check . - - run: ruff check --exit-non-zero-on-fix --verbose - - run: ruff format --check --verbose - - - id: meta - uses: https://github.com/docker/metadata-action@v5 - env: - DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index - with: - images: | - ghcr.io/thelovinator1/anewdawn - git.lovinator.space/thelovinator/anewdawn - tags: type=raw,value=latest,enable=${{ gitea.ref == format('refs/heads/{0}', 'master') }} - # GitHub Container Registry - uses: https://github.com/docker/login-action@v3 if: github.event_name != 'pull_request' @@ -58,10 +39,51 @@ jobs: username: thelovinator password: ${{ secrets.PACKAGES_WRITE_GITEA_TOKEN }} + # Download the latest commit from the master branch + - uses: https://github.com/actions/checkout@v4 + + # Set up QEMU + - id: qemu + uses: https://github.com/docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:master + platforms: linux/amd64,linux/arm64 + + # Set up Buildx so we can build multi-arch images + - uses: https://github.com/docker/setup-buildx-action@v3 + + + # Install the latest version of ruff + - uses: https://github.com/astral-sh/ruff-action@v3 + with: + version: "latest" + + # Lint the Python code using ruff + - run: ruff check --exit-non-zero-on-fix --verbose + + # Check if the Python code needs formatting + - run: ruff format --check --verbose + - run: docker build --check . + + # Extract metadata (tags, labels) from Git reference and GitHub events for Docker + - id: meta + uses: https://github.com/docker/metadata-action@v5 + env: + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index + with: + images: | + ghcr.io/thelovinator1/anewdawn + git.lovinator.space/thelovinator/anewdawn + tags: type=raw,value=latest,enable=${{ gitea.ref == format('refs/heads/{0}', 'master') }} + + # Build and push the Docker image - uses: https://github.com/docker/build-push-action@v6 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ gitea.event_name != 'pull_request' }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} annotations: ${{ steps.meta.outputs.annotations }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index d4dde17..5e89a04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 # check=error=true;experimental=all -FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim@sha256:73c021c3fe7264924877039e8a449ad3bb380ec89214282301affa9b2f863c5d +FROM --platform=$BUILDPLATFORM ghcr.io/astral-sh/uv:python3.13-bookworm-slim@sha256:73c021c3fe7264924877039e8a449ad3bb380ec89214282301affa9b2f863c5d # Change the working directory to the `app` directory WORKDIR /app