# --- Build stage ---
FROM python:3.12-slim AS builder

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /app

# Enable bytecode compilation for faster startup
ENV UV_COMPILE_BYTECODE=1
# Use copy mode (no hardlinks in containers)
ENV UV_LINK_MODE=copy

# Install dependencies first (cached if pyproject.toml unchanged)
COPY pyproject.toml uv.lock* ./
RUN uv sync --no-dev --no-install-project --frozen

# Copy source and install project
COPY src/ ./src/
RUN uv sync --no-dev --frozen

# --- Runtime stage ---
FROM python:3.12-slim

WORKDIR /app

# Copy the entire venv and project from builder
COPY --from=builder /app /app

# Add venv to PATH so we don't need uv at runtime
ENV PATH="/app/.venv/bin:$PATH"
ENV DATA_DIR=/app/data

RUN mkdir -p /app/data

CMD ["rss-bot"]
