feat(infra): PostgreSQL in the compose stacks, automatic pre-deploy backups (MITHOME-136)

- staging/prod: postgres:16-alpine per the llmdev Docker spec (healthcheck,
  log and memory limits, no host port); the app builds DATABASE_URI from
  POSTGRES_PASSWORD and waits for a healthy database; MongoDB kept for one
  release (rollback path, transfer source)
- dev: PostgreSQL replaces MongoDB and Mongo Express (host port 5433, checked
  and registered); integration test rewritten with pg
- deploy.sh: pg_dump (and, during the switch, mongodump) before the build
- pg/@types/pg pinned to the adapter's 8.20.0 (one copy, no type clash)
- docs: CLAUDE.md, architecture/testing steering, deploy workflow, DOCKER.md;
  staging switch runbook in the design

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 22:35:56 +02:00
co-authored by Claude Opus 5.5
parent a68fb94b61
commit 0ec5714676
17 changed files with 263 additions and 183 deletions
+48 -6
View File
@@ -14,10 +14,11 @@ services:
- "127.0.0.1:8081:3000" # Belső port — csak nginx-en keresztül elérhető
environment:
- NODE_ENV=production
# No fallback for MONGODB_URI: with root auth enabled on the Mongo container an
# unauthenticated default URI would silently break the app — fail loudly instead.
- MONGODB_URI=${MONGODB_URI}
- MONGODB_DB=${MONGODB_DB:-mozdit}
# MITHOME-136: PostgreSQL (the site's own database on the shared server).
# Built from POSTGRES_PASSWORD so the secret lives in one place; no
# fallback — a missing password must fail the deploy loudly. Use a
# URL-safe password (e.g. `openssl rand -hex 32`).
- DATABASE_URI=postgresql://${POSTGRES_USER:-mozdit_web}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}@postgres:5432/mozdit_web
# No fallback either (MITHOME-97): Payload refuses to start without a real
# secret ("missing secret key"), which is exactly what we want here.
- PAYLOAD_SECRET=${PAYLOAD_SECRET}
@@ -32,7 +33,14 @@ services:
# korábban feltöltött logókat/képeket (MITHOME-97).
- media_data_staging:/app/media
depends_on:
- mongodb
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3000/api/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks:
- mozdit-network-staging
restart: always
@@ -42,7 +50,39 @@ services:
max-size: "10m"
max-file: "3"
# MongoDB Database (külön a prod-tól)
# PostgreSQL (MITHOME-136) — llmdev Docker spec: healthcheck, log limit,
# memory limit, no host port (the app reaches it on the project network).
postgres:
image: postgres:16-alpine
container_name: mozdit-postgres-staging
environment:
- POSTGRES_DB=mozdit_web
- POSTGRES_USER=${POSTGRES_USER:-mozdit_web}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
volumes:
- postgres_data_staging:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-mozdit_web} -d mozdit_web"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
deploy:
resources:
limits:
memory: 1G
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "3"
networks:
- mozdit-network-staging
restart: unless-stopped
# MongoDB — MITHOME-136: no longer used by the app. Kept for one release as
# the rollback path and the source of the one-off content transfer
# (proto/scripts/transfer-content.ts); remove afterwards (tasks 4.3).
mongodb:
image: mongo:7.0
container_name: mozdit-mongodb-staging
@@ -60,6 +100,8 @@ services:
restart: always
volumes:
postgres_data_staging:
driver: local
mongodb_data_staging:
driver: local
media_data_staging: