Deploy the app on a push to main, and put it back if it fails - #169
Merged
Merged
Conversation
added 2 commits
September 15, 2026 22:12
Migrating reports what it applied. This reports what is there, which is the question the code about to serve traffic has: is anything still pending, has an applied file been edited since, and does every table the store reads exist. Read-only, so it is safe against production and says the same thing twice.
The workflow only ran when somebody remembered to dispatch it, and the last three runs failed on missing configuration, so app/ has been deployed by hand. It now runs on a push to main that touches app/, and nothing else: a change to the CLI, the relay or the site reaches people another way. Failing leaves production alone. The build, the tests and the migration all happen before anything is deployed, and the schema only ever gains things, so a run that stops partway leaves the Worker that is serving untouched. If the new Worker deploys but does not answer, or answers with the previous build, the version that was serving is put back. The database password is no longer a GitHub secret: it is read from Secret Manager with the short-lived identity the deploy already uses, so the one copy is the one the service reads, and this repository -- public -- holds none of it. Configured values reach scripts through the environment rather than being interpolated into them. CI migrates an empty database twice and verifies it, so a migration that only works on a schema that already exists, or that cannot be applied twice, fails there rather than against production.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
deploy-app.ymlruns on a push tomainthat touchesapp/**(or the workflow itself), plus the manual dispatch it already had. A change
to
cmd/shell/**,worker/**orweb/**does not deploy this Worker: thosereach people through the relay Worker and published binaries.
production is touched. Migrations are additive and one transaction per file,
so a run that stops partway leaves the serving Worker against a schema that
only gained things. If the Worker deploys but does not answer, or answers
with the previous
index.html, the version that was serving is rolled back.Manager with the short-lived Workload Identity token the deploy already needs
for the Cloud SQL proxy, and masked before use. One copy, held where the
service reads it, and none of it in a public repository.
npm run db:verify. Read-only: nothing pending, nothing edited sinceit was applied, every table the store reads present. It runs after migrating
and before the Worker goes out.
postgresdatabase onthe Postgres service the app job already runs, then verifies, then does both
again, so a migration that is not re-runnable fails in CI.
Migrations: idempotent, and why not sqitch
Checked rather than assumed, against a real Postgres:
The runner already takes an advisory lock, applies each file in its own
transaction with the
schema_migrationsrow written inside it, and records achecksum so an edited file is refused instead of half-applied. Sqitch would add
a Perl toolchain and a second source of truth to get
deploy/revert/verify;here
deployandverifynow exist, andrevertis deliberately not a thing:migrations only ever add, which is what makes rolling the Worker back safe. A
schema that could be reverted under a running Worker would be the more
dangerous design, not the safer one. Worth revisiting if a destructive change
is ever genuinely needed.
Secrets and variables
Everything needed is listed by the preflight step, which fails naming what is
missing. Required secrets:
CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID,GCP_WORKLOAD_IDENTITY_PROVIDER,GCP_SERVICE_ACCOUNT.DATABASE_URLis nolonger used and can be deleted. One new repository variable,
DATABASE_URL_SECRET, names the Secret Manager resource to read.Leak review
No
pull_request_target,issue_commentorworkflow_runtriggers; nogithub.event.*interpolated into a shell; every action pinned by SHA;persist-credentials: falseon checkout; configured values passed through theenvironment. The deploy is gated on the
productionenvironment.