@@ -10,78 +10,76 @@ RUN chown nonroot:nonroot /app
10
10
# Creating a separate directory for venvs allows to easily
11
11
# copy them from the builder and to mount the application
12
12
# for local development
13
- RUN mkdir /poetryvenvs && chown nonroot:nonroot /poetryvenvs
13
+ RUN mkdir /venv && chown nonroot:nonroot /venv
14
+ ENV PATH="/venv/bin:$PATH"
14
15
15
16
# Install necessary runtime libraries (e.g. libmysql)
16
17
RUN apt-get update \
17
18
&& apt-get install -y --no-install-recommends \
18
19
make \
19
20
&& rm -rf /var/lib/apt/lists/*
20
21
21
- # Update pip and install poetry
22
- RUN pip install --no-cache-dir -U pip
23
- RUN pip install --no-cache-dir -U poetry
24
-
25
- # We run everything by poetry run from now on, so that PATH will be handled
26
- # for binaries installed in virtual environments
27
- ENTRYPOINT ["poetry" , "run" ]
28
-
29
22
FROM base AS base_builder
23
+ ENV UV_PROJECT_ENVIRONMENT=/venv
24
+ # Enable bytecode compilation
25
+ ENV UV_COMPILE_BYTECODE=1
26
+
30
27
# Install build system requirements (gcc, library headers, etc.)
31
28
# for compiled Python requirements like psycopg2
32
29
RUN apt-get update \
33
30
&& apt-get install -y --no-install-recommends \
34
31
build-essential gcc git \
35
32
&& rm -rf /var/lib/apt/lists/*
36
33
34
+ COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /bin/
35
+
37
36
# From here we shouldn't need anymore a root user
38
37
# Switch to nonroot and config poetry
39
38
USER nonroot
40
- RUN poetry config virtualenvs.path /poetryvenvs
41
39
42
40
COPY --chown=nonroot:nonroot pyproject.toml .
43
- COPY --chown=nonroot:nonroot poetry .lock .
41
+ COPY --chown=nonroot:nonroot uv .lock .
44
42
COPY --chown=nonroot:nonroot Makefile .
45
43
46
- # Test image, contains all files and dependencies
44
+ # Dev image, contains all files and dependencies
47
45
FROM base_builder AS dev
48
46
COPY --chown=nonroot:nonroot . .
49
- RUN make dev-dependencies
47
+ RUN --mount=type=cache,target=~/.cache/uv \
48
+ make dev-dependencies
49
+
50
50
# Note that opentelemetry doesn't play well together with uvicorn reloader
51
51
# when signals are propagated, we disable it in dev image default CMD
52
52
CMD ["uvicorn" , "http_app:create_app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--factory" , "--reload" ]
53
53
54
54
# Installs requirements to run production dramatiq application
55
55
FROM base_builder AS dramatiq_builder
56
- RUN poetry install --no-root
56
+ RUN --mount=type=cache,target=~/.cache/uv \
57
+ uv sync --no-dev --no-install-project --frozen --no-editable
57
58
58
59
# Installs requirements to run production http application
59
60
FROM base_builder AS http_builder
60
- RUN poetry install --no-root --with http
61
+ RUN --mount=type=cache,target=~/.cache/uv \
62
+ uv sync --no-dev --group http --no-install-project --frozen --no-editable
61
63
62
- # Copy the shared python packages
64
+ # Create the base app with the common python packages
63
65
FROM base AS base_app
64
66
USER nonroot
65
- RUN poetry config virtualenvs.path /poetryvenvs
66
- COPY --chown=nonroot:nonroot pyproject.toml .
67
- COPY --chown=nonroot:nonroot poetry.lock .
68
67
COPY --chown=nonroot:nonroot src/alembic ./alembic
69
68
COPY --chown=nonroot:nonroot src/domains ./domains
70
69
COPY --chown=nonroot:nonroot src/gateways ./gateways
71
70
COPY --chown=nonroot:nonroot src/common ./common
72
71
COPY --chown=nonroot:nonroot src/alembic.ini .
73
- COPY --chown=nonroot:nonroot Makefile .
74
72
75
73
# Copy the http python package and requirements from relevant builder
76
74
FROM base_app AS http_app
77
- COPY --from=http_builder /poetryvenvs /poetryvenvs
75
+ COPY --from=http_builder /venv /venv
78
76
COPY --chown=nonroot:nonroot src/http_app ./http_app
79
77
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
80
78
CMD ["opentelemetry-instrument" , "uvicorn" , "http_app:create_app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--factory" ]
81
79
82
80
# Copy the dramatiq python package and requirements from relevant builder
83
81
FROM base_app AS dramatiq_app
84
- COPY --from=dramatiq_builder /poetryvenvs /poetryvenvs
82
+ COPY --from=dramatiq_builder /venv /venv
85
83
COPY --chown=nonroot:nonroot src/dramatiq_worker ./dramatiq_worker
86
84
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
87
85
# TODO: Review processes/threads
0 commit comments