Spaces:
Sleeping
Sleeping
| # Stage 1: Build the Frontend | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /app/frontend | |
| # Install git as some npm dependencies may require it | |
| RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* | |
| # Cache-buster to force fresh build: 2026-04-09_v3 | |
| ENV REBUILD_UI=4 | |
| COPY frontend/package*.json ./ | |
| RUN npm install | |
| COPY frontend/ . | |
| RUN npm run build | |
| # Stage 2: Final Runtime | |
| FROM python:3.11-slim | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| git \ | |
| poppler-utils \ | |
| tesseract-ocr \ | |
| tesseract-ocr-sqi \ | |
| ffmpeg \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Copy and install Python dependencies (slim runtime only) | |
| COPY --chown=user requirements-space.txt . | |
| RUN pip install --no-cache-dir --upgrade -r requirements-space.txt | |
| # Pre-download Whisper model to speed up first use | |
| RUN python -c "import whisper; whisper.load_model('small')" | |
| # Copy pre-built frontend | |
| COPY --chown=user --from=frontend-builder /app/frontend/dist ./frontend/dist | |
| # Copy application code and data | |
| COPY --chown=user . . | |
| # Create directories for ChromaDB and temp files | |
| RUN mkdir -p data/chroma_db data/gold | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/api/health')" || exit 1 | |
| # Run the FastAPI server | |
| EXPOSE 7860 | |
| CMD ["uvicorn", "app.api:app", "--host", "0.0.0.0", "--port", "7860"] | |