|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
1 | 3 | FROM python:3.11-slim-bookworm |
2 | 4 |
|
3 | 5 | WORKDIR /app |
4 | 6 |
|
5 | | -# Install system deps (minimal) |
6 | | -RUN apt-get update && apt-get install -y --no-install-recommends \ |
7 | | - curl \ |
8 | | - && rm -rf /var/lib/apt/lists/* |
| 7 | +# Install uv (better: copy the static binary from the official uv image) |
| 8 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ |
9 | 9 |
|
10 | | -# Install uv |
11 | | -RUN pip install --no-cache-dir uv |
| 10 | +# Optional but common: keep uv caches in a known place |
| 11 | +ENV UV_CACHE_DIR=/root/.cache/uv |
12 | 12 |
|
13 | | -# Copy dependency files first (better cache) |
14 | | -COPY pyproject.toml uv.lock* ./ |
| 13 | +# Copy only dependency inputs first for better Docker layer caching |
| 14 | +COPY pyproject.toml uv.lock ./ |
15 | 15 |
|
16 | | -# Install dependencies |
17 | | -RUN uv install --no-cache-dir . |
| 16 | +# Create/sync the project environment from the lockfile |
| 17 | +# --frozen: fail if lock and project metadata don't match; don't update the lock |
| 18 | +# --no-dev: skip dev dependency groups in the final image |
| 19 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 20 | + uv sync --frozen --no-dev |
18 | 21 |
|
19 | | -# Copy app code |
| 22 | +# Now copy the rest of the app |
20 | 23 | COPY . . |
21 | 24 |
|
22 | | -EXPOSE 8000 |
| 25 | +# Make sure the venv's executables are on PATH |
| 26 | +ENV PATH="/app/.venv/bin:$PATH" |
23 | 27 |
|
24 | | -CMD ["python", "tests/mock_server.py"] |
| 28 | +EXPOSE 8000 |
| 29 | +CMD ["uv", "run", "--frozen", "python", "tests/mock_server.py"] |
0 commit comments