# Rerank API Server
# Multi-stage build for smaller final image

FROM python:3.11.12-slim AS builder

# Install uv
COPY --from=ghcr.io/astral-sh/uv:0.10 /uv /usr/local/bin/uv

WORKDIR /app

# Copy project files
COPY pyproject.toml README.md ./
COPY src/ ./src/

# Install dependencies (with optional extras for backends)
RUN uv sync --frozen --no-dev --all-extras || uv sync --no-dev --all-extras

# Production image
FROM python:3.11.12-slim

WORKDIR /app

# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv

# Copy source code
COPY src/ ./src/

# Set environment variables
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=1
ENV RERANK_HOST=0.0.0.0
ENV RERANK_PORT=14200

# Health check (using Python since curl not available in slim image)
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:14200/health')" || exit 1

# Expose port
EXPOSE 14200

# Run the server
CMD ["python", "-m", "rerank.cli"]
