# ---------- BASE ----------
FROM python:3.12.9-slim AS base

# System deps (optional but often needed)
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install uv (official way)
RUN pip install --no-cache-dir uv

WORKDIR /app

# ---------- BUILDER ----------
FROM base AS builder

# Copy only dependency files first (for caching)
COPY pyproject.toml uv.lock* ./

# Create virtualenv
RUN uv venv

# Install dependencies (NO project code yet → better cache)
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --no-install-project --no-dev

# ---------- RUNTIME ----------
FROM python:3.12.9-slim AS runtime

WORKDIR /app

# Install uv (optional, only if you want uv run/debug)
RUN pip install --no-cache-dir uv

# Copy virtualenv from builder
COPY --from=builder /app/.venv /app/.venv

# Activate venv
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"

# Copy project code
COPY . .

# Install project itself (fast, no deps reinstall)
RUN uv pip install --no-deps .

# Run app
ENTRYPOINT ["python", "-m", "embedding_ingestion.main"]
