# syntax=docker/dockerfile:1 # Build stage: install dependencies into a virtual environment with uv. FROM python:3.13-slim AS build COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv # Compile bytecode for faster starts, and copy files out of the cache instead of linking them. ENV UV_COMPILE_BYTECODE=1 \ UV_LINK_MODE=copy \ UV_PYTHON_DOWNLOADS=0 WORKDIR /app # Dependencies first, so this layer stays cached until pyproject.toml or uv.lock changes. RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --locked --no-install-project --no-dev # Then the project itself. COPY . . RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --locked --no-dev --no-editable # Runtime stage: the same Python, the virtual environment and the code, without uv. FROM python:3.13-slim RUN groupadd --system app && useradd --system --gid app --no-create-home app WORKDIR /app COPY --from=build --chown=app:app /app /app ENV PATH="/app/.venv/bin:$PATH" \ PYTHONUNBUFFERED=1 USER app EXPOSE 8000 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]