Deployment Recipe: Generic Docker / VPS (Canonical Portable Baseline)
Support Tier: Tier 1 — Officially Tested & Supported Adapter
Target Platform: Any Virtual Private Server (VPS) / Virtual Machine (e.g., Ubuntu, Debian, AWS EC2, DigitalOcean Droplet, Hetzner, Linode) or bare-metal host running Docker & Docker Compose.
Overview
The generic Docker/VPS deployment path serves as the canonical portable baseline for the application. It packages the application into a self-contained, multi-platform Docker container (linux/amd64 and linux/arm64) with /opt/prisma-cli installed outside /app and /app/scripts/generate-password-hash.mjs copied for scrypt hash generation, orchestrated by docker-compose.yml across three services—db (postgres:15-alpine with shm_size: "256mb" and no-new-privileges:true), a dedicated one-shot migration job (./node_modules/.bin/prisma migrate deploy reusing wedding-website:latest via pull_policy: never), and app (the sole build: owner, running with HOSTNAME="0.0.0.0", RUN_MIGRATIONS="false", init: true, stop_grace_period: 15s, read_only: true, cap_drop: [ALL], no-new-privileges:true, tmpfs mounts at /tmp and /app/.next/cache, persistent uploads_data:/app/public/uploads volume storage, and a built-in /api/live container healthcheck)—with bounded json-file log rotation (max-size: "10m", max-file: "3"), pids_limit, mem_limit, and explicit stop_grace_period across every service. Zero-downtime updates layer docker-compose.rollout.yml (app-standby on 127.0.0.1:${STANDBY_PORT:-3001}:3000) via ./scripts/rollout-vps.sh behind a dual-upstream host reverse proxy. Standalone docker run deployments without Compose can opt into offline entrypoint migrations by setting RUN_MIGRATIONS=true or RUN_MIGRATIONS=1 in docker-entrypoint.sh (and passing --init --stop-timeout 15). When running host CLI scripts or building from source outside Docker, install Node.js v22.x LTS (>=22.22.1 <23.0.0 across engines.node and devEngines.runtime) and npm ^10.9.0 (enforced via engines and devEngines in package.json).
1. Database Provisioning & Connection
Provisioning
You can run PostgreSQL either alongside the application via Docker Compose or connect to an external managed database (such as AWS RDS, DigitalOcean Managed Database, Neon, or Supabase).
- Docker Compose Co-location: Uses the official
postgres:15-alpineimage (dbservice, gated viaprofiles: ["${CONTAINER_DATABASE_URL:+bundled-db}"]) with persistent volume mounting (db_data:/var/lib/postgresql/data), loopback host port binding (127.0.0.1:${DB_PORT:-5432}:5432), and apg_isreadyhealthcheck.migration,app(docker-compose.yml), andapp-standby(docker-compose.rollout.yml) construct containerDATABASE_URLidentically fromDB_USER, mandatoryDB_PASSWORD, andDB_NAMEvia${CONTAINER_DATABASE_URL:-postgres://${DB_USER:-wedding}:${DB_PASSWORD:?DB_PASSWORD is required}@db:5432/${DB_NAME:-wedding}?sslmode=disable}and scope containerPOSTGRES_URL_NON_POOLINGvia${CONTAINER_POSTGRES_URL_NON_POOLING:-}whenever explicit container overrides are not provided in.env(preventing host@localhost:5432DATABASE_URLandPOSTGRES_URL_NON_POOLINGsettings from leaking into containers). - External PostgreSQL: Ensure PostgreSQL v15+ is running and accessible over port
5432with SSL/TLS enabled if remote. SetCONTAINER_DATABASE_URL(and optionalCONTAINER_POSTGRES_URL_NON_POOLINGwhenCONTAINER_DATABASE_URLconnects via PgBouncer) directly in.envwhen orchestrating withdocker-compose.yml(migration,app, andapp-standbyhonor both container overrides automatically, whiledocker-compose.ymland./scripts/rollout-vps.shautomatically skip starting the bundleddbcontainer and bypass theDB_PASSWORDrequirement), or passDATABASE_URL(and optionalPOSTGRES_URL_NON_POOLING) directly when running standalonedocker run.
Connection String Format
Configure DATABASE_URL as an unquoted standard PostgreSQL URI (datasource.url via resolvePrismaDatasourceUrl in prisma.config.ts, used by both the Next.js runtime and Prisma CLI; leave values unquoted in .env so standalone docker run --env-file .env does not inject literal quote characters):
DATABASE_URL=postgresql://wedding_user:secure_password@db_host:5432/wedding_db?schema=public&sslmode=requireWhen DATABASE_URL (or CONTAINER_DATABASE_URL under Docker Compose) connects through a transaction-mode pooler such as PgBouncer, configure a direct unpooled URI targeting the same database and schema in POSTGRES_URL_NON_POOLING (for standalone docker run) or CONTAINER_POSTGRES_URL_NON_POOLING (for Docker Compose) so resolvePrismaDatasourceUrl in prisma.config.ts promotes the direct endpoint during prisma migrate deploy while keeping shadowDatabaseUrl undefined:
POSTGRES_URL_NON_POOLING=postgresql://wedding_user:secure_password@db_host:5432/wedding_db?schema=public&sslmode=require
CONTAINER_POSTGRES_URL_NON_POOLING=postgresql://wedding_user:secure_password@db_host:5432/wedding_db?schema=public&sslmode=require2. Docker & VPS Secrets and Compose Configuration
For the complete environment variable matrix, defaults, and persisted entity rules, refer to the Application Runtime Contract and .env.example.
.env Interpolation & Secret Requirements in docker-compose.yml
docker-compose.yml substitutes environment variables directly from .env without hardcoding production fallback secrets:
- Mandatory Operator Secrets (
:?required):DB_PASSWORD,ADMIN_PASSWORD(scrypt:[16-byte saltBase64]:[64-byte keyBase64]generated vianode scripts/generate-password-hash.mjs "password"),GUEST_PASSCODE, andGUEST_SESSION_SECRET(32+ characters, distinct fromGUEST_PASSCODE) have no default values indocker-compose.yml. Runningdocker compose configordocker compose up -dwithout setting them fails immediately. In addition,src/env.tsrejects non-64-byte scrypt hashes and repository placeholder/E2E fallback secrets inNODE_ENV=production. - Compose Network, Proxy & Database Interpolation:
DB_USER(wedding),DB_NAME(wedding), andDB_PORT(127.0.0.1:${DB_PORT:-5432}:5432) configure thedbcontainer and fallbackDATABASE_URL;PORT(127.0.0.1:${PORT:-3000}:3000),STANDBY_PORT(127.0.0.1:${STANDBY_PORT:-3001}:3000indocker-compose.rollout.yml), andHOSTNAME(0.0.0.0) configure loopback host port publishing and container network binding;ALLOWED_HOSTSandTRUST_PROXY=1(${TRUST_PROXY:-1}default indocker-compose.ymlanddocker-compose.rollout.yml, or2behind an upstream CDN/load balancer plus host proxy) configure reverse-proxy host validation and client IP forwarding behind Caddy or Nginx. - Scoped Container Runtime, Full 21-Variable Forwarding & 32-Variable
SITE_*Overrides:app(indocker-compose.yml) andapp-standby(indocker-compose.rollout.yml) pinNODE_ENV: productionso host development overrides never leak into production containers, forward all 21 runtime keys fromsrc/env.ts(including optionalS3_*,STRIPE_*,CRON_SECRET,RUN_MIGRATIONS, andPOSTGRES_URL_NON_POOLING— see the Application Runtime Contract) plus all 32 optional Layer 1SITE_*overrides (${SITE_*:-}), and scope containerDATABASE_URL(${CONTAINER_DATABASE_URL:-...}) andPOSTGRES_URL_NON_POOLING(${CONTAINER_POSTGRES_URL_NON_POOLING:-}) identically acrossmigration,app, andapp-standbywithout requiring a manualdocker-compose.override.ymlfile (automated CI smoke tests layer--env-file .env.ci -f docker-compose.yml -f docker-compose.ci.ymlseparately). - Trimmed & Blank-Safe
SITE_*Overrides:src/lib/config.ts(getEnvConfigOverrides) trims leading/trailing whitespace on all 32SITE_*keys and treats empty or whitespace-only values as unset before Zod validation andisSiteInitializedchecks, while still rejecting non-empty malformed overrides (such as invalid coordinates, dates, or hex colors) at startup. OptionalSITE_*keys (plusSTANDBY_PORT=3001for./scripts/rollout-vps.sh) can be set directly in.env:env# Optional standby loopback port for ./scripts/rollout-vps.sh (defaults to 3001) # STANDBY_PORT=3001 # Optional Layer 1 site overrides (blank or commented keys fall back to database AppConfig; see ../runtime-contract.md for all 32 SITE_* keys) SITE_PARTNER1_NAME="Alex" SITE_PARTNER2_NAME="Jordan" SITE_WEDDING_DATE="2027-09-18T17:00:00.000Z" SITE_BASE_URL="https://wedding.mydomain.com" - Single-Owner Provider-Neutral Local BuildKit Caching:
appis the solebuild:owner indocker-compose.yml(migrationandapp-standbysetpull_policy: neveronwedding-website:latest), compiling the image once on bothamd64andarm64hosts using local BuildKit layer and cache mounts (Dockerfile) with zero GitHub Actions (type=gha) cache backend references indocker-compose.ymlordocker-compose.rollout.yml(per-architecture CIcache_fromoverrides live strictly insidedocker-compose.ci.yml). - If any secret in
.envcontains a literal$, escape it as$$for Docker Compose interpolation.
Production Onboarding & E2E_TEST=false
docker-compose.yml defaults E2E_TEST to false (E2E_TEST: ${E2E_TEST:-false}) so fresh VPS deployments render the <SetupWizard /> onboarding flow until couple names and baseUrl are saved (docker-compose.ci.yml isolates E2E_TEST=true strictly to automated CI smoke tests). Keep E2E_TEST=false (or unset) in .env for production deployments—setting E2E_TEST=true also disables NODE_ENV=production blocklists for committed E2E_FALLBACK_* secrets in src/env.ts.
3. Migration Mechanism
Primary Path: Dedicated migration Service in docker-compose.yml
docker-compose.yml decouples schema migrations from application container boot:
dbstartspostgres:15-alpinebound to127.0.0.1:${DB_PORT:-5432}:5432and waits until itspg_isreadyhealthcheck reportsservice_healthy.migrationruns./node_modules/.bin/prisma migrate deployoffline (restart: "no",read_only: true,cap_drop: [ALL],tmpfs: [/tmp]) againstDATABASE_URL(${CONTAINER_DATABASE_URL:-postgres://${DB_USER:-wedding}:${DB_PASSWORD:?DB_PASSWORD is required}@db:5432/${DB_NAME:-wedding}?sslmode=disable}) and optionalPOSTGRES_URL_NON_POOLING(${CONTAINER_POSTGRES_URL_NON_POOLING:-}).appdefaultsRUN_MIGRATIONStofalse(${RUN_MIGRATIONS:-false}), setsNODE_ENV: production, and waits onmigration(condition: service_completed_successfully) before executingnode server.jsbehind/usr/bin/tini.
To run migrations on demand via Docker Compose (when CONTAINER_DATABASE_URL uses an external PgBouncer pooler, setting CONTAINER_POSTGRES_URL_NON_POOLING in .env allows migration to route through prisma.config.ts without extra flags):
docker compose run --rm migrationIf passing an ad-hoc direct DATABASE_URL override on the CLI instead of setting CONTAINER_POSTGRES_URL_NON_POOLING, unset and clear POSTGRES_URL_NON_POOLING so Prisma 7 never sees matching primary and shadow database URLs (P3025):
env -u POSTGRES_URL_NON_POOLING docker compose run --rm \
-e DATABASE_URL="${CONTAINER_POSTGRES_URL_NON_POOLING:-$CONTAINER_DATABASE_URL}" \
-e POSTGRES_URL_NON_POOLING="" \
migrationStandalone Container Path (docker-entrypoint.sh)
When running the image directly via docker run without Docker Compose's migration service, set RUN_MIGRATIONS=true or RUN_MIGRATIONS=1 so docker-entrypoint.sh validates DATABASE_URL, normalizes and preserves non-empty POSTGRES_URL_NON_POOLING (unsetting blank values), and executes ./node_modules/.bin/prisma migrate deploy (symlinked to /usr/local/bin/prisma and backed by /opt/prisma-cli, with npm update checks disabled) prior to node server.js.
4. Asset Storage
- Local Disk Storage (Default —
uploads_dataNamed Volume & EphemeraltmpfsCache): Static application files under/appare owned byroot:rootand mountedread_only: trueindocker-compose.yml(cap_drop: [ALL],no-new-privileges:true), with writabletmpfsmemory mounts backing/tmpand/app/.next/cache:uid=1001,gid=1001,mode=0755for Next.js/_next/imageoptimization. Uploaded files are written to/app/public/uploadsand streamed dynamically at/uploads/*in standalone mode (src/app/api/uploads/[...path]/route.ts, withX-Content-Type-Options: nosniff) without needing a container restart. BothDockerfileanddocker-compose.ymlpre-create/app/public/uploadsowned bynextjs:nodejs(UID/GID 1001) and mount the persistentuploads_datanamed volume by default so uploaded photos and branding assets survivedocker compose up -d --build:yamlIf overridingservices: app: volumes: - uploads_data:/app/public/uploads volumes: uploads_data:uploads_datawith a host bind mount (e.g.,./uploads:/app/public/uploadsor-v /var/lib/wedding/uploads:/app/public/uploadsin standalonedocker run), ensure host ownership/permissions allow writes by UID 1001 (chown -R 1001:1001 ./uploads). - S3 / Cloudflare R2 / Google Cloud Storage Object Storage (Recommended for Multi-Instance): Configure all six S3-compatible environment variables as needed (
S3_BUCKET,S3_REGION,S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT, andS3_PUBLIC_URL):- Cloudflare R2: Set
S3_BUCKET,S3_REGION=auto,S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com, andS3_PUBLIC_URL=https://assets.wedding.mydomain.com(an R2 Custom Domain or publichttps://pub-<id>.r2.devURL; private*.r2.cloudflarestorage.comendpoints requireS3_PUBLIC_URL). - Google Cloud Storage (S3 Interoperability): Enable Cloud Storage HMAC keys and set
S3_BUCKET,S3_REGION=us-central1(matching your bucket region),S3_ACCESS_KEY_ID,S3_SECRET_ACCESS_KEY,S3_ENDPOINT=https://storage.googleapis.com, and optionalS3_PUBLIC_URL. - AWS S3: Set
S3_BUCKET,S3_REGION,S3_ACCESS_KEY_ID, andS3_SECRET_ACCESS_KEY(withS3_ENDPOINTomitted andS3_PUBLIC_URLoptional for CloudFront).
- Cloudflare R2: Set
5. Custom Domain & TLS
Use a reverse proxy such as Caddy or Nginx with Let's Encrypt on the host, configured with dual loopback upstreams (127.0.0.1:3000 primary app and 127.0.0.1:3001 standby app-standby) so ./scripts/rollout-vps.sh updates app with zero dropped HTTP requests. Always configure reverse proxies to sanitize and overwrite client IP headers (X-Real-IP and X-Forwarded-For) to prevent attackers from spoofing their IP address to evade rate limiting.
Option A: Caddy (Automatic TLS + Standby Failover)
Create a Caddyfile:
wedding.mydomain.com {
reverse_proxy localhost:3000 localhost:3001 {
lb_policy first
lb_try_duration 5s
lb_try_interval 100ms
fail_duration 5s
# Overwrite/strip untrusted incoming X-Real-IP header with trusted remote client IP
header_up X-Real-IP {remote_host}
}
}Note: lb_policy first sends all normal traffic to primary localhost:3000 and automatically retries/fails over to warm localhost:3001 (app-standby) while app recreates during ./scripts/rollout-vps.sh. Caddy automatically manages X-Forwarded-For by appending the client IP, and header_up X-Real-IP {remote_host} ensures any incoming forged client X-Real-IP header is stripped and overwritten before the request reaches the container.
Option B: Nginx + Certbot (Primary + Backup Upstream Failover)
upstream wedding_backend {
server 127.0.0.1:3000 max_fails=1 fail_timeout=2s;
server 127.0.0.1:3001 backup;
keepalive 16;
}
server {
server_name wedding.mydomain.com;
location / {
proxy_pass http://wedding_backend;
proxy_http_version 1.1;
proxy_next_upstream error timeout http_502 http_503 http_504;
proxy_next_upstream_tries 2;
proxy_connect_timeout 1s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-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;
}
}Note: Marking 127.0.0.1:3001 as backup routes all steady-state requests to primary 127.0.0.1:3000 and transparently retries on 127.0.0.1:3001 (app-standby) via proxy_next_upstream the instant app closes its socket during rollout. Setting proxy_set_header X-Forwarded-Host $host; and proxy_set_header X-Real-IP $remote_addr; explicitly overwrites any client-supplied X-Forwarded-Host or X-Real-IP headers with the ingress host $host and direct connecting IP address $remote_addr. Combined with $proxy_add_x_forwarded_for and TRUST_PROXY=1 (the docker-compose.yml default), the application evaluates only the trusted proxy hop for host validation, canonical origin resolution, and rate limiting while ignoring spoofed forwarded headers whenever TRUST_PROXY=false.
Obtain TLS certificate:
sudo certbot --nginx -d wedding.mydomain.com6. Build & Deploy Commands
Initial Build & Start
# Clone repository on host
git clone https://github.com/fderuiter/wedding_website.git /opt/wedding_website
cd /opt/wedding_website
# Build the container image and generate a 16-byte salt / 64-byte scrypt hash inside Docker (no host Node.js required)
docker build -t wedding-website:latest .
ADMIN_HASH=$(docker run --rm wedding-website:latest node scripts/generate-password-hash.mjs "replace-with-strong-admin-password")
GUEST_SECRET=$(openssl rand -hex 32)
DB_SECRET=$(openssl rand -hex 24)
# Configure required secrets and runtime settings in .env (unquoted for `docker run --env-file` compatibility)
cat <<EOF > .env
DB_USER=wedding
DB_PASSWORD=${DB_SECRET}
DB_NAME=wedding
DATABASE_URL=postgresql://wedding:${DB_SECRET}@db:5432/wedding?schema=public&sslmode=disable
PORT=3000
STANDBY_PORT=3001
ADMIN_PASSWORD=${ADMIN_HASH}
ALLOWED_HOSTS=wedding.mydomain.com,localhost,127.0.0.1
GUEST_PASSCODE=choose-a-unique-celebration-passcode
GUEST_SESSION_SECRET=${GUEST_SECRET}
TRUST_PROXY=1
E2E_TEST=false
EOF
# Build wedding-website:latest once via `app`, run `migration`, and start `app` in detached mode
docker compose build app
docker compose up -dZero-Downtime Deployment Update (scripts/rollout-vps.sh)
Use ./scripts/rollout-vps.sh (layered with docker-compose.rollout.yml) so updates snapshot any existing wedding-website:latest image as wedding-website:previous, compile the image once via app, apply pending Prisma migrations, warm app-standby on 127.0.0.1:${STANDBY_PORT:-3001}:3000, verify Host-free loopback /api/live, /api/health, and /api/ready probes, recreate primary app on 127.0.0.1:${PORT:-3000}:3000 without dropping requests behind Caddy or Nginx (preserving app-standby and attempting automatic primary rollback onto wedding-website:previous if primary cutover fails), and retire app-standby:
git pull origin main
./scripts/rollout-vps.sh(For maintenance windows without a dual-upstream proxy, docker compose build app && docker compose up -d also applies migration before recreating app.)
Automated Rollouts via GitHub Actions (docker-host & generic-webhook)
Instead of building on the VPS, operators can pull attested multi-arch ghcr.io images automatically from .github/workflows/deploy.yml or .github/workflows/deploy-provider.yml using provider: docker-host (or provider: generic-webhook). Configure vars.SERVICE_URL plus environment secrets DEPLOY_WEBHOOK_URL and DEPLOY_WEBHOOK_SECRET in your staging, production, and optional unguarded production-rollback GitHub Environments, and see Section 9 below for the stateless signed webhook payload, timestamp window, and dual-HMAC verification contract.
7. Health Checks & Graceful Shutdown
docker-compose.yml already configures built-in healthcheck probes on both db (pg_isready) and app (/api/live), along with init: true and stop_grace_period: 15s so Next.js finishes active HTTP requests and src/lib/prisma.ts drains pg.Pool within its 5000ms shutdown safety timer—no manual edits to docker-compose.yml are required:
app:
init: true
stop_grace_period: 15s
ports:
- "127.0.0.1:${PORT:-3000}:3000"
healthcheck:
test: ["CMD-SHELL", "node -e \"fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/live').then((res)=>{if(!res.ok)process.exit(1);}).catch(()=>process.exit(1))\""]
interval: 15s
timeout: 5s
retries: 3
start_period: 20sVerify live container status with docker compose ps. Stateless GET and HEAD probes to /api/live, /api/health, and /api/ready enforce syntactic Host validation only, so loopback 127.0.0.1 probes succeed without Host header overrides even when ALLOWED_HOSTS lists only public domains. Continuous container liveness checks hit /api/live (HTTP 200 { "status": "alive", "timestamp": "..." }) so brief PostgreSQL blips do not restart warm containers, while deployment rollout checks query /api/health (HTTP 200 OK with Cache-Control: no-store when PostgreSQL is connected):
{
"success": true,
"data": {
"status": "ok",
"timestamp": "2026-09-30T14:30:00.000Z",
"database": "connected"
}
}When PostgreSQL is unreachable (HTTP 503 Service Unavailable), withApiMiddleware (isHealthProbe: true in src/utils/withApiMiddleware.ts) preserves diagnostic probe fields { "success": false, "status": "degraded", "database": "disconnected", "timestamp": "2026-09-30T14:30:00.000Z", "error": "Database connection failed" } on /api/health while sanitizing error text in NODE_ENV=production so internal driver details never leak. Unwrapped readiness monitors and rollout gates query /api/ready, which verifies all 16 prisma/schema.prisma tables (REQUIRED_SCHEMA_TABLES in src/lib/readinessManifest.ts) and all 47 committed _prisma_migrations entries (REQUIRED_MIGRATION_NAMES in src/lib/readinessManifest.ts, allowing extra forward N+1 migrations during N-1 rollbacks) without requiring seeded AppConfig rows and returns HTTP 200 { "status": "ready", "database": "connected", "timestamp": "..." } or HTTP 503 with status: "unhealthy" (database: "connected" and error: "Database schema is not ready" when schema/migrations are incomplete, or database: "disconnected" and error: "Database connection failed" when PostgreSQL is unreachable).
8. Rollback Strategy
- Tag Image Builds Before Updating: Tag the currently running image (or pull an attested
ghcr.io/fderuiter/wedding_website@sha256:<digest>release image) prior to upgrading:bashdocker tag wedding-website:latest wedding-website:previous - Networked & Port-Mapped Container Rollback:
- Via Docker Compose (Recommended — preserves Compose
dbnetwork,127.0.0.1:${PORT:-3000}:3000port binding,stop_grace_period: 15s, and healthcheck):bashdocker tag wedding-website:previous wedding-website:latest docker compose up -d --no-deps app - Via Standalone
docker run(Must attach Compose network, publish loopback port, allow15sstop timeout, and loadDATABASE_URLdirectly from--env-file .env):bashdocker compose stop app docker run -d --name app-rollback \ --init \ --stop-timeout 15 \ --network wedding_website_default \ -p 127.0.0.1:3000:3000 \ --read-only \ --cap-drop=ALL \ --security-opt=no-new-privileges:true \ --tmpfs /tmp \ --tmpfs /app/.next/cache:uid=1001,gid=1001,mode=0755 \ -v wedding_website_uploads_data:/app/public/uploads \ --env-file .env \ -e E2E_TEST=false \ wedding-website:previous
- Via Docker Compose (Recommended — preserves Compose
- Automated GitHub Actions Rollback (
rollback.yml&deploy-provider.yml): When deploying viaprovider: docker-hostorprovider: generic-webhook,.github/workflows/deploy-provider.ymlfilters completeddeploy.ymlanddeploy-provider.ymlruns to the last non-dry-run target-environment (stagingorproduction) rollout, verifies candidate tags in GHCR viadocker buildx imagetools inspect(skipping unpublishedHEAD^1commits), and forwards bothprevious_image_tagandprevious_image_digestto.github/workflows/rollback.ymlif/api/healthor/api/readyfails. - Database Schema Rollback: Prisma migrations are forward-only by design. Keep database schema changes backward-compatible (e.g., expand-and-contract pattern) to ensure older container versions can operate alongside migrated schemas.
9. Webhooks & Scheduled Background Jobs
Stripe payment_intent.succeeded Webhook
- Set
STRIPE_SECRET_KEY,NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY, andSTRIPE_WEBHOOK_SECRETin.env(docker-compose.ymlforwards all three variables directly intoapp). - In the Stripe Dashboard > Developers > Webhooks, create an endpoint pointing to
https://wedding.mydomain.com/api/registry/webhook/stripe(ensurewedding.mydomain.comis inALLOWED_HOSTS) and subscribe topayment_intent.succeeded. - Ensure Caddy or Nginx forwards the raw request body and
Stripe-Signatureheader untouched (default behavior in both reverse proxy configs above).src/middleware.tsexempts/api/registry/webhook/stripefrom session cookies while verifyingALLOWED_HOSTS, and the webhook handler validatesstripe-signatureusingSTRIPE_WEBHOOK_SECRET.
Signed Deployment Webhook Receiver (docker-host & generic-webhook)
When .github/workflows/deploy-provider.yml runs with provider: docker-host or provider: generic-webhook (without dry_run), GitHub Actions sends an authenticated POST request (--fail-with-body, 10s connect timeout, 30s max runtime) to DEPLOY_WEBHOOK_URL signed with DEPLOY_WEBHOOK_SECRET — requiring no repository-managed daemon on your VPS:
- GitHub Environment Secrets: Set
DEPLOY_WEBHOOK_URL(HTTPS listener URL on your VPS reverse proxy) andDEPLOY_WEBHOOK_SECRET(32+ byte random HMAC secret) instaging,production, and optionalproduction-rollback, alongsidevars.SERVICE_URL. POSTJSON Payload Schema ({image, digest, environment}) & Multi-Line Raw-Byte Formatting:deploy-provider.ymlformatsPAYLOADusingjq -n(without-c), sending pretty-printed multi-line UTF-8 JSON with 2-space indentation and internal\nnewlines (trailing newline stripped by bash$(...);digestis omitted only if empty):jsonRaw-Byte Rule: Read the unparsed HTTP request buffer ({ "image": "ghcr.io/fderuiter/wedding_website@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "digest": "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "environment": "production" }PAYLOAD) directly and compute HMAC digests over those exact raw bytes. Never parse JSON and re-serialize withJSON.stringify(), which stripsjq -nnewlines/indentation and breaks signature verification.- Timestamp Window & Dual-HMAC Headers:
Content-Type: application/jsonX-Deploy-Timestamp: <unix-seconds>— UTC epoch seconds (date -u +%s). Reject requests whenMath.abs(nowSeconds - Number(timestamp)) > 300(5-minute replay window).X-Hub-Signature-256: sha256=<64-lowercase-hex>—HMAC-SHA256(DEPLOY_WEBHOOK_SECRET, PAYLOAD)over rawPAYLOADbytes.X-Deploy-Signature-256: sha256=<64-lowercase-hex>—HMAC-SHA256(DEPLOY_WEBHOOK_SECRET, "${X-Deploy-Timestamp}.${PAYLOAD}")over the timestamp-prefixed raw payload (${X-Deploy-Timestamp}.${PAYLOAD}). Verify both headers using constant-time digest comparison (crypto.timingSafeEqual) before pulling the@sha256:image and restartingapp.
Scheduled Broadcast Cron (CRON_SECRET)
- Set
CRON_SECRETin.env(docker-compose.ymlforwardsCRON_SECRETdirectly intoapp). - Add a host
crontabentry (crontab -e) or systemd timer that triggers/api/cron/broadcastsevery 5 minutes over loopback with an allowedHostheader andAuthorization: Bearer <CRON_SECRET>:cron*/5 * * * * curl -fsS -X POST http://127.0.0.1:3000/api/cron/broadcasts -H "Host: localhost" -H "Authorization: Bearer replace-with-random-cron-secret" >/dev/null
10. Provider-Specific Limitations
- Host Dependency: Requires managing server OS patches, Docker engine updates, and firewall rules (ports 80, 443, 22).
- Disk Persistence: If using local filesystem storage, host backups must include the
uploads_dataDocker volume (or host upload directory) alongsidedb_data. - Single-Node Availability: Without an external load balancer or swarm/k8s cluster, host maintenance causes brief downtime.