Repository navigation
Expand file tree
/
Copy pathDockerfile.debug
More file actions
45 lines (38 loc) · 1.89 KB
/
Copy pathDockerfile.debug
File metadata and controls
45 lines (38 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Debug variant of Dockerfile: identical image, but waits for a debugpy client
# on 5678 before starting. Keep in step with Dockerfile.
ARG PYTHONVER=3.14
ARG DISTROBASE=bookworm
FROM ghcr.io/astral-sh/uv:python${PYTHONVER}-${DISTROBASE}-slim AS builder
# See Dockerfile: without this, uv downloads a managed interpreter that the
# final stage never copies, leaving .venv/bin/python3 dangling.
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_PREFERENCE=only-system
WORKDIR /app
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 \
uv sync --frozen --no-install-project --no-dev
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
# Then, use a final image without uv
FROM python:${PYTHONVER}-slim-${DISTROBASE}
# It is important to use the image that matches the builder, as the path to the
# Python executable must be the same, e.g., using `python:3.11-slim-bookworm`
# will fail.
# Run unprivileged. /app must remain writable by that user: the default
# SQLALCHEMY_DATABASE_URI puts app.db alongside config.py.
RUN useradd --create-home --uid 1000 app
# Copy the application from the builder
COPY --from=builder --chown=app:app /app /app
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1
# Probe with the interpreter that is already here rather than installing curl.
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD ["python3", "-c", "import sys,urllib.request; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/health', timeout=2).status == 200 else 1)"]
# Extra steps for debugging
RUN pip install debugpy -t /tmp
USER app
WORKDIR /app
EXPOSE 8000 5678
CMD ["python3", "/tmp/debugpy", "--wait-for-client", "--listen", "0.0.0.0:5678", "app.py"]