FROM ghcr.io/astral-sh/uv:debian-slim AS builder

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y git curl && rm -rf /var/lib/apt/lists/*

# Copy dependency files first for better caching
COPY pyproject.toml uv.lock .env* README.md ./
COPY src/ ./src/

# Install Python dependencies
RUN uv sync --no-dev --frozen --python {}

# Install nbr (ensure we get the correct architecture)
RUN curl -LsSf https://github.com/fllesser/nbr/releases/latest/download/nbr-Linux-musl-x86_64.tar.gz | tar -xzf - -C /usr/local/bin/ && \
    chmod +x /usr/local/bin/nbr

EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8080/health || exit 1

CMD ["nbr", "run"]