# --- STAGE 1: Build Frontend --- # This stage uses a more robust, standard pattern for building Node.js apps. # It creates a dedicated 'frontend' directory inside the container to avoid potential # file conflicts in the root directory. FROM node:20-slim AS frontend-builder WORKDIR /app/frontend # 1. Copy ONLY package files first (better caching, no host node_modules contamination) COPY frontend/package.json ./ # 2. Clean install dependencies # We ignore the local package-lock.json to force a resolution compatible with the container environment RUN npm install --no-audit --no-fund && \ npx update-browserslist-db@latest # 3. Copy source code AFTER install COPY frontend/ ./ # 4. Build 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) 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 from the new, correct location COPY --from=frontend-builder /app/frontend/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"]