20 — Production deployment guide
Version: 1.9
Last Updated: 2026-08-05 17:38:42
Location: docs/03 - DEPLOYMENT AND PRODUCTION/ — canonical production deploy document
Audience: Product owner (reference) and AI agents / automation (run the scripts). This is the single source of truth for production push, backups on deploy, and post-deploy gates.
Start here: 00-INDEX.md in this folder lists every production-related document and its role.
1. Production topology
Section titled “1. Production topology”| Surface | URL | Host | Deploy artifact |
|---|---|---|---|
| Marketing site | https://lyncareos.com / www | Cloudflare Pages project lyncareos-marketing | Static files in marketing/palliative/ |
| Product (app) | https://app.lyncareos.com | DigitalOcean VPS lyncareos-prod-syd1 | Docker image magna123456/lyncareos:<tag> |
| App tunnel | app.lyncareos.com → VPS :8020 | cloudflared systemd on VPS | Tunnel c0396e69-…, config /etc/cloudflared/config.yml |
| LM Studio tunnel | lmstudio.lyncareos.com → workstation :1234 | cloudflared Windows service on workstation (192.168.7.104) | Tunnel b2aa7c18-…, remote-managed (config in Cloudflare dashboard / API) |
| Database | — | VPS Docker postgres | Volume lyncare_pg_data → /data/pg (50 GB block volume) |
VPS access (from Windows workstation):
ssh -i "$env:USERPROFILE\.ssh\lyncareos_vps" root@134.199.173.206cd /opt/lyncareos| Attribute | Value |
|---|---|
| Public IP | 134.199.173.206 |
| App files | /opt/lyncareos/ |
| Compose | docker-compose.yml + docker-compose.vps.yml, --env-file .env.production, --profile production |
| Live since | 2026-05-20 (workstation decommissioned as production host) |
Hosting decision (May 2026)
Section titled “Hosting decision (May 2026)”Production runs on DigitalOcean Sydney (lyncareos-prod-syd1, Basic 2 vCPU / 4 GB, 50 GB volume at /data/pg). Cloudflare Tunnel c0396e69-b202-48eb-a3c7-925b0d7c618c terminates app.lyncareos.com. Images publish via Docker Hub; VPS has no git checkout.
Provider comparison and cutover checklist (historical): ../archive/25-PRODUCTION-SERVER-BUILD-AND-PROVIDER-ANALYSIS.md. Scale path: 17-HARDENING-SCALE-RUNBOOK.md Part I.
2. What deploys separately
Section titled “2. What deploys separately”Three independent surfaces — do not assume one command updates everything.
| Change type | Deploy command | Updates |
|---|---|---|
| Backend, SPA, API behaviour | .\scripts\deploy.ps1 | app.lyncareos.com only |
| Pricing copy, hero, marketing HTML | .\scripts\deploy-marketing-pages.ps1 | lyncareos.com only |
| PostgreSQL schema | Automatic on app startup after image deploy; read 11-DATABASE-SAFETY-AND-MIGRATIONS.md first | Database on VPS |
Order of operations: Prefer the app healthy on app.lyncareos.com (tiers, signup, CORS) before or together with marketing changes that depend on new API behaviour. Marketing pages call https://app.lyncareos.com for billing and signup when served from lyncareos.com.
2a. Release philosophy (what “push to production” means)
Section titled “2a. Release philosophy (what “push to production” means)”When the product owner says push to production or release to production, they mean: thorough testing on dev first, then promote code and database changes together through each tier — never migrations on live VPS without the matching app image.
| Tier | Where you test / gate | Database | Code (app + API + SPA) | How schema/data changes apply |
|---|---|---|---|---|
| 1 — Dev | Native Postgres + Vite (dev-start.ps1, :8021) | lyncareos_dev @ :5432 | Running from repo (hot reload) | migrate.ps1 -Target Dev · manual/feature testing before any release |
| 2 — Docker UAT | Full Compose production profile on this PC (:8020) | lyncareos @ :5433 | docker compose --profile production up -d --build — same image shape as VPS | init_db() on app start + migrate.ps1 -Target Production if needed · gate: PENDING: none |
| 3 — Live VPS | https://app.lyncareos.com | lyncareos on DO Sydney | deploy.ps1 — build, push Docker Hub, pull on VPS | init_db() on app start after deploy · full pg_dump backup before container change |
Agent entry point (owner does not run scripts): .\scripts\push-to-production.ps1 — implements the table above. Full agent contract: §2b below.
Data in migrations: Seed/backfill SQL in backend/migrations/ ships with the same promotion path (dev → Docker → VPS). One-off PHI backfill may run via production-migration-preflight.ps1 inside deploy.ps1 when required.
Not the same as marketing deploy: deploy-marketing-pages.ps1 updates lyncareos.com only — no VPS database.
2b. AI agent / automation contract
Section titled “2b. AI agent / automation contract”The product owner does not run PowerShell scripts or manual backups. AI agents (or CI) run the automation below. Tell the owner what you ran, whether smoke tests passed, and cache / gate results — not which commands they should type. Example: “I pushed to production; backup on VPS; API 200; new CACHE_NAME hash confirmed on sw.js.”
Single entry point
Section titled “Single entry point”When the owner says push to production, release to production, or deploy (after they have tested on dev), run the three-tier promotion in §2a — code + migrations together — never VPS schema changes without the matching image.
cd D:\Projects\LynCareOS.\scripts\push-to-production.ps1This runs, in order:
- Dev —
migrate.ps1 -Target Dev+ audit untilPENDING: none(owner should already have tested features on dev) - Docker UAT — backup →
docker compose --profile production up -d --build→ HTTP 200 on:8020(migrations on app startup viainit_db) → auditPENDING: none(skip with-SkipDockerUatonly if the owner explicitly says VPS-only). Do not callmigrate.ps1 -Target Productionafter compose up — it deadlocks on the advisory lock. - VPS —
deploy.ps1(fullpg_dumpbefore deploy, retain 10+10 backups) → audit VPSPENDING: none
Migrations and any migration-bundled data run via migrations.runner on app startup at tiers 2 and 3.
Do not ask the owner to run vps-production-backup.ps1 separately. Do not SSH psql DDL/DML to production except read-only diagnostics.
| Script | When |
|---|---|
push-to-production.ps1 | Default — dev + Docker UAT + VPS deploy |
push-to-production.ps1 -SkipDockerUat | VPS deploy only (dev migrations still run) |
deploy.ps1 | Image-only roll when dev/UAT already done |
apply-vps-pending-migrations.ps1 | Rare — migrations.runner on VPS after failed deploy; runs full backup first |
Forbidden without an explicit owner request for disaster rehearsal:
backup-restore-drill-vps-production.ps1 -IUnderstand(destructive overwrite of live DB)- Manual
DROP DATABASE/pg_restoreinto livelyncareoson VPS - Applying VPS migrations by SSH without
apply-vps-pending-migrations.ps1ordeploy.ps1
Backups (automatic on deploy paths)
Section titled “Backups (automatic on deploy paths)”| Event | Full backup? | Retention |
|---|---|---|
Every deploy.ps1 | Yes — pre-deploy pg_dump -Fc | 10 on VPS /var/backups/lyncareos/, 10 production files on this PC |
apply-vps-pending-migrations.ps1 | Yes — calls vps-production-backup.ps1 first | Same |
vps-production-backup.ps1 | Standalone only if an agent needs backup without deploy | Same |
Log: backups/backup-run-log.jsonl. Procedure detail: 23-BACKUP-RESTORE-DRILL.md. Uploads (lyncare_uploads volume) are not in Postgres dumps — note in release notes if file recovery matters. Prefer a third offsite copy outside this workstation.
Post-deploy: do not announce until gates pass
Section titled “Post-deploy: do not announce until gates pass”Do not treat “containers restarted” as deploy complete. Work §6 in order, including:
- New
sw.jsCACHE_NAME(must differ from previous deploy) index.html/ shellCache-Control: no-cache, no-store, must-revalidateGET /api/billing/tiers→ HTTP 200- Care Module preview gate (§6.3) — hard fail inside
deploy.ps1 - PHI crypto health gate (§6.4) — hard fail on Docker UAT and VPS
Local vs production: A stuck push-to-production.ps1 on the workstation (e.g. Docker UAT backup hang) does not change production. Never kill arbitrary VPS processes to unstick a local script — production restarts happen only via deploy.ps1 → vps-pull-and-start.sh --redeploy. See .cursor/rules/production-deploy-cache.mdc.
3. Pre-flight (every deploy)
Section titled “3. Pre-flight (every deploy)”| Check | Command / action |
|---|---|
| Repo vs VPS migrations | .\migration-audit.ps1 -Target Vps -NonInteractive |
| Frontend builds | cd frontend && npm run build (also inside deploy.ps1; runs brand touchpoint check first) |
| PHI backfill if V090 pending | .\scripts\production-migration-preflight.ps1 -RunBackfillIfNeeded |
| CORS includes marketing origins | .env.production: ALLOWED_ORIGINS includes https://lyncareos.com, https://www.lyncareos.com, https://app.lyncareos.com |
| Stripe tiers on production DB | Live keys + tier seed against production lyncareos — not dev DB |
| Brand parity (logo + wordmark) | cd frontend && node scripts/check-brand-touchpoints.mjs — fails if desktop/mobile/auth shells drift |
| Post-deploy visual (mobile) | On phone: top bar = Heartmark 2 + tri-colour LynCareOS; tab icon = split-heart (may need tab close / re-add home screen) |
4. Deploy the app (app.lyncareos.com)
Section titled “4. Deploy the app (app.lyncareos.com)”4.1 One command (AI agent runs this — not the product owner)
Section titled “4.1 One command (AI agent runs this — not the product owner)”Default pipeline (dev → Docker UAT → VPS, with automatic full backups):
cd D:\Projects\LynCareOS.\scripts\push-to-production.ps1Deploy only (when dev/UAT already done):
.\scripts\deploy.ps1Agent contract and script variants: §2b. The owner does not run backup scripts manually; deploy.ps1 always pg_dumps the full lyncareos database and retains the newest 10 dumps on the VPS and 10 on this workstation.
Optional flags:
.\scripts\deploy.ps1 -Tag v1.2.3 # meaningful release name on Docker Hub.\scripts\deploy.ps1 -SkipBuild # redeploy existing :latest without rebuild4.2 What the script does
Section titled “4.2 What the script does”- Pre-flight — Docker running, SSH key,
.env.production, VPS reachable - Frontend build —
npm run build(unless-SkipBuild) - Migration preflight — PHI backfill gate before V090 if needed
- Pre-deploy backup —
pg_dumpon VPS to/tmp/pre-deploy-<tag>.dump - Docker build — workstation builds
backend/Dockerfile(SPA + API) - Push to Docker Hub —
magna123456/lyncareos:latestand:deploy-YYYYMMDD-HHMM - VPS pull + restart —
appandscan_workeronly; Postgres/Redis untouched - Smoke test — up to 120 s; internal + public
GET /api/billing/tiers→ HTTP 200 - PHI key pin —
production-phi-pin.ps1if keys missing on VPS
Postgres, Redis, and PgBouncer keep running throughout.
4.3 Migrations on startup
Section titled “4.3 Migrations on startup”init_db() applies pending migrations first, then idempotent schema.sql (see 11 §3a). Watch logs:
ssh -i "$env:USERPROFILE\.ssh\lyncareos_vps" root@134.199.173.206 ` "docker logs lyncareos-app-1 2>&1 | grep -i migrat"V090 failure: run .\scripts\production-migration-preflight.ps1 -RunBackfillIfNeeded, then restart app. See 11 §2.
V099 / patient_id boot failure (2026-05-29 lesson): If app crashes with UndefinedColumn: column "patient_id" does not exist on audit_log, the image started schema.sql before V099 on an older DB. Recovery without rollback:
ssh -i "$env:USERPROFILE\.ssh\lyncareos_vps" root@134.199.173.206 ` 'cd /opt/lyncareos && docker compose -f docker-compose.yml -f docker-compose.vps.yml --env-file .env.production --profile production run --rm --no-deps app python -m migrations.runner && docker compose -f docker-compose.yml -f docker-compose.vps.yml --env-file .env.production --profile production restart app'Then redeploy when the repo includes migrations-first init_db() so the next pending migration cannot repeat this pattern.
4.4 App rollback
Section titled “4.4 App rollback”.\scripts\deploy.ps1 -SkipBuild -Tag deploy-20260519-1100Previous tags: https://hub.docker.com/r/magna123456/lyncareos/tags
If a migration caused boot failure, roll back the image first, then inspect schema_migrations and the pre-deploy dump — full procedure in 04 - OPERATIONS/07-PLATFORM-RUNBOOK.md §13.3 and doc 11.
5. Deploy the marketing website (lyncareos.com)
Section titled “5. Deploy the marketing website (lyncareos.com)”Marketing is Cloudflare Pages, not the Docker app image. Source: marketing/palliative/ (includes _worker.js private-beta gate).
5.1 Routine deploy (after copy/design changes)
Section titled “5.1 Routine deploy (after copy/design changes)”cd D:\Projects\LynCareOS.\scripts\deploy-marketing-pages.ps1Requires in .env.production:
CLOUDFLARE_API_TOKENCLOUDFLARE_ACCOUNT_ID(for account-scoped API tokens)MARKETING_PREVIEW_SECRET(private-beta gate; synced to Pages bindingPREVIEW_SECRETbefore deploy)
Equivalent manual command:
npx wrangler pages deploy marketing/palliative --project-name lyncareos-marketing --branch main5.1a Preview secret rotation
Section titled “5.1a Preview secret rotation”The marketing gate secret is never committed in _worker.js. Rotate when revoking early-access links or after any leak:
- Generate:
python -c "import secrets; print(secrets.token_urlsafe(24))" - Set
MARKETING_PREVIEW_SECRETin.env.production - Run
.\scripts\deploy-marketing-pages.ps1(pushes secret via Wrangler, then deploys) - Distribute new
?preview=<secret>invitation links — existing preview cookies invalidate
5.2 First-time Pages setup
Section titled “5.2 First-time Pages setup”If the Pages project does not exist yet, follow 13-MARKETING-AND-SUBDOMAIN-DEPLOYMENT.md §3–4:
- DNS:
appCNAME → tunnel; root/www→ Pages (remove conflicting tunnel CNAMEs first) - Pages project root directory:
marketing/palliative - Build command: blank (static HTML)
- Custom domains:
lyncareos.com,www.lyncareos.com
5.3 How marketing finds the API
Section titled “5.3 How marketing finds the API”In marketing/palliative/index.html, when served from lyncareos.com or www.lyncareos.com, JavaScript sets window.LYNCAREOS_API_BASE to https://app.lyncareos.com. Signup, FX preview, and billing calls are cross-origin — backend CORS must allow marketing origins.
5.4 Marketing rollback
Section titled “5.4 Marketing rollback”In Cloudflare dashboard: Pages → lyncareos-marketing → Deployments → select previous deployment → Rollback to this deployment.
Or redeploy a known-good git commit via deploy-marketing-pages.ps1 from that commit.
6. Post-deploy verification
Section titled “6. Post-deploy verification”Work through in order.
Marketing (lyncareos.com)
Section titled “Marketing (lyncareos.com)”-
https://lyncareos.comloads marketing page (not app login) -
https://www.lyncareos.comredirects to apex - Images load (no broken icons)
- Login →
https://app.lyncareos.com - Pricing cards show expected copy (e.g. tier bullets match product)
- Mobile layout and nav work
App (app.lyncareos.com)
Section titled “App (app.lyncareos.com)”- Login screen loads
- Username/password login → dashboard
- Google OAuth (desktop + iOS Safari/PWA as applicable)
-
GET /api/billing/tiers→ HTTP 200 (public) - Sample mutation (dispense, shift) — no CORS errors in console
- SPA cache invalidation is live —
curl -sI https://app.lyncareos.com/sw.js | head -5returns 200 and the body’sCACHE_NAMEcontains a different hash from the previous deploy (grep CACHE_NAMEin the response). If the hash is unchanged, mid-session users will not auto-reload onto the new build — investigate before announcing the deploy. - index.html is no-store —
curl -sI https://app.lyncareos.com/ | grep -i cache-controlreturnsno-cache, no-store, must-revalidate. - Mid-session smoke test — open the app in a normal window before running
deploy.ps1, then after deploy navigate to a lazy route (/scripts,/analytics,/calendar). Expected: a brief flash and the page loads cleanly. Unexpected: an “Error ID: …” card — that means the recovery path failed; capture the console error and checkfrontend/src/lib/lazyWithReload.tsis wired into the bundle.
6.3 Care Module preview gate (mandatory until public board rollout)
Section titled “6.3 Care Module preview gate (mandatory until public board rollout)”Interactive care boards (/care/cancer-at-home, /care/breathing, /api/care-modules/*) are not general availability until a slug is live in backend/care_modules/go_live.json. While a slug is preview, only users in that slug’s preview_user_ids and with care_module_dev_preview enabled (default off) see board nav and Subscriptions offers. All other accounts see no board nav, get 403 on board APIs, and see the gate message if they hit a /care/* URL directly.
Automated (runs inside deploy.ps1 / push-to-production.ps1):
.\scripts\verify-care-module-preview-gate.ps1The script checks workstation + VPS .env.production, frontend/.env.production (VITE_CARE_MODULE_BOARDS), runtime config inside lyncareos-app-1, and slug_board_visible('cancer_at_home', …) — user 1 with preview off blocked, user 1 with preview on allowed (cohort default), user 2 blocked. Deploy fails if any check fails.
Manual spot-check (optional, after deploy):
- Log in as a non-preview test account → Home has no Cancer/Breathing care board nav or dashboard widgets
- Log in as Peter (user id 1) with preview toggle ON and a patient on
cancer_at_home→ board nav and hub load; with toggle OFF → same as any customer (no board nav)
Policy knobs (keep workstation and VPS in sync):
| Variable | Location | Current launch policy |
|---|---|---|
CARE_MODULE_BOARDS_ENABLED | Root .env.production + VPS | true (boards deployed) |
CARE_MODULE_PREVIEW_USER_IDS | Root .env.production + VPS | 1 (Peter only) |
VITE_CARE_MODULE_BOARDS | frontend/.env.production (Docker build) | true (routes in SPA bundle; UI still gated per user) |
To widen preview: add comma-separated user ids to CARE_MODULE_PREVIEW_USER_IDS on both workstation and VPS, restart app, re-run verification with -ExpectedPreviewUserIds "1,42". To turn boards off for everyone: set CARE_MODULE_BOARDS_ENABLED=false on VPS and VITE_CARE_MODULE_BOARDS=false in frontend build, then redeploy.
Architecture: care-profile-specs/30-CARE-MODULE-PLUGIN-ARCHITECTURE.md.
Full checklist (OAuth edge cases, uploads): 13-MARKETING-AND-SUBDOMAIN-DEPLOYMENT.md §Step 8.
Background on the SPA cache-invalidation strategy and why the two checks above matter: docs/plans/2026-05-29-spa-deploy-resilience.md.
6.4 PHI crypto health gate (mandatory — hard fail)
Section titled “6.4 PHI crypto health gate (mandatory — hard fail)”Encrypted identity fields (users.email_enc, patient names/DOBs, care groups, tenants) must decrypt with the keys loaded in the running app environment. A key/ciphertext mismatch breaks login and patient load and can breach operator-blindness claims in Terms/Privacy.
Automated (hard fail inside push-to-production.ps1 / deploy.ps1):
.\scripts\verify-phi-crypto-health.ps1 -Target DockerUat # after Docker UAT migrations.\scripts\verify-phi-crypto-health.ps1 -Target Vps # pre-redeploy (after backup) and post-redeploy (after smoke)Deploy must not proceed or be announced if either check fails. Counts only in output — never PHI. Canonical detail: 11-DATABASE-SAFETY-AND-MIGRATIONS.md §2a-gate and plan 2026-07-20-phi-crypto-release-gate.md.
7. Day-2 operations (not deploy)
Section titled “7. Day-2 operations (not deploy)”After shipping, use 04 - OPERATIONS/07-PLATFORM-RUNBOOK.md §12–§18 for:
- Container status, logs, restart
- Cloudflare Tunnel (
cloudflared) service - Backups and restore drill — 23-BACKUP-RESTORE-DRILL.md (A5 + A5b complete 2026-06-02). Workstation offsite copy:
.\scripts\vps-production-backup.ps1(tier 2 best-effort) - Incident response
- VPS OS upgrade: mandatory PostgreSQL
REINDEX DATABASE lyncareos— 07-PLATFORM-RUNBOOK §18 and 11-DATABASE-SAFETY §2q (control: record completion before closing the change)
8. Related documents
Section titled “8. Related documents”| Topic | Document |
|---|---|
| This folder index | 00-INDEX.md |
| Database safety | [04 - OPERATIONS/11-DATABASE-SAFETY-AND-MIGRATIONS.md](../04 - OPERATIONS/11-DATABASE-SAFETY-AND-MIGRATIONS.md) |
| Stripe live flip | 21-STRIPE-LIVE-SWITCHOVER.md |
| CI/CD automation | [02 - ARCHITECTURE_DESIGN/12-CI-REFERENCE.md](../02 - ARCHITECTURE_DESIGN/12-CI-REFERENCE.md) §0.9, §9.6 |
| Marketing visuals / first-time DNS | 13-MARKETING-AND-SUBDOMAIN-DEPLOYMENT.md |
| Current shipped state | 04-ROADMAP.md |
| Backup/restore drill (A5) | 23-BACKUP-RESTORE-DRILL.md |
| Provider analysis / tier-3 B2 | 99-ARCHIVE/25-PRODUCTION-SERVER-BUILD-AND-PROVIDER-ANALYSIS.md |
9. Helper scripts
Section titled “9. Helper scripts”| Script | Purpose |
|---|---|
scripts/deploy.ps1 | Full app deploy to VPS |
scripts/deploy-marketing-pages.ps1 | Cloudflare Pages deploy (+ sync PREVIEW_SECRET) |
scripts/security-review-static.ps1 | Git-free static security review (Ruff, router SQL, secret scan) |
migration-audit.ps1 -Target Vps -NonInteractive | Repo vs VPS migration versions |
scripts/production-migration-preflight.ps1 | PHI backfill before V090 |
scripts/production-phi-pin.ps1 | Pin encryption keys on VPS |
scripts/push-to-production.ps1 | Agent default — dev + Docker UAT + deploy (automatic full backup) |
scripts/deploy.ps1 | VPS deploy only (step 2 full backup; keep 10 + 10) |
scripts/apply-vps-pending-migrations.ps1 | Rare VPS migration restart — backup first |
scripts/vps-production-backup.ps1 | Called by deploy/apply — not run by product owner |
scripts/pull-vps-backup-to-workstation.ps1 | Wrapper → vps-production-backup.ps1 |
scripts/backup-restore-drill-vps-production.ps1 -IUnderstand | Phase 3 disaster-restore rehearsal (destructive; ops only) |