# ============================================ # Stage 1: Build Frontend # ============================================ FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend # Copy package files COPY frontend/package*.json ./ # Install dependencies RUN npm ci # Copy frontend source COPY frontend/ ./ # Set API base URL to same origin (relative path) ENV VITE_API_BASE_URL="" # Build frontend RUN npm run build # ============================================ # Stage 2: Python Backend + Serve Frontend # ============================================ FROM python:3.12-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ && rm -rf /var/lib/apt/lists/* # Copy backend source code and pyproject.toml COPY backend/pyproject.toml ./ COPY backend/src/ ./src/ # Install Python dependencies RUN pip install --no-cache-dir . # Copy built frontend to serve as static files COPY --from=frontend-builder /app/frontend/dist ./static # Set working directory to src for imports WORKDIR /app/src # Create notes directory with proper permissions for HF Spaces (runs as non-root user) RUN mkdir -p /app/src/notes && chmod 777 /app/src/notes # Expose port 7860 (Hugging Face Spaces default) EXPOSE 7860 # Environment variables (will be overridden by HF Secrets) ENV HOST=0.0.0.0 ENV PORT=7860 ENV CORS_ORIGINS="*" # Use absolute path for notes workspace ENV NOTES_WORKSPACE="/app/src/notes" # Start the application (ensure notes dir exists at runtime) CMD mkdir -p /app/src/notes && python -m uvicorn main:app --host 0.0.0.0 --port 7860