agentleFS
frankbriafrankbria/narrative-modeling-app/.claude/skills/staging-ops/SKILL.md

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.

The file

Files
SKILL.md

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.sh is the only builder (PR gate: both images, no push, then check_frontend_image_is_host_agnostic.sh; deploy.yml's build-images: push to GHCR by commit SHA). A box never builds: scripts/deploy/deploy_images.sh pulls the two digests with the run's own GITHUB_TOKEN in 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 (never docker image prune: the box is shared). Its preflight is the new commit's, read with git show before the checkout moves. No NEXT_PUBLIC_* build arg, no compose build:, no --build. Guard: test_images_built_once.py.
  • One compose file, called one way (#831): docker-compose.deploy.yml serves staging and production and names neither. Every compose call on a box is scripts/deploy/compose.sh <args>: it sets ENVIRONMENT from the env file's name (.env.staging → staging; exactly one of the two files per box) and the images and APP_VERSION from .deploy-images.env. With no record it still runs exec/ps/logs and refuses up/pull/run (the subcommand is the first argument; an option first is refused). Values on_box.sh must hand a script go in ON_BOX_FORWARD, which travel in the body, never on the command line.
  • Deploys: deploy.yml ships main → staging over SSH via the tailnet (HOST must be the box's bare tailnet machine name, never the full MagicDNS name, whose suffix a tailnet rename breaks (#1150); labelled the same in SSH_KNOWN_HOSTS; port 22 is firewalled publicly). The health and reconciliation alerts are public issues: a scheduled workflow files only through scripts/ci/file_alert.sh (redacts HOST, 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; retries gh once after 60 s, so the 3-minute report budget assumes two gh calls; #1215, #1231, #1241, test_file_alert.py) and reports on failure() || cancelled(); every step before the report that can hang carries its own timeout-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.yml is manual.
  • Every workflow step reaches the box through scripts/deploy/on_box.sh (#790, #756), never its own ssh: a repo script or a QUOTED heredoc (<<'REMOTE') reading "$DEPLOY_PATH" from env. It quotes with printf %q and runs the body from a file with stdin at /dev/null. test_deploy_on_box.py fails on a raw ssh or '$DEPLOY_PATH' in a workflow.
  • Staging health (#552, #756, #757, #768, #973): python -m app.health_probe (in the backend container) checks /health/ready plus a fresh Mongo connection, S3, OpenAI and signups_24h (> SIGNUP_ALERT_THRESHOLD_24H is unhealthy); every status must be healthy or healthy (<detail>), and failures print a class name or HTTP status, never a message. scripts/deploy/frontend_probe.sh asks the frontend's GET /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.yml runs hourly and opens/closes a [P1] [ops] issue deduped on Staging health probe is failing; deploy.yml gates on /health/ready then the probes. On failure, scripts/deploy/backend_state.sh reports container state and an exception-class histogram, never raw log lines (public repo). Credential rotation: docs/ops/CREDENTIAL_ROTATION.md (up -d --force-recreate, never restart; test_staging_health_wiring.py).
  • Subscription reconciliation (#606): subscription-reconcile.yml runs python -m app.billing.reconcile_subscriptions --apply in 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 on Subscription 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.yml lists it. scripts/deploy/preflight_staging_env.sh requires every ${VAR:?} there except the four compose.sh supplies (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_KEY and EMAIL_FROM (#494) are optional this way: with either blank the backend sends no mail and logs Email: 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); only apps/frontend/test-e2e.sh sets them.
  • Edge config (#594, #789, #830, #768): nginx-staging.conf is a template rendered and deployed by scripts/deploy/apply_nginx_conf.sh (placeholders in SUBST_VARS only, test_nginx_template.py; sed, not envsubst; no-op until NGINX_SERVER_NAME is set; restores the backup if nginx -t fails; --check diffs the box). An edge fix ships only when a deploy runs. The Stripe webhook (POST /webhooks/stripe/webhook, outside /api/v1) needs its own location with client_max_body_size (test_nginx_webhook_route.py); it carries a per-address limit_conn (narrative_webhook_conn, 20 in flight, refusals 503 so Stripe retries) and never a limit_req, which would throttle Stripe's few addresses (#595, test_nginx_webhook_conn_limit.py). Each app/api/** handler needs a frontend location (test_nginx_next_api_routes.py; /api/health is the exemption). /api/auth/ is rate-limited (narrative_auth zone; test_nginx_auth_rate_limit.py). Only the production host is indexable (map $host $narrative_robots_tag); no location/if may declare its own add_header (test_nginx_noindex.py). Certificates via certbot certonly, before NGINX_SERVER_NAME names the host.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.