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 @@ + + +
+ + +