# Multi-stage build for React frontend and FastAPI backend # Stage 1: Build the frontend FROM node:20-slim AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm install COPY frontend/ ./ RUN npm run build # Stage 2: Build the final image FROM python:3.11-slim WORKDIR /app # Install system dependencies for OCR and PDF processing RUN apt-get update && apt-get install -y \ libgl1 \ libglx-mesa0 \ libglib2.0-0 \ build-essential \ && rm -rf /var/lib/apt/lists/* # Copy backend requirements and install COPY backend/requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy backend code COPY backend/ /app/ # Copy built frontend assets to static folder in backend COPY --from=frontend-builder /app/frontend/dist /app/static # Set environment variables for production ENV PYTHONUNBUFFERED=1 ENV PORT=7860 # Expose the port HF Spaces expects EXPOSE 7860 # Start the application on 0.0.0.0 for container access CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]