# Multi-stage Dockerfile for ultra-lightweight Crucible AI proxy

FROM python:3.11-slim as builder

WORKDIR /build

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy source
COPY pyproject.toml .
COPY src ./src
COPY README.md README-PYPI.md .

# Build wheel
RUN pip install --upgrade pip wheel && \
    pip wheel --no-cache-dir --no-deps --wheel-dir /wheels .


FROM python:3.11-slim

WORKDIR /app

# Copy wheels from builder
COPY --from=builder /wheels /wheels

LABEL version="1.0.1" description="Semantic cache + reverse proxy for LLM inference"

# Install runtime dependencies
RUN pip install --no-cache-dir --no-index --find-links /wheels crucible-ai && \
    rm -rf /wheels

# Expose default port
EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')" || exit 1

# Run Crucible AI
ENTRYPOINT ["crucible-ai"]
CMD ["start", "--port", "8080"]
