1- FROM python:3.10 -slim
1+ FROM ghcr.io/astral-sh/uv:python3.14-trixie -slim
22
3+ # Setup a non-root user
4+ RUN groupadd --system --gid 999 nonroot \
5+ && useradd --system --gid 999 --uid 999 --create-home nonroot
6+
7+ # Install the project into `/app`
8+ WORKDIR /app
9+
10+ # Keeps Python from buffering stdout and stderr to avoid situations where
11+ # the application crashes without emitting any logs due to buffering.
312ENV PYTHONUNBUFFERED=1
413
5- RUN pip install --upgrade pip
14+ # Enable bytecode compilation
15+ ENV UV_COMPILE_BYTECODE=1
616
7- WORKDIR /app
17+ # Copy from the cache instead of linking since it's a mounted volume
18+ ENV UV_LINK_MODE=copy
19+
20+ # Omit development dependencies
21+ ENV UV_NO_DEV=1
22+
23+ # Ensure installed tools can be executed out of the box
24+ ENV UV_TOOL_BIN_DIR=/usr/local/bin
25+
26+ # Install the project's dependencies using the lockfile and settings
27+ RUN --mount=type=cache,target=/root/.cache/uv \
28+ --mount=type=bind,source=uv.lock,target=uv.lock \
29+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
30+ uv sync --locked --no-install-project
831
9- COPY requirements.txt .
10- RUN pip install --no-cache-dir -r requirements.txt
32+ # Then, add the rest of the project source code and install it
33+ # Installing separately from its dependencies allows optimal layer caching
34+ COPY . /app
35+ RUN --mount=type=cache,target=/root/.cache/uv \
36+ uv sync --locked
1137
12- COPY . .
38+ # Place executables in the environment at the front of the path
39+ ENV PATH="/app/.venv/bin:$PATH"
1340
14- EXPOSE 8766
41+ # Reset the entrypoint, don't invoke `uv`
42+ ENTRYPOINT []
1543
16- ENV IS_DOCKER=1
44+ # Use the non-root user to run our application
45+ USER nonroot
1746
18- CMD ["python" , "__main__.py" ]
47+ CMD ["uv" , "run" , " python" , "__main__.py" ]
0 commit comments