# Use Python 3.12 slim image as the base
FROM python:3.12-slim-bookworm

# Copy the `uv` binary from the astral-sh Docker image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Enable Python bytecode compilation for performance
ENV UV_COMPILE_BYTECODE=1

# Use cache instead of linking for mounted volumes
ENV UV_LINK_MODE=copy

# Set the working directory
WORKDIR /app

# Install dependencies using the lockfile and settings
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 --frozen --no-install-project --no-dev

# Add the rest of the project source code and install it
# This step ensures dependencies are separate from source code for better caching
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-dev

# Add executables to the path
ENV PATH="/app/.venv/bin:$PATH"

# Reset the entrypoint, allowing custom commands
ENTRYPOINT []

# Default command (can be overridden)
CMD ["uv", "run"]

