FROM ghcr.io/astral-sh/uv:latest as uv
FROM nvidia/cuda:12.8.0-runtime-ubuntu22.04

# Install minimal dependencies for uv
RUN apt-get update && apt-get install -y \
    curl \
    ca-certificates \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy uv from the uv image
COPY --from=uv /uv /uvx /bin/

# Install Python using uv
RUN uv python install 3.13

# Set working directory
WORKDIR /app

# Copy project files
COPY pyproject.toml uv.lock ./

# Install dependencies with cache mount for faster rebuilds
RUN --mount=type=cache,target=/root/.cache/uv \
    UV_LINK_MODE=copy \
    uv sync --frozen --no-install-project

# Copy the rest of the application
COPY . .

# Final sync to install the project itself
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen

# Run the application
CMD ["uv", "run", "python", "main.py"]