diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..53aa4e0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +.github +.context +.venv +.pytest_cache +.ruff_cache +__pycache__ +tests +*.pyc +*.pyo +*.pyd +.DS_Store +.gitignore +Makefile +README.md diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..b28c337 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,42 @@ +name: Build and Publish Docker Image + +on: + push: + tags: + - '*.*.*' + +permissions: + contents: read + packages: write + +jobs: + docker: + runs-on: ubuntu-latest + 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 }} + flavor: | + latest=true + tags: | + 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 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.