FROM python:3.12-slim

WORKDIR /app

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

# Install cacheback with proxy extras
COPY pyproject.toml README.md LICENSE ./
COPY cacheback/ cacheback/
RUN pip install --no-cache-dir ".[proxy]"

# Cache directory (mount a volume for persistence)
ENV CACHEBACK_CACHE_DIR=/data/cacheback
RUN mkdir -p /data/cacheback

EXPOSE 8080

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

CMD ["python", "-m", "cacheback.proxy"]
