- FastAPI app with SPAStaticFiles catch-all (root_path NOT in constructor)
- config.py with DATA_PATH, PROMPTS_PATH, OUTPUTS_PATH, CAMPAIGNS_PATH, CONFIG_PATH
- Startup lifespan creates data directories automatically
- Health endpoint: GET /api/health -> {"status": "ok"}
- Dockerfile multi-stage: node:22-slim builds React, python:3.12-slim serves API+SPA
- --root-path /postgenerator set in Uvicorn CMD only (avoids Pitfall #4)
- docker-compose.yml: lab-postgenerator-app, proxy_net, named volume for data persistence
- requirements.txt with pinned versions: fastapi[standard]==0.135.1, anthropic==0.84.0
42 lines
1.2 KiB
Docker
42 lines
1.2 KiB
Docker
# ============================================================
|
|
# Stage 1: Build React SPA
|
|
# ============================================================
|
|
FROM node:22-slim AS frontend-builder
|
|
|
|
WORKDIR /app/frontend
|
|
|
|
# Install dependencies first (layer cache optimization)
|
|
COPY frontend/package*.json ./
|
|
RUN npm ci
|
|
|
|
# Copy source and build
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
# ============================================================
|
|
# Stage 2: Python runtime (serves API + built SPA)
|
|
# ============================================================
|
|
FROM python:3.12-slim AS runtime
|
|
|
|
WORKDIR /app
|
|
|
|
# Install Python dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy backend source
|
|
COPY backend/ ./backend/
|
|
|
|
# Copy built React SPA from frontend-builder stage
|
|
COPY --from=frontend-builder /app/frontend/dist ./static
|
|
|
|
# Create data directory structure
|
|
RUN mkdir -p /app/data/prompts /app/data/outputs /app/data/campaigns /app/data/config
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# CRITICAL: --root-path /postgenerator is set HERE (Uvicorn), NOT in FastAPI() constructor
|
|
# This avoids the double-path bug (Pitfall #4)
|
|
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000", "--root-path", "/postgenerator"]
|