Skip to content

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.


SurfaceURLHostDeploy artifact
Marketing sitehttps://lyncareos.com / wwwCloudflare Pages project lyncareos-marketingStatic files in marketing/palliative/
Product (app)https://app.lyncareos.comDigitalOcean VPS lyncareos-prod-syd1Docker image magna123456/lyncareos:<tag>
App tunnelapp.lyncareos.com → VPS :8020cloudflared systemd on VPSTunnel c0396e69-…, config /etc/cloudflared/config.yml
LM Studio tunnellmstudio.lyncareos.com → workstation :1234cloudflared Windows service on workstation (192.168.7.104)Tunnel b2aa7c18-…, remote-managed (config in Cloudflare dashboard / API)
Database—VPS Docker postgresVolume lyncare_pg_data → /data/pg (50 GB block volume)

Workstation 192.168.7.104

DO Sydney lyncareos-prod-syd1

Cloudflare

Internet

https Bearer

Browser

Pages: lyncareos-marketing

Tunnel app.lyncareos.com

Tunnel lmstudio.lyncareos.com

cloudflared systemd

app :8020

FastAPI + SPA

scan_worker

postgres

cloudflared Windows service

LM Studio :1234

Qwen2.5-VL

VPS access (from Windows workstation):

Terminal window
ssh -i "$env:USERPROFILE\.ssh\lyncareos_vps" root@134.199.173.206
cd /opt/lyncareos
AttributeValue
Public IP134.199.173.206
App files/opt/lyncareos/
Composedocker-compose.yml + docker-compose.vps.yml, --env-file .env.production, --profile production
Live since2026-05-20 (workstation decommissioned as production host)

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.


Three independent surfaces — do not assume one command updates everything.

Change typeDeploy commandUpdates
Backend, SPA, API behaviour.\scripts\deploy.ps1app.lyncareos.com only
Pricing copy, hero, marketing HTML.\scripts\deploy-marketing-pages.ps1lyncareos.com only
PostgreSQL schemaAutomatic on app startup after image deploy; read 11-DATABASE-SAFETY-AND-MIGRATIONS.md firstDatabase 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.

TierWhere you test / gateDatabaseCode (app + API + SPA)How schema/data changes apply
1 — DevNative Postgres + Vite (dev-start.ps1, :8021)lyncareos_dev @ :5432Running from repo (hot reload)migrate.ps1 -Target Dev · manual/feature testing before any release
2 — Docker UATFull Compose production profile on this PC (:8020)lyncareos @ :5433docker compose --profile production up -d --build — same image shape as VPSinit_db() on app start + migrate.ps1 -Target Production if needed · gate: PENDING: none
3 — Live VPShttps://app.lyncareos.comlyncareos on DO Sydneydeploy.ps1 — build, push Docker Hub, pull on VPSinit_db() on app start after deploy · full pg_dump backup before container change

1 Dev

lyncareos_dev

you test here

2 Docker UAT

build stack

PENDING none

3 VPS

app.lyncareos.com

backup + deploy

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.


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.”

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.

Terminal window
cd D:\Projects\LynCareOS
.\scripts\push-to-production.ps1

This runs, in order:

  1. Dev — migrate.ps1 -Target Dev + audit until PENDING: none (owner should already have tested features on dev)
  2. Docker UAT — backup → docker compose --profile production up -d --build → HTTP 200 on :8020 (migrations on app startup via init_db) → audit PENDING: none (skip with -SkipDockerUat only if the owner explicitly says VPS-only). Do not call migrate.ps1 -Target Production after compose up — it deadlocks on the advisory lock.
  3. VPS — deploy.ps1 (full pg_dump before deploy, retain 10+10 backups) → audit VPS PENDING: 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.

ScriptWhen
push-to-production.ps1Default — dev + Docker UAT + VPS deploy
push-to-production.ps1 -SkipDockerUatVPS deploy only (dev migrations still run)
deploy.ps1Image-only roll when dev/UAT already done
apply-vps-pending-migrations.ps1Rare — 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_restore into live lyncareos on VPS
  • Applying VPS migrations by SSH without apply-vps-pending-migrations.ps1 or deploy.ps1
EventFull backup?Retention
Every deploy.ps1Yes — pre-deploy pg_dump -Fc10 on VPS /var/backups/lyncareos/, 10 production files on this PC
apply-vps-pending-migrations.ps1Yes — calls vps-production-backup.ps1 firstSame
vps-production-backup.ps1Standalone only if an agent needs backup without deploySame

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:

  1. New sw.js CACHE_NAME (must differ from previous deploy)
  2. index.html / shell Cache-Control: no-cache, no-store, must-revalidate
  3. GET /api/billing/tiers → HTTP 200
  4. Care Module preview gate (§6.3) — hard fail inside deploy.ps1
  5. 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.


CheckCommand / action
Repo vs VPS migrations.\migration-audit.ps1 -Target Vps -NonInteractive
Frontend buildscd 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 DBLive 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.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):

Terminal window
cd D:\Projects\LynCareOS
.\scripts\push-to-production.ps1

Deploy only (when dev/UAT already done):

Terminal window
.\scripts\deploy.ps1

Agent 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:

Terminal window
.\scripts\deploy.ps1 -Tag v1.2.3 # meaningful release name on Docker Hub
.\scripts\deploy.ps1 -SkipBuild # redeploy existing :latest without rebuild
  1. Pre-flight — Docker running, SSH key, .env.production, VPS reachable
  2. Frontend build — npm run build (unless -SkipBuild)
  3. Migration preflight — PHI backfill gate before V090 if needed
  4. Pre-deploy backup — pg_dump on VPS to /tmp/pre-deploy-<tag>.dump
  5. Docker build — workstation builds backend/Dockerfile (SPA + API)
  6. Push to Docker Hub — magna123456/lyncareos:latest and :deploy-YYYYMMDD-HHMM
  7. VPS pull + restart — app and scan_worker only; Postgres/Redis untouched
  8. Smoke test — up to 120 s; internal + public GET /api/billing/tiers → HTTP 200
  9. PHI key pin — production-phi-pin.ps1 if keys missing on VPS

Postgres, Redis, and PgBouncer keep running throughout.

init_db() applies pending migrations first, then idempotent schema.sql (see 11 §3a). Watch logs:

Terminal window
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:

Terminal window
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.

Terminal window
.\scripts\deploy.ps1 -SkipBuild -Tag deploy-20260519-1100

Previous 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)”
Terminal window
cd D:\Projects\LynCareOS
.\scripts\deploy-marketing-pages.ps1

Requires in .env.production:

  • CLOUDFLARE_API_TOKEN
  • CLOUDFLARE_ACCOUNT_ID (for account-scoped API tokens)
  • MARKETING_PREVIEW_SECRET (private-beta gate; synced to Pages binding PREVIEW_SECRET before deploy)

Equivalent manual command:

Terminal window
npx wrangler pages deploy marketing/palliative --project-name lyncareos-marketing --branch main

The marketing gate secret is never committed in _worker.js. Rotate when revoking early-access links or after any leak:

  1. Generate: python -c "import secrets; print(secrets.token_urlsafe(24))"
  2. Set MARKETING_PREVIEW_SECRET in .env.production
  3. Run .\scripts\deploy-marketing-pages.ps1 (pushes secret via Wrangler, then deploys)
  4. Distribute new ?preview=<secret> invitation links — existing preview cookies invalidate

If the Pages project does not exist yet, follow 13-MARKETING-AND-SUBDOMAIN-DEPLOYMENT.md §3–4:

  • DNS: app CNAME → 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

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.

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.


Work through in order.

  • https://lyncareos.com loads marketing page (not app login)
  • https://www.lyncareos.com redirects 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
  • 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 -5 returns 200 and the body’s CACHE_NAME contains a different hash from the previous deploy (grep CACHE_NAME in 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-control returns no-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 check frontend/src/lib/lazyWithReload.ts is 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):

Terminal window
.\scripts\verify-care-module-preview-gate.ps1

The 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):

VariableLocationCurrent launch policy
CARE_MODULE_BOARDS_ENABLEDRoot .env.production + VPStrue (boards deployed)
CARE_MODULE_PREVIEW_USER_IDSRoot .env.production + VPS1 (Peter only)
VITE_CARE_MODULE_BOARDSfrontend/.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):

Terminal window
.\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.


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)

TopicDocument
This folder index00-INDEX.md
Database safety[04 - OPERATIONS/11-DATABASE-SAFETY-AND-MIGRATIONS.md](../04 - OPERATIONS/11-DATABASE-SAFETY-AND-MIGRATIONS.md)
Stripe live flip21-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 DNS13-MARKETING-AND-SUBDOMAIN-DEPLOYMENT.md
Current shipped state04-ROADMAP.md
Backup/restore drill (A5)23-BACKUP-RESTORE-DRILL.md
Provider analysis / tier-3 B299-ARCHIVE/25-PRODUCTION-SERVER-BUILD-AND-PROVIDER-ANALYSIS.md

ScriptPurpose
scripts/deploy.ps1Full app deploy to VPS
scripts/deploy-marketing-pages.ps1Cloudflare Pages deploy (+ sync PREVIEW_SECRET)
scripts/security-review-static.ps1Git-free static security review (Ruff, router SQL, secret scan)
migration-audit.ps1 -Target Vps -NonInteractiveRepo vs VPS migration versions
scripts/production-migration-preflight.ps1PHI backfill before V090
scripts/production-phi-pin.ps1Pin encryption keys on VPS
scripts/push-to-production.ps1Agent default — dev + Docker UAT + deploy (automatic full backup)
scripts/deploy.ps1VPS deploy only (step 2 full backup; keep 10 + 10)
scripts/apply-vps-pending-migrations.ps1Rare VPS migration restart — backup first
scripts/vps-production-backup.ps1Called by deploy/apply — not run by product owner
scripts/pull-vps-backup-to-workstation.ps1Wrapper → vps-production-backup.ps1
scripts/backup-restore-drill-vps-production.ps1 -IUnderstandPhase 3 disaster-restore rehearsal (destructive; ops only)