ClassLens / Dockerfile
chih.yikuan
Fix: Change SDK from static to docker and add Dockerfile at root
4d7cfb5
# 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 chatkit/frontend/package*.json ./
# Install dependencies
RUN npm ci --legacy-peer-deps
# Copy source files
COPY chatkit/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 chatkit/backend/pyproject.toml ./
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir .
# Copy backend code
COPY --chown=user chatkit/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
# 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"]