Skip to content

Commit eedc62e

Browse files
committed
Improve Dockerfile and build
1 parent f176fa9 commit eedc62e

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
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-
1924
COPY --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-
2926
WORKDIR /app
3027

31-
32-
# development image
28+
###
29+
# Development image
30+
###
3331
FROM builder-base AS development
3432

33+
# Install dependencies without project itself
3534
RUN --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

4241
ADD . /app
4342

43+
# Install project itself
4444
RUN --mount=type=cache,target=/root/.cache/uv \
45-
uv sync --frozen
45+
uv sync --locked
4646

47+
ARG PROJECT_VERSION
4748
ENV PROJECT_VERSION=${PROJECT_VERSION}
4849

49-
# production image
50+
###
51+
# Production image
52+
###
5053
FROM builder-base AS production
5154

55+
# Install dependencies without dev and project itself
5256
RUN --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

5761
ADD . /app
5862

63+
# Install project itself
5964
RUN --mount=type=cache,target=/root/.cache/uv \
60-
uv sync --frozen --no-dev
65+
uv sync --locked --no-dev
6166

67+
ARG PROJECT_VERSION
6268
ENV PROJECT_VERSION=${PROJECT_VERSION}

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ x-app: &default-app
22
image: example_project_dev:latest
33
build:
44
target: development
5+
pull_policy: build
56
volumes:
67
- .:/app
78
- /app/.venv
@@ -19,7 +20,6 @@ services:
1920

2021
web:
2122
<<: *default-app
22-
pull_policy: build
2323
ports:
2424
- ${WEB_DEV_PORT:-8000}:8000
2525
- ${REMOTE_DEBUGGING_PORT:-5678}:5678

0 commit comments

Comments
 (0)