| # --------- 1) Build frontend (React + Vite) ---------- | |
| FROM node:18 AS frontend-builder | |
| WORKDIR /frontend | |
| # Install dependencies for frontend | |
| COPY frontend/package.json frontend/package-lock.json* ./ | |
| RUN npm install | |
| # Copy the rest of the frontend and build | |
| COPY frontend . | |
| RUN npm run build | |
| # NOTE: Your Vite config is writing output to ../app/frontend_dist | |
| # So in this builder image, the built files are at: /app/frontend_dist | |
| # --------- 2) Backend (FastAPI + Python) ---------- | |
| FROM python:3.11-slim | |
| WORKDIR /app | |
| # Install backend dependencies | |
| COPY app/requirements.txt /app/requirements.txt | |
| RUN pip install --no-cache-dir -r /app/requirements.txt | |
| # Copy backend code | |
| COPY app /app | |
| # Copy built frontend from builder image into this final image | |
| # IMPORTANT: we copy from /app/frontend_dist (not /frontend/dist) | |
| COPY --from=frontend-builder /app/frontend_dist /app/frontend_dist | |
| EXPOSE 7860 | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |