# Stage 1: Build React Frontend FROM node:20-alpine AS build WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm install COPY frontend . RUN npm run build # Stage 2: Serve with FastAPI (Hugging Face setup) FROM python:3.11-slim # Create a non-root user matching Hugging Face defaults (1000) RUN useradd -m -u 1000 user WORKDIR /app # System dependencies for scientific packages RUN apt-get update && apt-get install -y gcc g++ \ && rm -rf /var/lib/apt/lists/* # Copy project metadata and backend source for package installation COPY pyproject.toml README.md ./ COPY backend ./backend/ RUN pip install --no-cache-dir . # Create necessary directories and set ownership RUN mkdir -p /app/backend /data /app/frontend RUN chown -R user:user /app /data # Switch to the non-root user USER user # Copy pre-built frontend from stage 1 COPY --from=build --chown=user:user /app/frontend/dist /app/frontend/dist # Copy legacy data for ML Engine COPY --chown=user:user data ./data/ # Copy backend source COPY --chown=user:user backend ./backend/ # Hugging Face deployment assumes we serve on 7860 EXPOSE 7860 # FastAPI startup CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]