11# Ideas from https://docs.astral.sh/uv/guides/integration/docker/
2+ # and https://hynek.me/articles/docker-uv/
23
3- FROM python:3.12-bullseye AS builder-base
4+ FROM python:3.13-bookworm AS builder-base
45
5- ARG PROJECT_VERSION
6+ ENV PYTHONUNBUFFERED=1 \
7+ PYTHONDONTWRITEBYTECODE=1 \
8+ UV_LINK_MODE=copy \
9+ UV_COMPILE_BYTECODE=1 \
10+ UV_PYTHON_DOWNLOADS=never \
11+ PATH="/app/.venv/bin:$PATH" \
12+ # There is no git during image build so we need to provide a fake version
13+ UV_DYNAMIC_VERSIONING_BYPASS=0.0.0
614
715# Install dependencies for the `psql` command.
816# Must match the version of the postgres service in the compose file!
@@ -13,25 +21,16 @@ RUN apt-get update \
1321 postgresql-client-17 \
1422 && rm -rf /var/lib/apt/lists/*
1523
16- ENV PYTHONUNBUFFERED=1 \
17- PYTHONDONTWRITEBYTECODE=1
18-
1924COPY --from=ghcr.io/astral-sh/uv:0.7.2 /uv /uvx /bin/
2025
21- ENV UV_COMPILE_BYTECODE=1 \
22- UV_LINK_MODE=copy
23-
24- # There is no git during image build so we need to provide a fake version
25- ENV UV_DYNAMIC_VERSIONING_BYPASS=0.0.0
26-
27- ENV PATH="/app/.venv/bin:$PATH"
28-
2926WORKDIR /app
3027
31-
32- # development image
28+ # ##
29+ # Development image
30+ # ##
3331FROM builder-base AS development
3432
33+ # Install dependencies without project itself
3534RUN --mount=type=cache,target=/root/.cache/uv \
3635 --mount=type=bind,source=uv.lock,target=uv.lock \
3736 --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
@@ -41,22 +40,29 @@ RUN playwright install --with-deps chromium
4140
4241ADD . /app
4342
43+ # Install project itself
4444RUN --mount=type=cache,target=/root/.cache/uv \
45- uv sync --frozen
45+ uv sync --locked
4646
47+ ARG PROJECT_VERSION
4748ENV PROJECT_VERSION=${PROJECT_VERSION}
4849
49- # production image
50+ # ##
51+ # Production image
52+ # ##
5053FROM builder-base AS production
5154
55+ # Install dependencies without dev and project itself
5256RUN --mount=type=cache,target=/root/.cache/uv \
5357 --mount=type=bind,source=uv.lock,target=uv.lock \
5458 --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
5559 uv sync --frozen --no-install-project --no-dev
5660
5761ADD . /app
5862
63+ # Install project itself
5964RUN --mount=type=cache,target=/root/.cache/uv \
60- uv sync --frozen --no-dev
65+ uv sync --locked --no-dev
6166
67+ ARG PROJECT_VERSION
6268ENV PROJECT_VERSION=${PROJECT_VERSION}
0 commit comments