|
1 | | -FROM python:3.11 |
2 | | - |
3 | | -# ARG DEBIAN_FRONTEND=noninteractive |
| 1 | +FROM ghcr.io/astral-sh/uv:python3.12-trixie-slim |
4 | 2 |
|
5 | 3 | LABEL name="ms2rescore" |
6 | 4 |
|
7 | | -# ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/ms2rescore |
| 5 | +# Setup a non-root user |
| 6 | +RUN groupadd --system --gid 999 nonroot \ |
| 7 | + && useradd --system --gid 999 --uid 999 --create-home nonroot |
| 8 | + |
| 9 | +# Install the project into `/ms2rescore` |
| 10 | +WORKDIR /ms2rescore |
| 11 | + |
| 12 | +# Enable bytecode compilation |
| 13 | +ENV UV_COMPILE_BYTECODE=1 |
| 14 | + |
| 15 | +# Copy from the cache instead of linking since it's a mounted volume |
| 16 | +ENV UV_LINK_MODE=copy |
8 | 17 |
|
| 18 | +# Ensure installed tools can be executed out of the box |
| 19 | +ENV UV_TOOL_BIN_DIR=/usr/local/bin |
| 20 | + |
| 21 | +RUN apt-get update && apt-get install -y procps |
| 22 | + |
| 23 | +# Then, add the rest of the project source code and install it |
| 24 | +# Installing separately from its dependencies allows optimal layer caching |
9 | 25 | ADD pyproject.toml /ms2rescore/pyproject.toml |
10 | 26 | ADD LICENSE /ms2rescore/LICENSE |
11 | 27 | ADD README.md /ms2rescore/README.md |
12 | 28 | ADD MANIFEST.in /ms2rescore/MANIFEST.in |
| 29 | +ADD uv.lock /ms2rescore/uv.lock |
13 | 30 | ADD ms2rescore /ms2rescore/ms2rescore |
14 | 31 |
|
15 | | -RUN apt-get update \ |
16 | | - && apt install -y procps \ |
17 | | - && pip install /ms2rescore --only-binary :all: |
| 32 | +# Install the project and its dependencies using the lockfile and settings |
| 33 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 34 | + uv sync --no-dev |
| 35 | + |
| 36 | +# Place executables in the environment at the front of the path |
| 37 | +ENV PATH="/ms2rescore/.venv/bin:$PATH" |
| 38 | + |
| 39 | +# Reset the entrypoint, don't invoke `uv` |
| 40 | +ENTRYPOINT [] |
18 | 41 |
|
19 | | -ENTRYPOINT [""] |
| 42 | +# Use the non-root user to run our application |
| 43 | +USER nonroot |
0 commit comments