staging-ops
Skill6 starsChanged 2 months agoApache-2.0View on GitHub
Conventions for deploying SheetPredict to staging and changing what runs there — deploy.yml, scripts/deploy/on_box.sh, docker-compose.deploy.yml env vars, the staging health probe, nginx-staging.conf. Use before editing any of those, adding a staging env var, or debugging a deploy or a red staging-health run.
- Reads credentials
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
Files
Staging operations
Staging access rules (ssh staging-ts only) are in the root CLAUDE.md. Runbooks: docs/ops/.
- Images are built once, in CI (#831):
scripts/ci/build_images.shis the only builder (PR gate: both images, no push, thencheck_frontend_image_is_host_agnostic.sh;deploy.yml'sbuild-images: push to GHCR by commit SHA). A box never builds:scripts/deploy/deploy_images.shpulls the two digests with the run's ownGITHUB_TOKENin a throwaway docker config (no credential stays on the box, and another app's login is untouched), starts them, then writes.deploy-images.env(commit + digests: the answer to "what is running") and removes this repository's images that are neither running nor the previous deploy's (neverdocker image prune: the box is shared). Its preflight is the new commit's, read withgit showbefore the checkout moves. NoNEXT_PUBLIC_*build arg, no composebuild:, no--build. Guard:test_images_built_once.py. - One compose file, called one way (#831):
docker-compose.deploy.ymlserves staging and production and names neither. Every compose call on a box isscripts/deploy/compose.sh <args>: it setsENVIRONMENTfrom the env file's name (.env.staging→staging; exactly one of the two files per box) and the images andAPP_VERSIONfrom.deploy-images.env. With no record it still runsexec/ps/logsand refusesup/pull/run(the subcommand is the first argument; an option first is refused). Valueson_box.shmust hand a script go inON_BOX_FORWARD, which travel in the body, never on the command line. - Deploys:
deploy.ymlshipsmain→ staging over SSH via the tailnet (HOSTmust be the box's bare tailnet machine name, never the full MagicDNS name, whose suffix a tailnet rename breaks (#1150); labelled the same inSSH_KNOWN_HOSTS; port 22 is firewalled publicly). The health and reconciliation alerts are public issues: a scheduled workflow files only throughscripts/ci/file_alert.sh(redactsHOST,DEPLOY_PATH, the deploy user and tailnet addresses, nothing else; sends the body as a file cut to 65,536 characters, closing an open fence or<details>and logging the whole redacted body between::stop-commands::markers; retriesghonce after 60 s, so the 3-minute report budget assumes twoghcalls; #1215, #1231, #1241,test_file_alert.py) and reports onfailure() || cancelled(); every step before the report that can hang carries its owntimeout-minutes, leaving the report 3 minutes of the job's (test_every_step_that_can_hang_stops_before_the_job_does). GitHub disables schedules after 60 quiet days (docs/ops/STAGING_DEPLOYMENT_GUIDE.md, "A schedule that stopped running").integration-tests.ymlis manual. - Every workflow step reaches the box through
scripts/deploy/on_box.sh(#790, #756), never its ownssh: a repo script or a QUOTED heredoc (<<'REMOTE') reading"$DEPLOY_PATH"from env. It quotes withprintf %qand runs the body from a file with stdin at/dev/null.test_deploy_on_box.pyfails on a rawsshor'$DEPLOY_PATH'in a workflow. - Staging health (#552, #756, #757, #768, #973):
python -m app.health_probe(in the backend container) checks/health/readyplus a fresh Mongo connection, S3, OpenAI andsignups_24h(>SIGNUP_ALERT_THRESHOLD_24His unhealthy); every status must behealthyorhealthy (<detail>), and failures print a class name or HTTP status, never a message.scripts/deploy/frontend_probe.shasks the frontend'sGET /api/health/ready(lib/health/readiness.ts: fresh Mongo connection + a backend-verified minted token) from inside the container; that route must stay unreachable through the edge.staging-health.ymlruns hourly and opens/closes a[P1] [ops]issue deduped onStaging health probe is failing;deploy.ymlgates on/health/readythen the probes. On failure,scripts/deploy/backend_state.shreports container state and an exception-class histogram, never raw log lines (public repo). Credential rotation:docs/ops/CREDENTIAL_ROTATION.md(up -d --force-recreate, neverrestart;test_staging_health_wiring.py). - Subscription reconciliation (#606):
subscription-reconcile.ymlrunspython -m app.billing.reconcile_subscriptions --applyin the backend container daily, over the same path as the health probe. Exit 1 = a row Stripe would not return or one a webhook changed mid-run, 2 = a missing setting, 3 = it did not finish (class name only), 4 = no counts line (it never ran; the container's stderr stays on the box); any of them, or a missing deploy secret (this workflow fails on one, it does not skip), opens a[P2] [billing]issue deduped onSubscription reconciliation is failing, and a clean run closes it. After a Stripe account or key swap every old row reads as unreadable until those rows are removed. Production needs its own job (#771). Guard:test_subscription_reconcile_wiring.py. - Staging env vars (#457, #474): a variable reaches a container only if
docker-compose.deploy.ymllists it.scripts/deploy/preflight_staging_env.shrequires every${VAR:?}there except the fourcompose.shsupplies (so it still runs by hand, before or after a deploy), so mark a new variable${VAR:-}until it is provisioned. Optional passthrough arrives as"": treat blank as unset, and every consumer reads through the same accessor (stripe_client.setting()).RESEND_API_KEYandEMAIL_FROM(#494) are optional this way: with either blank the backend sends no mail and logsEmail: not sending mail (…)at startup.PLAUSIBLE_DOMAIN(#769, frontend only) is optional too: blank counts no visits, and staging leaves it blank. The frontend's public settings (NEXT_PUBLIC_API_URL,NEXT_PUBLIC_SENTRY_DSN,NEXT_PUBLIC_SENTRY_ENVIRONMENT) are container env read per request, so changing one needs a recreate, never a new image.PLAN_*overrides are passed nowhere in deployment (test_plan_limits_are_the_product_values.py); onlyapps/frontend/test-e2e.shsets them. - Edge config (#594, #789, #830, #768):
nginx-staging.confis a template rendered and deployed byscripts/deploy/apply_nginx_conf.sh(placeholders inSUBST_VARSonly,test_nginx_template.py;sed, notenvsubst; no-op untilNGINX_SERVER_NAMEis set; restores the backup ifnginx -tfails;--checkdiffs the box). An edge fix ships only when a deploy runs. The Stripe webhook (POST /webhooks/stripe/webhook, outside/api/v1) needs its ownlocationwithclient_max_body_size(test_nginx_webhook_route.py); it carries a per-addresslimit_conn(narrative_webhook_conn, 20 in flight, refusals 503 so Stripe retries) and never alimit_req, which would throttle Stripe's few addresses (#595,test_nginx_webhook_conn_limit.py). Eachapp/api/**handler needs a frontend location (test_nginx_next_api_routes.py;/api/healthis the exemption)./api/auth/is rate-limited (narrative_authzone;test_nginx_auth_rate_limit.py). Only the production host is indexable (map $host $narrative_robots_tag); nolocation/ifmay declare its ownadd_header(test_nginx_noindex.py). Certificates viacertbot certonly, beforeNGINX_SERVER_NAMEnames the host.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

