| # Multi-stage build for Hugging Face Spaces (Docker) with single URL serving | |
| # --- Frontend build stage --- | |
| FROM node:20-alpine AS frontend-build | |
| WORKDIR /app | |
| COPY frontend/package*.json ./ | |
| RUN npm ci | |
| COPY frontend ./ | |
| RUN npm run build | |
| # --- Backend stage --- | |
| FROM python:3.11-slim AS runtime | |
| # System deps for OpenCV and general libs | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| build-essential \ | |
| python3-dev \ | |
| git \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # Install backend deps | |
| COPY backend/requirements.txt /app/backend/requirements.txt | |
| RUN pip install --upgrade pip && \ | |
| pip install --no-cache-dir -r /app/backend/requirements.txt | |
| # Copy application code | |
| COPY backend /app/backend | |
| COPY content /app/content | |
| # Copy built frontend | |
| COPY --from=frontend-build /app/dist /app/frontend_dist | |
| # Environment | |
| ENV PORT=7860 \ | |
| DATA_DIR=/data \ | |
| FRONTEND_DIST=/app/frontend_dist | |
| EXPOSE 7860 | |
| # Run FastAPI (serve API + static frontend) | |
| CMD ["python", "-m", "uvicorn", "app.main:app", "--app-dir", "backend", "--host", "0.0.0.0", "--port", "7860"] | |