| # Use a multi-stage build to optimize the image | |
| # Stage 1: Build the React frontend | |
| FROM node:18-alpine AS frontend-builder | |
| WORKDIR /app | |
| COPY frontend/package.json frontend/package-lock.json ./ | |
| RUN npm install | |
| COPY frontend/ . | |
| RUN npm run build | |
| # Stage 2: Set up the FastAPI backend | |
| FROM python:3.9-slim | |
| WORKDIR /app | |
| COPY backend/requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| COPY backend/ . | |
| COPY --from=frontend-builder /app/dist/ ./frontend/dist/ | |
| # Expose port | |
| EXPOSE 7860 | |
| # Environment variables | |
| ENV GEMINI_API_KEY=${GEMINI_API_KEY} | |
| # Run the app | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |