| # Stage 1: Build the frontend | |
| FROM node:20 as frontend-builder | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm install | |
| COPY frontend/ ./ | |
| RUN npm run build | |
| # Stage 2: Build the backend and serve everything | |
| FROM python:3.11-slim | |
| WORKDIR /app | |
| # Copy backend code | |
| COPY backend/ ./backend | |
| # Corrected: Copy built frontend assets to backend/static (where main.py expects them) | |
| COPY --from=frontend-builder /app/frontend/dist ./backend/static | |
| # Install backend dependencies | |
| # Install uv | |
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | |
| # Install backend dependencies using uv into a virtual environment | |
| # We install from the /app/backend directory where pyproject.toml is located | |
| WORKDIR /app/backend | |
| RUN uv venv /app/.venv | |
| RUN uv pip install . | |
| # Reset workdir | |
| WORKDIR /app | |
| # Enable venv | |
| ENV VIRTUAL_ENV=/app/.venv | |
| ENV PATH="/app/.venv/bin:$PATH" | |
| # Environment variables | |
| ENV PORT=7860 | |
| ENV FRONTEND_URL="" | |
| ENV PYTHONPATH="/app/backend" | |
| # Expose the port | |
| EXPOSE 7860 | |
| # Command to run the application | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port $PORT"] | |