From 4aa3143a6dd189ee2eb92295b9e846c04e45c659 Mon Sep 17 00:00:00 2001 From: Victor Kataev Date: Mon, 26 Oct 2026 16:28:28 +0000 Subject: [PATCH 1/3] ci: add Dockerfile linting and formatting hooks - Add pinned upstream hadolint and dockerfmt hooks - Manage hadolint through prek mise support and fail on warnings or errors --- .pre-commit-config.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6aac408..b555411 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,3 +29,14 @@ repos: rev: v1.7.7 hooks: - id: actionlint + - repo: https://github.com/hadolint/hadolint + rev: v2.15.1 + hooks: + - id: hadolint + language: mise + additional_dependencies: ["hadolint@2.15.1"] + args: ["--failure-threshold", "warning"] + - repo: https://github.com/reteps/dockerfmt + rev: v0.5.4 + hooks: + - id: dockerfmt From debdea6ba4ac2871c39333d4966255cde7d9ebe9 Mon Sep 17 00:00:00 2001 From: Victor Kataev Date: Mon, 26 Oct 2026 16:29:53 +0000 Subject: [PATCH 2/3] build: address Dockerfile lint recommendations - Combine Python warmup and dependency installation in one RUN instruction - Use the existing numeric UID and GID for the runtime user --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6464220..f4fd397 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,8 @@ WORKDIR /app COPY pyproject.toml uv.lock /app/ # Warm up to avoid findpython timeout on arm64 build -RUN /usr/local/bin/python -EsSc 'import platform; print(platform.python_version())' - -RUN UV_PROJECT_ENVIRONMENT=/usr/local uv sync --locked --no-dev --no-install-project --inexact +RUN /usr/local/bin/python -EsSc 'import platform; print(platform.python_version())' \ + && UV_PROJECT_ENVIRONMENT=/usr/local uv sync --locked --no-dev --no-install-project --inexact COPY src/ ./src/ ENV PYTHONPATH=/app/src \ @@ -22,7 +21,7 @@ ENV PYTHONPATH=/app/src \ RUN addgroup -S -g 1000 appuser && adduser -S -u 1000 -G appuser appuser # Switch to the non-root user -USER appuser +USER 1000:1000 EXPOSE 8000 From 7c341783a51a22855ae4a2c4b97e39ceda39de07 Mon Sep 17 00:00:00 2001 From: Victor Kataev Date: Mon, 26 Oct 2026 17:01:18 +0000 Subject: [PATCH 3/3] build: separate application build and runtime stages - Install locked production dependencies with uv cache mounts - Package the application non-editably and copy only its environment into runtime - Include README and LICENSE in the build context for package metadata --- .dockerignore | 2 ++ Dockerfile | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1dc0c20..a2ad9bd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,8 @@ !pyproject.toml !uv.lock +!README.md +!LICENSE !src/ src/**/__pycache__/ diff --git a/Dockerfile b/Dockerfile index f4fd397..93b1fd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,38 @@ -FROM python:3.12-alpine +FROM python:3.12-alpine AS builder -ENV PYTHONDONTWRITEBYTECODE=1 \ - PYTHONUNBUFFERED=1 +ENV UV_LINK_MODE=copy \ + UV_PYTHON_DOWNLOADS=0 COPY --from=ghcr.io/astral-sh/uv:0.13.5 /uv /usr/local/bin/uv WORKDIR /app -COPY pyproject.toml uv.lock /app/ - # Warm up to avoid findpython timeout on arm64 build -RUN /usr/local/bin/python -EsSc 'import platform; print(platform.python_version())' \ - && UV_PROJECT_ENVIRONMENT=/usr/local uv sync --locked --no-dev --no-install-project --inexact +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + /usr/local/bin/python -EsSc 'import platform; print(platform.python_version())' \ + && uv sync --locked --no-dev --no-install-project --no-editable +COPY pyproject.toml uv.lock README.md LICENSE /app/ COPY src/ ./src/ -ENV PYTHONPATH=/app/src \ +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --locked --no-dev --no-editable + +FROM python:3.12-alpine + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PATH="/app/.venv/bin:$PATH" \ CALIBRE_LIBRARY_PATH=/app/calibre/ +WORKDIR /app + # Create a non-root user to run the application RUN addgroup -S -g 1000 appuser && adduser -S -u 1000 -G appuser appuser +COPY --from=builder --chown=1000:1000 /app/.venv /app/.venv + # Switch to the non-root user USER 1000:1000