@@ -10,78 +10,76 @@ RUN chown nonroot:nonroot /app
1010# Creating a separate directory for venvs allows to easily
1111# copy them from the builder and to mount the application
1212# 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"
1415
1516# Install necessary runtime libraries (e.g. libmysql)
1617RUN apt-get update \
1718 && apt-get install -y --no-install-recommends \
1819 make \
1920 && rm -rf /var/lib/apt/lists/*
2021
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-
2922FROM base AS base_builder
23+ ENV UV_PROJECT_ENVIRONMENT=/venv
24+ # Enable bytecode compilation
25+ ENV UV_COMPILE_BYTECODE=1
26+
3027# Install build system requirements (gcc, library headers, etc.)
3128# for compiled Python requirements like psycopg2
3229RUN apt-get update \
3330 && apt-get install -y --no-install-recommends \
3431 build-essential gcc git \
3532 && rm -rf /var/lib/apt/lists/*
3633
34+ COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /bin/
35+
3736# From here we shouldn't need anymore a root user
3837# Switch to nonroot and config poetry
3938USER nonroot
40- RUN poetry config virtualenvs.path /poetryvenvs
4139
4240COPY --chown=nonroot:nonroot pyproject.toml .
43- COPY --chown=nonroot:nonroot poetry .lock .
41+ COPY --chown=nonroot:nonroot uv .lock .
4442COPY --chown=nonroot:nonroot Makefile .
4543
46- # Test image, contains all files and dependencies
44+ # Dev image, contains all files and dependencies
4745FROM base_builder AS dev
4846COPY --chown=nonroot:nonroot . .
49- RUN make dev-dependencies
47+ RUN --mount=type=cache,target=~/.cache/uv \
48+ make dev-dependencies
49+
5050# Note that opentelemetry doesn't play well together with uvicorn reloader
5151# when signals are propagated, we disable it in dev image default CMD
5252CMD ["uvicorn" , "http_app:create_app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--factory" , "--reload" ]
5353
5454# Installs requirements to run production dramatiq application
5555FROM 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
5758
5859# Installs requirements to run production http application
5960FROM 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
6163
62- # Copy the shared python packages
64+ # Create the base app with the common python packages
6365FROM base AS base_app
6466USER nonroot
65- RUN poetry config virtualenvs.path /poetryvenvs
66- COPY --chown=nonroot:nonroot pyproject.toml .
67- COPY --chown=nonroot:nonroot poetry.lock .
6867COPY --chown=nonroot:nonroot src/alembic ./alembic
6968COPY --chown=nonroot:nonroot src/domains ./domains
7069COPY --chown=nonroot:nonroot src/gateways ./gateways
7170COPY --chown=nonroot:nonroot src/common ./common
7271COPY --chown=nonroot:nonroot src/alembic.ini .
73- COPY --chown=nonroot:nonroot Makefile .
7472
7573# Copy the http python package and requirements from relevant builder
7674FROM base_app AS http_app
77- COPY --from=http_builder /poetryvenvs /poetryvenvs
75+ COPY --from=http_builder /venv /venv
7876COPY --chown=nonroot:nonroot src/http_app ./http_app
7977# Run CMD using array syntax, so it's uses `exec` and runs as PID1
8078CMD ["opentelemetry-instrument" , "uvicorn" , "http_app:create_app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--factory" ]
8179
8280# Copy the dramatiq python package and requirements from relevant builder
8381FROM base_app AS dramatiq_app
84- COPY --from=dramatiq_builder /poetryvenvs /poetryvenvs
82+ COPY --from=dramatiq_builder /venv /venv
8583COPY --chown=nonroot:nonroot src/dramatiq_worker ./dramatiq_worker
8684# Run CMD using array syntax, so it's uses `exec` and runs as PID1
8785# TODO: Review processes/threads
0 commit comments