Skip to content

Hosted deployment

The hosted application runs on Cloudflare Workers with D1, R2, static web assets, and Cloudflare Email Service. The application and API are served same-origin at https://app.commitmentdesk.com, with the API under /v1. The public documentation site at https://commitmentdesk.com is deployed separately; see documentation site.

Deployment is manual and owner-approved. Pull-request CI has no production credentials and cannot deploy.

Environment Worker D1 database R2 bucket Host
Development local Wrangler local D1 local R2 http://localhost:8787
Staging commitment-desk-api-staging commitment-desk-staging commitment-desk-attachments-staging https://app-staging.commitmentdesk.com
Production commitment-desk-api commitment-desk commitment-desk-attachments https://app.commitmentdesk.com

inbox.commitmentdesk.com is a permanent redirect to the application host and preserves path and query. See ADR 0011.

  • Cloudflare Workers Paid, which is required for arbitrary email recipients and included D1/R2 usage.
  • An account-owned Cloudflare API token scoped to commitmentdesk.com with Workers Scripts, Workers Routes, Workers R2 Storage, D1, Cloudflare Pages, Email Sending, DNS, SSL and Certificates, Zone Settings, Single Redirect, and read/analytics permissions.
  • The GitHub production environment with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets.
  • Cloudflare Email Service onboarding for commitmentdesk.com. See email delivery.

Never commit the token. Store it in the password manager and the protected GitHub environment.

Create remote resources once per environment:

Terminal window
pnpm --filter @commitment-desk/api exec wrangler d1 create commitment-desk-staging
pnpm --filter @commitment-desk/api exec wrangler d1 create commitment-desk
pnpm --filter @commitment-desk/api exec wrangler r2 bucket create commitment-desk-attachments-staging
pnpm --filter @commitment-desk/api exec wrangler r2 bucket create commitment-desk-attachments

Put the returned D1 ids into the matching env.staging and env.production blocks in apps/api/wrangler.jsonc. Keep the staging and production ids distinct.

Each Wrangler environment sets:

  • ENVIRONMENT=production so session cookies are Secure and HttpOnly.
  • WEB_BASE_URL to the environment’s own HTTPS origin.
  • EMAIL_FROM, EMAIL_FROM_NAME, and EMAIL_REPLY_TO.
  • The send_email binding restricted to [email protected].
  • The environment’s D1 and R2 bindings.
  • Workers Static Assets from apps/web/dist, with /v1 and /v1/* routed to the Worker first.

The Worker has no application secret bindings: sessions are random tokens stored hashed in D1, and API keys and webhook secrets are generated per tenant.

Build the web app first, then apply migrations before deploying the Worker:

Terminal window
pnpm --filter @commitment-desk/web build
pnpm --filter @commitment-desk/api exec wrangler d1 migrations apply DB --remote --env staging
pnpm --filter @commitment-desk/api exec wrangler d1 migrations apply DB --remote --env production

Migrations are ordered by filename in infra/cloudflare/migrations. A failed migration stops the deployment before traffic switches; fix forward or restore the previous Worker version as described under rollback.

Use the manual Deploy hosted app workflow from main. Choose staging or production, type deploy, and approve the production environment if the repository plan supports required reviewers. The workflow builds the web assets, applies migrations, deploys the Worker and assets, records the commit and Worker version, seeds the synthetic demo tenant, and runs the smoke check.

The equivalent operator commands are:

Terminal window
pnpm --filter @commitment-desk/web build
pnpm --filter @commitment-desk/api exec wrangler d1 migrations apply DB --remote --env production
pnpm --filter @commitment-desk/api exec wrangler deploy --env production

Pull-request CI does not have deployment credentials and cannot deploy. The workflow is the only automated path to production.

  • app.commitmentdesk.com is a Worker custom domain attached by Wrangler.
  • app-staging.commitmentdesk.com is the staging custom domain.
  • inbox.commitmentdesk.com has a proxied placeholder DNS record and a Cloudflare Single Redirect rule to https://app.commitmentdesk.com, preserving path and query.
  • commitmentdesk.com is owned by the documentation Pages project, not the Worker.

Verify:

Terminal window
curl -fsS https://app.commitmentdesk.com/v1/health
curl -fsSI https://inbox.commitmentdesk.com/some/path?q=1

The redirect must return a 301 to https://app.commitmentdesk.com/some/path?q=1.

The smoke script verifies health, reviewer session, capture submission, parcel review, export, and a signed webhook delivery against a dedicated synthetic tenant. It mints short-lived operator sessions directly in D1 and removes them afterwards; it does not send magic-link email.

Terminal window
node scripts/seed.mjs --remote --env staging
SMOKE_WEBHOOK_URL=https://example.com/webhook pnpm smoke:hosted:staging
node scripts/seed.mjs --remote --env production
SMOKE_WEBHOOK_URL="$SMOKE_WEBHOOK_URL" pnpm smoke:hosted:production

The Deploy hosted app workflow passes SMOKE_DEMO_API_KEY and the SMOKE_WEBHOOK_URL repository variable to the same scripts. If SMOKE_WEBHOOK_URL is unset, the webhook portion is skipped with a warning; production deployments should keep it set to a receiver that verifies the X-CommitmentDesk-Signature header.

.github/workflows/hosted-health.yml runs every fifteen minutes and on demand. It checks /v1/health, recent Worker errors from Cloudflare analytics, final webhook failures in the last hour, and upload bytes in the last day. A failure opens or updates a Hosted deployment health alert issue labeled ops-alert; recovery comments and closes it.

Workers observability is enabled in every environment. Logs identify tenant and request identifiers where appropriate and never contain capture payloads, attachment contents, tokens, or credentials.

Before a risky migration, export the database:

Terminal window
pnpm --filter @commitment-desk/api exec wrangler d1 export commitment-desk --remote --env production --output backup.sql

D1 Time Travel provides point-in-time restore for the recent window. Keep R2 object versioning or replication enabled, keep the bucket private, and rehearse a restore into staging before accepting client data. After a restore, run the smoke check against the restored environment.

  1. Stop the deployment before traffic switches if a migration fails.

  2. Roll back to the previous Worker version:

    Terminal window
    pnpm --filter @commitment-desk/api exec wrangler rollback --env production
  3. Do not drop production tables. Fix forward with a new migration when possible.

  4. Re-run the smoke check and record the incident and version.

Use the remote seed command with the target environment to create or refresh a normal synthetic demo tenant and explicit demo memberships:

Terminal window
CD_DEMO_API_KEY="$SMOKE_DEMO_API_KEY" node scripts/seed.mjs --remote --env production

The generated API key is written to .remote-demo-<environment>.json (gitignored) or supplied through CD_DEMO_API_KEY; keep it in the secret manager, never in the repository. Demo data is isolated by tenant and contains no real taxpayer information. A public demo host with automated reset remains a separate change.