ClassLens / Dockerfile
kuanz's picture
Add database management: Supabase persistence, teacher profiles, admin dashboard (#1)
4c4a722
Raw
History Blame Contribute Delete
2.26 kB
# ClassLens v2 - Hugging Face Spaces Docker Deployment
# Multi-stage build for React frontend + FastAPI backend
# =============================================================================
# Stage 1: Build React Frontend
# =============================================================================
FROM node:22-slim AS frontend-builder
WORKDIR /app/frontend
# Copy package files first for layer caching
COPY chatkit/frontend/package*.json ./
# Install dependencies
RUN npm ci --legacy-peer-deps
# Copy source files (after npm ci to leverage cache)
COPY chatkit/frontend/src ./src
COPY chatkit/frontend/public ./public
COPY chatkit/frontend/index.html chatkit/frontend/vite.config.ts chatkit/frontend/tsconfig*.json chatkit/frontend/postcss.config.mjs chatkit/frontend/eslint.config.mjs ./
# 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 Alembic migration config (applied on startup)
COPY --chown=user chatkit/backend/alembic.ini ./alembic.ini
COPY --chown=user chatkit/backend/alembic ./alembic
# 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')"
# Apply DB migrations (Supabase) then run the server.
# Migrations are a no-op for non-Postgres providers.
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 7860"]