-
-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (59 loc) · 2.12 KB
/
Dockerfile
File metadata and controls
76 lines (59 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -----------------------------------
# STAGE BUILDER: Prepare builder image
# Only install main dependencies
# -----------------------------------
FROM ghcr.io/astral-sh/uv:0.9.17-python3.13-bookworm-slim AS builder
{%- if cookiecutter.db_info.name == "mysql" %}
RUN apt-get update && apt-get install -y \
default-libmysqlclient-dev \
gcc \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
{%- endif %}
{%- if cookiecutter.db_info.name == "postgresql" %}
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
{%- endif %}
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=0 \
UV_PROJECT_ENVIRONMENT=/opt/.venv \
VIRTUAL_ENV="/opt/.venv" \
PATH="/opt/.venv/bin:$PATH" \
{%- if cookiecutter.orm == 'piccolo' %}
PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \
{%- endif %}
UV_NO_DEV=1
WORKDIR /app/src
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 --locked --no-install-project
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked
# -----------------------------------
# STAGE PROD: Production image
# Copy dependencies and environment from builder image
# -----------------------------------
FROM python:3.13-slim-bookworm AS prod
RUN groupadd --system --gid 999 nonroot \
&& useradd --system --gid 999 --uid 999 --create-home nonroot
ENV VIRTUAL_ENV="/opt/.venv" \
{%- if cookiecutter.orm == 'piccolo' %}
PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf" \
{%- endif %}
PATH="/opt/.venv/bin:$PATH"
COPY --from=builder --chown=nonroot:nonroot /app/src /app/src
COPY --from=builder --chown=nonroot:nonroot /opt/.venv /opt/.venv
USER nonroot
WORKDIR /app/src
# -----------------------------------
# STAGE DEVELOPMENT: Development image
# Copy dependencies and environment from builder image and add dev dependencies
# -----------------------------------
FROM builder AS dev
ENV UV_NO_DEV=0
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --all-groups