# Backend API Service
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies for PDF parsing and embeddings
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Create cache directory with persistent volume mount point
RUN mkdir -p /app/.embed_cache

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY app/ ./app/

# Mount volumes at these paths (configured in docker-compose)
# ./docs -> /docs  
# ./data -> /data
# /data holds: db.sqlite, qdrant storage volume mount from docker-compose

# Expose API port
EXPOSE 8787

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

# Run the FastAPI application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8787"]
