ClassLensPortal / chatkit /Dockerfile
taboola
restore demo data, remove category breakdown
1acff4f
Raw History Blame Contribute Delete
2.32 kB
# 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 Alembic migrations + config — needed at runtime because the
# entrypoint applies pending migrations before uvicorn starts (there's no
# separate deploy step that runs `alembic upgrade head`).
COPY --chown=user backend/alembic ./alembic
COPY --chown=user backend/alembic.ini ./alembic.ini
# 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
# Entrypoint: runs pending migrations (Supabase only) as their own process,
# then execs uvicorn — see entrypoint.sh for why this isn't done in-process.
COPY --chown=user entrypoint.sh ./entrypoint.sh
# 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 ["./entrypoint.sh"]