# --- Build Stage: Frontend --- FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm install COPY frontend/ ./ # Set production environment for build ENV NODE_ENV=production RUN npm run build # --- Stage: Final Image --- FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Copy backend requirements and install COPY backend/requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy backend code COPY backend/ ./ # Copy built frontend from previous stage to the static directory served by FastAPI COPY --from=frontend-builder /app/frontend/out ./static # Environment variables ENV PORT=7860 ENV DATABASE_URL="" # Hugging Face Spaces run on port 7860 by default EXPOSE 7860 # Command to run the application # We use uvicorn to run the FastAPI app, which now also serves the frontend CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]