# Multi-stage Dockerfile for Drift Quant on Hugging Face Spaces # ------------------------------------------------------------------------------ # Stage 1: Build the React 19 Frontend # ------------------------------------------------------------------------------ FROM node:20-slim AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm ci COPY frontend/ ./ RUN npm run build # ------------------------------------------------------------------------------ # Stage 2: Python 3.12 Backend & Production Image # ------------------------------------------------------------------------------ FROM python:3.12-slim # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ git \ build-essential \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Install uv for fast, reliable Python dependency resolution RUN pip install --no-cache-dir uv # Copy dependency definition and install COPY pyproject.toml ./ RUN uv pip install --system --no-cache -e . # Copy backend source code, persisted artifacts, and data archive COPY src/ /app/src/ COPY artifacts/ /app/artifacts/ COPY all_NSE500_15min_data_2019_onwards.zip /app/all_NSE500_15min_data_2019_onwards.zip # Copy built frontend assets from builder stage COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist # Set environment variables for production execution ENV PYTHONUNBUFFERED=1 \ PORT=7860 \ HOST=0.0.0.0 \ FRONTEND_DIST_DIR=/app/frontend/dist # Hugging Face Spaces security requirement: runs as non-root user (UID 1000) RUN useradd -m -u 1000 user && \ chown -R user:user /app USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH EXPOSE 7860 # Run FastAPI app on Hugging Face default port 7860 CMD ["uvicorn", "drift_quant.api.app:app", "--host", "0.0.0.0", "--port", "7860"]