|
1 |
| -# Adapted from https://github.com/astral-sh/uv-docker-example |
| 1 | +FROM ghcr.io/praekeltfoundation/docker-django-bootstrap-nw:py3.9-bullseye |
2 | 2 |
|
3 |
| -# Use a Python image with uv pre-installed |
4 |
| -FROM ghcr.io/astral-sh/uv:python3.10-bookworm AS builder |
| 3 | +COPY . /app |
5 | 4 |
|
6 |
| -# Install the project into `/app` |
7 |
| -WORKDIR /app |
8 |
| - |
9 |
| -# Enable bytecode compilation |
10 |
| -ENV UV_COMPILE_BYTECODE=1 |
11 |
| - |
12 |
| -# Copy from the cache instead of linking since it's a mounted volume |
13 |
| -ENV UV_LINK_MODE=copy |
14 |
| - |
15 |
| -# Install the project's dependencies using the lockfile and settings |
16 |
| -RUN --mount=type=cache,target=/root/.cache/uv \ |
17 |
| - --mount=type=bind,source=uv.lock,target=uv.lock \ |
18 |
| - --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
19 |
| - uv sync --frozen --no-install-project --no-dev |
20 |
| - |
21 |
| -# Then, add the rest of the project source code and install it |
22 |
| -# Installing separately from its dependencies allows optimal layer caching |
23 |
| -ADD . /app |
24 |
| -RUN --mount=type=cache,target=/root/.cache/uv \ |
25 |
| - uv sync --frozen --no-dev |
26 |
| - |
27 |
| - |
28 |
| -# Then, use a final image without uv |
29 |
| -FROM ghcr.io/praekeltfoundation/docker-django-bootstrap-nw:py3.10-bullseye |
30 |
| -# It is important to use the image that matches the builder, as the path to the |
31 |
| -# Python executable must be the same, e.g., using `python:3.11-slim-bookworm` |
32 |
| -# will fail. |
33 |
| - |
34 |
| -# Copy the application from the builder |
35 |
| -COPY --from=builder --chown=app:app /app /app |
36 |
| - |
37 |
| -RUN pip install uv |
38 |
| -RUN uv venv |
39 |
| - |
40 |
| -# Place executables in the environment at the front of the path |
41 |
| -ENV PATH="/app/.venv/bin:$PATH" |
| 5 | +RUN pip install -e . |
42 | 6 |
|
43 | 7 | ENV DJANGO_SETTINGS_MODULE "config.settings.production"
|
44 | 8 | RUN SECRET_KEY=placeholder ALLOWED_HOSTS=placeholder python manage.py collectstatic --noinput
|
|
0 commit comments