# --- STAGE 1: Build Frontend --- FROM node:20-slim AS frontend-builder WORKDIR /build # Use --no-cache and clear npm cache to keep this layer small if needed, # although it's a build stage. COPY frontend/package*.json ./ RUN npm install --no-audit --no-fund COPY frontend/ ./ RUN npm run build # --- STAGE 2: Backend Builder --- FROM python:3.11-slim AS backend-builder WORKDIR /app # Install only the bare essentials for building Python wheels RUN apt-get update && \ apt-get install -y --no-install-recommends build-essential gcc && \ rm -rf /var/lib/apt/lists/* COPY requirements.txt . # Install to /install to easily copy to final stage RUN pip install --no-cache-dir --prefix=/install -r requirements.txt # --- STAGE 3: Final Runtime --- FROM python:3.11-slim WORKDIR /app # Set non-interactive to avoid prompts ENV DEBIAN_FRONTEND=noninteractive # Minimal runtime system dependencies (if any are ever needed) # Currently none identified from requirements.txt that need system libs on slim RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Copy only the installed Python packages COPY --from=backend-builder /install /usr/local ENV PATH=/usr/local/bin:$PATH # Copy Built Frontend COPY --from=frontend-builder /build/dist /frontend_static # Copy only necessary Backend Source COPY backend ./backend # Environment Variables ENV PYTHONPATH=/app ENV PYTHONUNBUFFERED=1 # Expose Port EXPOSE 8000 # Start FastAPI (Production mode without --reload) CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"]