From 1e28526be7124555ad2de9114fb705a589cf2745 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sun, 17 Aug 2025 12:16:55 +0100 Subject: [PATCH] Use '.python-version' for builds --- .github/workflows/build-container.yaml | 6 ++++++ .github/workflows/release.yaml | 2 -- Dockerfile | 6 ++++-- Taskfile.yaml | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-container.yaml b/.github/workflows/build-container.yaml index 1f0329c..54be751 100644 --- a/.github/workflows/build-container.yaml +++ b/.github/workflows/build-container.yaml @@ -22,11 +22,17 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set build args + run: | + PYTHON_VERSION=$(cat .python-version) + echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV - name: Build and push id: docker_build uses: docker/build-push-action@v6 with: push: true + build-args: | + PYTHON_VERSION=${{ env.PYTHON_VERSION }} tags: | ghcr.io/${{ github.repository }}:${{ github.ref_name }} ghcr.io/${{ github.repository }}:latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c201c83..bb86620 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -14,8 +14,6 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 - with: - python-version: "3.9" - name: Install uv uses: astral-sh/setup-uv@v6 diff --git a/Dockerfile b/Dockerfile index 696aaf5..217c72d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder +ARG PYTHON_VERSION="3.13" + +FROM ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS builder ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy ENV UV_PYTHON_DOWNLOADS=0 WORKDIR /app @@ -11,7 +13,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --locked --no-dev -FROM python:3.13-slim-bookworm +FROM python:${PYTHON_VERSION}-slim-bookworm COPY --from=builder --chown=app:app /app /app ENV PATH="/app/.venv/bin:$PATH" EXPOSE 80/tcp diff --git a/Taskfile.yaml b/Taskfile.yaml index 019afdf..6cca52f 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -14,7 +14,7 @@ tasks: docker:build: desc: Build the container using Docker cmds: - - docker build . -t smsbot:latest + - docker build . --build-arg PYTHON_VERSION=$(cat .python-version) -t smsbot:latest smsbot:run: desc: Run the SMSBot