# ---------------------------- # STAGE 1: Build React frontend # ---------------------------- FROM node:20-alpine AS frontend-builder WORKDIR /build # Copy package.json first for dependency installation COPY frontend/package*.json ./ RUN npm ci # Install devDependencies for build # Copy rest of frontend source code COPY frontend/ ./ # Copy .env if exists COPY frontend/.env* ./ # Build React app RUN npm run build # Clean up node_modules to reduce image size RUN rm -rf node_modules # ---------------------------- # STAGE 2: Build FastAPI backend + embed frontend # ---------------------------- FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && \ apt-get install -y --no-install-recommends build-essential gcc && \ rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY backend/requirements.txt ./ RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy backend source code COPY backend/ ./ # Copy React build output into ./static for FastAPI # FIX: The Vite/React build outputs to /build/build/client COPY --from=frontend-builder /build/build/client ./static # ---------------------------- # HF Spaces ENV # ---------------------------- ENV PORT=7860 ENV HOST=0.0.0.0 ENV DEBUG=False EXPOSE 7860 # ---------------------------- # Make startup script executable and set it as entrypoint # ---------------------------- COPY backend/start.sh /app/start.sh RUN chmod +x /app/start.sh # ---------------------------- # Start FastAPI (runs migrations first) # ---------------------------- CMD ["/app/start.sh"]