a81ee50ed8
Deploy to VPS / deploy (push) Has been cancelled
Acts on the audit's NEXT block — operational resilience. Backups (N1): - New `backup` compose service (postgres:16-alpine) runs scripts/backup-loop.sh: immediate pg_dump on start, then nightly, gzip, 14-day rotation into ./backups on the host. Configurable via BACKUP_RETENTION_DAYS / BACKUP_INTERVAL_SECONDS. (Offsite copy is the documented next step.) Resource limits + healthchecks (N2): - deploy.resources.limits.memory on postgres (2g), app (1500m), nginx (256m), backup (256m) so no container can starve the others (the Nginx outage was a reminder). - Nginx now has a healthcheck hitting a new self-served `/nginx-health` endpoint on the default_server (no upstream dependency). Chat resilience (N3): - buildSystemPrompt() wraps its 4 Prisma queries in try/catch with safe defaults — if Postgres is down the assistant degrades instead of 500-ing. - Result is cached for 60s (only on healthy builds) so we don't run 4 queries per message; CMS edits still appear within the TTL. - POST fails fast with 503 if OPENAI_API_KEY is missing (instead of breaking mid-stream after headers are sent). - streamText gets an onError handler that logs + persists an `error` AiEvent. Idempotent submissions (N4): - consultation/route.ts and operations.ts now wrap the email-tracking UPDATE in try/catch — the lead/signal is already saved, so a telemetry hiccup can't 500 the request and trigger a duplicate retry. operations.ts also returns emailError. Performance (N5): - Index GlobalNode(application, isActive) — backs the case-study join on every application page. Migration 20260609130000_index_globalnode_application. Verified: next build compiles (Docker parity, SESSION_SECRET unset), TypeScript clean, prisma schema valid, golden tests 17/17, `docker compose config` valid. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
174 lines
5.4 KiB
YAML
174 lines
5.4 KiB
YAML
# ═══════════════════════════════════════════════════════════════
|
|
# FLUX SRL — Docker Compose (Production)
|
|
# Services: PostgreSQL 16 + Next.js App + Nginx
|
|
# ═══════════════════════════════════════════════════════════════
|
|
|
|
services:
|
|
|
|
# ── PostgreSQL Database ──
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
restart: always
|
|
environment:
|
|
POSTGRES_USER: ${DB_USER}
|
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
POSTGRES_DB: ${DB_NAME}
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
networks:
|
|
- flux-net
|
|
# Resource caps so no single container can starve the others (the Nginx
|
|
# outage earlier was a reminder). VPS has ~11 GB; these leave headroom.
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
memory: 2g
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 5
|
|
command:
|
|
- postgres
|
|
- -c
|
|
- shared_buffers=256MB
|
|
- -c
|
|
- effective_cache_size=1GB
|
|
- -c
|
|
- work_mem=16MB
|
|
- -c
|
|
- maintenance_work_mem=128MB
|
|
- -c
|
|
- max_connections=50
|
|
- -c
|
|
- random_page_cost=1.1
|
|
|
|
# ── Next.js Application ──
|
|
app:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
args:
|
|
# NEXT_PUBLIC_* are inlined into the client bundle at build time.
|
|
# Sourced from .env on the host; the fallback is the FLUX GA4 ID so
|
|
# analytics works out of the box even if .env doesn't override it.
|
|
NEXT_PUBLIC_GA_ID: ${NEXT_PUBLIC_GA_ID:-G-KQ1JRV3KN7}
|
|
NEXT_PUBLIC_GSC_VERIFICATION: ${NEXT_PUBLIC_GSC_VERIFICATION:-}
|
|
restart: always
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
environment:
|
|
DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}?schema=public
|
|
OPENAI_API_KEY: ${OPENAI_API_KEY}
|
|
SESSION_SECRET: ${SESSION_SECRET}
|
|
NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL}
|
|
SMTP_HOST: ${SMTP_HOST}
|
|
SMTP_PORT: ${SMTP_PORT}
|
|
SMTP_USER: ${SMTP_USER}
|
|
SMTP_PASS: ${SMTP_PASS}
|
|
SMTP_FROM: ${SMTP_FROM}
|
|
SMTP_SECURE: ${SMTP_SECURE}
|
|
NODE_ENV: production
|
|
# Optional: REDIS_URL enables multi-instance rate limiting. Leave unset
|
|
# for the current single-container deploy — the in-memory store is used.
|
|
REDIS_URL: ${REDIS_URL:-}
|
|
REDIS_TOKEN: ${REDIS_TOKEN:-}
|
|
volumes:
|
|
- ./public/footage:/app/public/footage
|
|
- ./public/applications:/app/public/applications
|
|
- ./public/cases:/app/public/cases
|
|
- ./public/news:/app/public/news
|
|
- ./public/parts:/app/public/parts
|
|
- ./public/operations-inbox:/app/public/operations-inbox
|
|
- ./public/branding:/app/public/branding
|
|
- ./public/team:/app/public/team
|
|
networks:
|
|
- flux-net
|
|
expose:
|
|
- "3000"
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
memory: 1500m
|
|
healthcheck:
|
|
test:
|
|
- CMD-SHELL
|
|
- "node -e \"fetch('http://localhost:3000/api/health').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))\""
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
# ── Nginx Reverse Proxy ──
|
|
nginx:
|
|
image: nginx:alpine
|
|
restart: always
|
|
ports:
|
|
- "80:80"
|
|
- "443:443"
|
|
volumes:
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
- ./nginx/conf.d:/etc/nginx/conf.d:ro
|
|
- ./certbot/conf:/etc/letsencrypt:ro
|
|
- ./certbot/www:/var/www/certbot:ro
|
|
- ./public/cases:/srv/cases:ro
|
|
- ./public/applications:/srv/applications:ro
|
|
- ./public/news:/srv/news:ro
|
|
- ./public/parts:/srv/parts:ro
|
|
- ./public/footage:/srv/footage:ro
|
|
- ./public/operations-inbox:/srv/operations-inbox:ro
|
|
- ./public/branding:/srv/branding:ro
|
|
- ./public/team:/srv/team:ro
|
|
depends_on:
|
|
- app
|
|
networks:
|
|
- flux-net
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
memory: 256m
|
|
healthcheck:
|
|
# Nginx self-health (served directly by the default_server, no upstream).
|
|
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1/nginx-health || exit 1"]
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 3
|
|
start_period: 10s
|
|
|
|
# ── Automated Postgres backups ──
|
|
# Nightly pg_dump -> gzip into ./backups on the host, 14-day rotation.
|
|
# NOTE: this is LOCAL to the VPS. Offsite copy (S3/rsync) is the recommended
|
|
# next step once the client provides storage credentials.
|
|
backup:
|
|
image: postgres:16-alpine
|
|
restart: always
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
environment:
|
|
DB_USER: ${DB_USER}
|
|
DB_PASSWORD: ${DB_PASSWORD}
|
|
DB_NAME: ${DB_NAME}
|
|
BACKUP_DIR: /backups
|
|
RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-14}
|
|
BACKUP_INTERVAL_SECONDS: ${BACKUP_INTERVAL_SECONDS:-86400}
|
|
volumes:
|
|
- ./backups:/backups
|
|
- ./scripts/db-backup.sh:/usr/local/bin/db-backup.sh:ro
|
|
- ./scripts/backup-loop.sh:/usr/local/bin/backup-loop.sh:ro
|
|
entrypoint: ["/bin/sh", "/usr/local/bin/backup-loop.sh"]
|
|
networks:
|
|
- flux-net
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
memory: 256m
|
|
|
|
volumes:
|
|
pgdata:
|
|
|
|
networks:
|
|
flux-net:
|
|
driver: bridge
|