| # Build the Vite frontend | |
| FROM node:18-alpine AS frontend-builder | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm install | |
| COPY frontend/ . | |
| RUN npm run build | |
| # Use an official Python runtime as a parent image | |
| FROM python:3.11-slim-bookworm | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PORT=8000 | |
| # Set work directory | |
| WORKDIR /app | |
| # Install system dependencies (needed for some python packages like WeasyPrint) | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| python3-dev \ | |
| libpangocairo-1.0-0 \ | |
| libcairo2 \ | |
| libgdk-pixbuf-2.0-0 \ | |
| libffi-dev \ | |
| shared-mime-info \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy project | |
| COPY . . | |
| # Copy the built frontend from the builder stage | |
| COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist | |
| # Pre-download the embedding model so it's baked into the image | |
| # This saves ~420MB of bandwidth on every deploy and makes starts instant | |
| RUN python scripts/download_model.py | |
| # Expose the port required by Hugging Face Spaces | |
| EXPOSE 7860 | |
| # Start the application | |
| CMD uvicorn api.main:app --host 0.0.0.0 --port 7860 | |