From 083f9f0c4c9781f73272f5f9466ff92158016548 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Fri, 3 Apr 2026 19:20:01 +0200 Subject: [PATCH 1/2] feat: add Docker image publishing to ghcr.io Co-Authored-By: Claude Opus 4.6 --- .dockerignore | 9 ++++++ .github/workflows/publish-docker.yml | 43 ++++++++++++++++++++++++++++ Dockerfile | 13 +++++---- Makefile | 2 +- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/publish-docker.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e5eba7a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.github +.venv +__pycache__ +tests +*.md +LICENSE +Makefile +.context diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..45be465 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,43 @@ +name: Build and Publish Docker Image + +on: + workflow_run: + workflows: ["pytest"] + types: [completed] + branches: [main] + +permissions: + contents: read + packages: write + +jobs: + docker: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest + type=sha,prefix= + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index d06ae57..dc851d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM python:3.12-slim +FROM python:3.13-slim # Install uv. -COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ - -# Copy the application into the container. -COPY . /app +COPY --from=ghcr.io/astral-sh/uv:0.11 /uv /uvx /bin/ # Install the application dependencies. WORKDIR /app +COPY pyproject.toml uv.lock /app/ RUN uv sync --frozen --no-cache +# Copy the application into the container. +COPY . /app + # Run the application. -CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"] \ No newline at end of file +CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"] diff --git a/Makefile b/Makefile index f7ba856..0fcd365 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ start: uv run fastapi dev app/main.py build-docker: - docker build -t ecologits-api + docker build -t ecologits-api . run-docker: docker run -p 8000:80 ecologits-api From ee31cfb0813b62ea9a9323daae704a00c32a0887 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Thu, 9 Apr 2026 10:22:20 +0200 Subject: [PATCH 2/2] chore: update docker release process --- .dockerignore | 12 +++++++++--- .github/workflows/publish-docker.yml | 11 +++++------ RELEASE.md | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 RELEASE.md diff --git a/.dockerignore b/.dockerignore index e5eba7a..53aa4e0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,15 @@ .git .github +.context .venv +.pytest_cache +.ruff_cache __pycache__ tests -*.md -LICENSE +*.pyc +*.pyo +*.pyd +.DS_Store +.gitignore Makefile -.context +README.md diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 45be465..b28c337 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -1,10 +1,9 @@ name: Build and Publish Docker Image on: - workflow_run: - workflows: ["pytest"] - types: [completed] - branches: [main] + push: + tags: + - '*.*.*' permissions: contents: read @@ -13,7 +12,6 @@ permissions: jobs: docker: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - uses: actions/checkout@v4 - uses: docker/setup-qemu-action@v3 @@ -27,8 +25,9 @@ jobs: id: meta with: images: ghcr.io/${{ github.repository }} + flavor: | + latest=true tags: | - type=raw,value=latest type=sha,prefix= type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..fabc3e5 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,15 @@ +# Release +1. Update version number in `pyproject.toml` and `app/core/config.py`. +2. Run `uv lock` +3. Commit, tag and push changes. + ```shell + git add . + git commit -m "chore: bump version to x.y.z" + git push origin # wait for all CI jobs to succeed + git tag x.y.z + git push origin --tags + ``` +4. Go to GitHub in the tags section, on the latest tag click "Create release". +5. Click on "Generate release notes" and review the changelog. +6. Click "Publish release". +7. Go to GitHub Actions and check that the Docker publish job succeeded.