|
1 | | -FROM python:3.9 |
| 1 | +# Use a Python image with uv pre-installed |
| 2 | +FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim |
2 | 3 |
|
3 | | -WORKDIR /code |
| 4 | +# Install the project into `/app` |
| 5 | +WORKDIR /app |
4 | 6 |
|
5 | | -# set python env variables |
6 | | -ENV PYTHONDONTWRITEBYTECODE 1 |
7 | | -ENV PYTHONUNBUFFERED 1 |
| 7 | +# Enable bytecode compilation |
| 8 | +ENV UV_COMPILE_BYTECODE=1 |
8 | 9 |
|
9 | | -# install pipenv |
10 | | -RUN pip install pipenv |
| 10 | +# Copy from the cache instead of linking since it's a mounted volume |
| 11 | +ENV UV_LINK_MODE=copy |
11 | 12 |
|
12 | | -# copy required pipenv files |
13 | | -COPY ./Pipfile ./Pipfile.lock /code/ |
| 13 | +# Install the project's dependencies using the lockfile and settings |
| 14 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 15 | + --mount=type=bind,source=uv.lock,target=uv.lock \ |
| 16 | + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
| 17 | + uv sync --frozen --no-install-project --no-dev |
14 | 18 |
|
15 | | -# install requirements locally in the project at /code/.venv |
16 | | -RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy |
| 19 | +# Then, add the rest of the project source code and install it |
| 20 | +# Installing separately from its dependencies allows optimal layer caching |
| 21 | +ADD backend /app |
| 22 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 23 | + --mount=type=bind,source=uv.lock,target=uv.lock \ |
| 24 | + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
| 25 | + uv sync --frozen --no-dev |
17 | 26 |
|
18 | | -# add requirements to path |
19 | | -ENV PATH="/code/.venv/bin:$PATH" |
| 27 | +# Place executables in the environment at the front of the path |
| 28 | +ENV PATH="/app/.venv/bin:$PATH" |
20 | 29 |
|
21 | | -ENV PYTHONPATH=/code |
22 | | - |
23 | | -# copy app code at end to make it easier to change code and not have to rebuild requirement layers |
24 | | -COPY ./app /code/app |
25 | | -COPY ./heartbeat_listener.py /code/heartbeat_listener.py |
| 30 | +# Reset the entrypoint, don't invoke `uv` |
| 31 | +ENTRYPOINT [] |
26 | 32 |
|
27 | 33 | CMD ["python", "heartbeat_listener.py"] |
0 commit comments