Spaces:
Runtime error
Runtime error
| # ExamInsight - Hugging Face Spaces Docker Deployment | |
| # Multi-stage build for React frontend + FastAPI backend | |
| # ============================================================================= | |
| # Stage 1: Build React Frontend | |
| # ============================================================================= | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /app/frontend | |
| # Copy package files | |
| COPY frontend/package*.json ./ | |
| # Install dependencies | |
| RUN npm ci --legacy-peer-deps | |
| # Copy source files | |
| COPY frontend/ ./ | |
| # Build for production (output to dist/) | |
| RUN npm run build | |
| # ============================================================================= | |
| # Stage 2: Python Backend + Serve Frontend | |
| # ============================================================================= | |
| FROM python:3.11-slim | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| # Create non-root user for HF Spaces | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user | |
| ENV PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Install Python dependencies | |
| COPY --chown=user backend/pyproject.toml ./ | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir . | |
| # Copy backend code | |
| COPY --chown=user backend/app ./app | |
| # Copy report template | |
| COPY --chown=user report-template.html ./ | |
| # Copy built frontend from Stage 1 | |
| COPY --from=frontend-builder --chown=user /app/frontend/dist ./static | |
| # Copy report template HTML file | |
| COPY --chown=user backend/static/report-template.html ./static/report-template.html | |
| # Expose port (HF Spaces uses 7860) | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" | |
| # Run the server | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"] | |