From 9e2961d6484e3461b75cb0e5ea595f060abe3d02 Mon Sep 17 00:00:00 2001 From: John Lightner Date: Tue, 7 Apr 2026 01:44:52 -0500 Subject: [PATCH] MAESTRO: Create multi-stage Dockerfile, nginx.conf, and frontend/backend scaffolding Three-stage Dockerfile: frontend-build (Node 20), api (Python 3.12 + uvicorn), web (nginx 1.27). nginx.conf proxies /api and /ws to the API service with WebSocket upgrade support. Includes backend/requirements.txt with all Python deps, frontend scaffolding (Vite + React + TypeScript + Tailwind), and placeholder alembic files for Docker COPY compatibility. --- Auto Run Docs/01-scaffold.md | 3 +- alembic.ini | 4 +++ alembic/env.py | 1 + backend/requirements.txt | 16 +++++++++ docker/Dockerfile | 63 ++++++++++++++++++++++++++++++++++++ docker/nginx.conf | 44 +++++++++++++++++++++++++ frontend/index.html | 12 +++++++ frontend/package.json | 26 +++++++++++++++ frontend/postcss.config.js | 6 ++++ frontend/src/App.tsx | 5 +++ frontend/src/index.css | 3 ++ frontend/src/main.tsx | 10 ++++++ frontend/src/vite-env.d.ts | 1 + frontend/tailwind.config.js | 8 +++++ frontend/tsconfig.json | 21 ++++++++++++ frontend/vite.config.ts | 20 ++++++++++++ 16 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 alembic.ini create mode 100644 alembic/env.py create mode 100644 backend/requirements.txt create mode 100644 docker/Dockerfile create mode 100644 docker/nginx.conf create mode 100644 frontend/index.html create mode 100644 frontend/package.json create mode 100644 frontend/postcss.config.js create mode 100644 frontend/src/App.tsx create mode 100644 frontend/src/index.css create mode 100644 frontend/src/main.tsx create mode 100644 frontend/src/vite-env.d.ts create mode 100644 frontend/tailwind.config.js create mode 100644 frontend/tsconfig.json create mode 100644 frontend/vite.config.ts diff --git a/Auto Run Docs/01-scaffold.md b/Auto Run Docs/01-scaffold.md index ecd9d6d..cbb5eab 100644 --- a/Auto Run Docs/01-scaffold.md +++ b/Auto Run Docs/01-scaffold.md @@ -14,7 +14,8 @@ Set up the PromptLooper repository, Docker infrastructure, and basic project ske - [x] Create docker-compose.yml following XPLTD conventions: project name xpltd_promptlooper, network promptlooper (172.33.0.0/24), PostgreSQL on port 5434, Redis, API service, worker service, and web service on port 8400. Use bind mounts under /vmPool/r/services/promptlooper_* for persistent data. Model this after Chrysopedia's docker-compose.yml patterns. > Updated existing docker-compose.yml: fixed DATABASE_URL to use standard postgresql:// scheme (not asyncpg), hardcoded DB credentials instead of requiring .env vars, added API_KEY pass-through, added working_dir for worker service, made JWT_SECRET optional with dev default. All 5 services defined: db (:5434), redis, api (MCP :8401), worker (Celery), web (:8400). Bind mounts under /vmPool/r/services/promptlooper_*. Health checks on db and redis with dependency conditions. -- [ ] Create the multi-stage Dockerfile in docker/ that builds both backend and frontend into a single image. Stage 1: Node build for frontend (npm ci && npm run build). Stage 2: Python runtime with uvicorn, copying the built frontend assets. Include nginx.conf that serves the frontend and proxies /api and /ws to uvicorn. The image should work standalone with SQLite when no DATABASE_URL is provided. +- [x] Create the multi-stage Dockerfile in docker/ that builds both backend and frontend into a single image. Stage 1: Node build for frontend (npm ci && npm run build). Stage 2: Python runtime with uvicorn, copying the built frontend assets. Include nginx.conf that serves the frontend and proxies /api and /ws to uvicorn. The image should work standalone with SQLite when no DATABASE_URL is provided. + > Created 3-stage Dockerfile: (1) frontend-build with Node 20 Alpine, (2) api stage with Python 3.12-slim + uvicorn + static assets for single-container mode, (3) web stage with nginx 1.27 Alpine for production compose. nginx.conf proxies /api/ and /health to the API, upgrades /ws/ connections for WebSocket. Also created: backend/requirements.txt, frontend scaffolding (package.json, vite.config.ts, tsconfig.json, index.html, App.tsx, Tailwind config), and placeholder alembic.ini/env.py for Dockerfile COPY. - [ ] Create backend/config.py using Pydantic Settings. Define all configuration from the Environment Variables table. Implement the SQLite fallback logic: when DATABASE_URL is not set, construct a SQLite URL pointing to DATA_DIR/promptlooper.db. When REDIS_URL is not set, set a flag for in-process mode. diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 0000000..9f7e4dc --- /dev/null +++ b/alembic.ini @@ -0,0 +1,4 @@ +# Alembic Configuration (placeholder — will be configured in the Alembic setup task) +[alembic] +script_location = alembic +sqlalchemy.url = sqlite:///data/promptlooper.db diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 0000000..8b73b3a --- /dev/null +++ b/alembic/env.py @@ -0,0 +1 @@ +# Placeholder — will be implemented in the Alembic setup task diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..3e9f625 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,16 @@ +# PromptLooper — Backend Dependencies +fastapi>=0.115,<1.0 +uvicorn[standard]>=0.32,<1.0 +sqlalchemy>=2.0,<3.0 +alembic>=1.14,<2.0 +pydantic>=2.0,<3.0 +pydantic-settings>=2.0,<3.0 +python-jose[cryptography]>=3.3,<4.0 +passlib[bcrypt]>=1.7,<2.0 +celery>=5.4,<6.0 +redis>=5.0,<6.0 +httpx>=0.27,<1.0 +websockets>=13.0,<14.0 +psycopg2-binary>=2.9,<3.0 +aiosqlite>=0.20,<1.0 +python-multipart>=0.0.9 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..98bab7a --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,63 @@ +# ============================================================================= +# Stage 1: Frontend build +# ============================================================================= +FROM node:20-alpine AS frontend-build + +WORKDIR /build + +COPY frontend/package.json frontend/package-lock.json* ./ +RUN npm ci || npm install + +COPY frontend/ ./ +RUN npm run build + +# ============================================================================= +# Stage 2: Python API runtime +# ============================================================================= +FROM python:3.12-slim AS api + +WORKDIR /app + +# Install system dependencies for psycopg2 and general use +RUN apt-get update && \ + apt-get install -y --no-install-recommends gcc libpq-dev curl && \ + rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +COPY backend/requirements.txt /app/backend/requirements.txt +RUN pip install --no-cache-dir -r /app/backend/requirements.txt + +# Copy backend source +COPY backend/ /app/backend/ +COPY alembic/ /app/alembic/ +COPY alembic.ini /app/alembic.ini + +# Copy frontend build for single-container mode +COPY --from=frontend-build /build/dist /app/static + +# Create data directory for SQLite mode +RUN mkdir -p /data + +ENV PYTHONPATH=/app/backend +ENV DATA_DIR=/data + +EXPOSE 8000 8401 + +# Default: run the API server +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--app-dir", "/app/backend"] + +# ============================================================================= +# Stage 3: Nginx frontend (production compose) +# ============================================================================= +FROM nginx:1.27-alpine AS web + +# Remove default config +RUN rm /etc/nginx/conf.d/default.conf + +# Copy custom nginx config +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf + +# Copy built frontend assets +COPY --from=frontend-build /build/dist /usr/share/nginx/html + +EXPOSE 80 diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..3ea7079 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,44 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Frontend static assets + location / { + try_files $uri $uri/ /index.html; + } + + # API proxy + location /api/ { + proxy_pass http://promptlooper-api:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Health endpoint proxy + location /health { + proxy_pass http://promptlooper-api:8000; + proxy_set_header Host $host; + } + + # WebSocket proxy + location /ws/ { + proxy_pass http://promptlooper-api:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_read_timeout 86400; + } + + # Gzip compression + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; + gzip_min_length 256; +} diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..4e22599 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,12 @@ + + + + + + PromptLooper + + +
+ + + diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..4cf7587 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,26 @@ +{ + "name": "promptlooper-frontend", + "private": true, + "version": "0.1.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-router-dom": "^6.28.0" + }, + "devDependencies": { + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "@vitejs/plugin-react": "^4.3.4", + "autoprefixer": "^10.4.20", + "postcss": "^8.4.49", + "tailwindcss": "^3.4.15", + "typescript": "^5.6.3", + "vite": "^6.0.0" + } +} diff --git a/frontend/postcss.config.js b/frontend/postcss.config.js new file mode 100644 index 0000000..2aa7205 --- /dev/null +++ b/frontend/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx new file mode 100644 index 0000000..19c4ac2 --- /dev/null +++ b/frontend/src/App.tsx @@ -0,0 +1,5 @@ +function App() { + return
PromptLooper
; +} + +export default App; diff --git a/frontend/src/index.css b/frontend/src/index.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/frontend/src/index.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx new file mode 100644 index 0000000..27481e0 --- /dev/null +++ b/frontend/src/main.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App"; +import "./index.css"; + +ReactDOM.createRoot(document.getElementById("root")!).render( + + + , +); diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/frontend/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js new file mode 100644 index 0000000..614c86b --- /dev/null +++ b/frontend/tailwind.config.js @@ -0,0 +1,8 @@ +/** @type {import('tailwindcss').Config} */ +export default { + content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..20fb0a0 --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["src"] +} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts new file mode 100644 index 0000000..60992cd --- /dev/null +++ b/frontend/vite.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; + +export default defineConfig({ + plugins: [react()], + build: { + outDir: "dist", + }, + server: { + port: 5173, + proxy: { + "/api": "http://localhost:8000", + "/ws": { + target: "ws://localhost:8000", + ws: true, + }, + "/health": "http://localhost:8000", + }, + }, +});