Spaces:
Sleeping
Sleeping
| # Multi-stage build for AI Newsletter Generator | |
| # Optimized for Hugging Face Spaces deployment | |
| # Stage 1: Build frontend | |
| FROM node:20-slim as frontend-builder | |
| # Install pnpm | |
| RUN npm install -g pnpm | |
| # Set working directory | |
| WORKDIR /app/frontend | |
| # Copy frontend package files and pnpm configuration | |
| COPY frontend/package.json frontend/pnpm-lock.yaml frontend/.pnpmfile.cjs ./ | |
| # Install frontend dependencies | |
| RUN pnpm install --frozen-lockfile | |
| # Copy frontend source | |
| COPY frontend/ . | |
| # Build frontend for production | |
| RUN pnpm build | |
| # Stage 2: Python backend with built frontend | |
| FROM python:3.12-slim | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PORT=7860 | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install uv for fast Python package management | |
| RUN pip install uv | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy Python configuration | |
| COPY pyproject.toml uv.lock ./ | |
| # Install Python dependencies | |
| RUN uv sync --no-dev | |
| # Copy backend source | |
| COPY backend/ ./backend/ | |
| # Copy built frontend from previous stage | |
| COPY --from=frontend-builder /app/frontend/dist ./frontend/dist | |
| # Create non-root user for security | |
| RUN useradd --create-home --shell /bin/bash app | |
| RUN chown -R app:app /app | |
| USER app | |
| # Expose port (Hugging Face Spaces uses 7860) | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/api/health || exit 1 | |
| # Start command for Hugging Face Spaces | |
| CMD ["uv", "run", "uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"] | |