# ======================= # 1️⃣ Frontend build stage # ======================= FROM node:22-slim AS frontend-builder # Install pnpm globally RUN corepack enable && corepack prepare pnpm@latest --activate # Set working directory WORKDIR /app/frontend # Copy package files first for caching COPY frontend/pnpm-lock.yaml frontend/package.json ./ # Install dependencies (prod only for frontend) RUN pnpm install --frozen-lockfile # Copy the rest of the frontend source COPY frontend/ ./ # Build frontend ENV VITE_APP_ENV=production RUN pnpm build # ======================= # 2️⃣ Backend build stage # ======================= FROM python:3.12-slim AS backend-builder # Install uv (fast Python package installer) RUN pip install --no-cache-dir uv # Set working directory WORKDIR /app # Copy backend requirements and install (no dev deps) COPY backend/pyproject.toml backend/uv.lock ./backend/ RUN cd backend && uv pip install --no-cache-dir --system . # Copy backend source COPY backend/ ./backend/ # Copy built frontend from stage 1 COPY --from=frontend-builder /app/frontend/dist ./frontend/dist # ======================= # 3️⃣ Production runtime # ======================= FROM python:3.12-slim # Create non-root user RUN useradd -m appuser WORKDIR /app # Copy installed packages and app COPY --from=backend-builder /usr/local /usr/local COPY --from=backend-builder /app /app # Set frontend path for FastAPI ENV FRONTEND_PATH=/app/frontend/dist # Switch to non-root user USER appuser # Expose port (adjust if needed) EXPOSE 8000 # Run FastAPI via uvicorn CMD ["uvicorn", "backend.src.app:app", "--host", "0.0.0.0", "--port", "8000"]