Repository navigation
feat(publish): store the site snapshot in Workers KV from the API - #8
Merged
Merged
Conversation
The API builds the snapshot in a background publisher, stores it under snapshot:<hash> and latest in Workers KV, then dispatches the publish workflow with the hash. CI downloads it instead of reading Supabase, so SNAPSHOT_DATABASE_URL and the site_reader role go away. The nightly rollover moves into the API, and admins can force POST /site/republish. Closes #7
A forced run now sends client_payload.force, and the publish workflow skips its live-hash check for it. Before, the workflow saw the live site already served the hash and skipped the build, so republish now did nothing.
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 and why
The publish workflow no longer reads Supabase. The API builds the site snapshot, stores it in Cloudflare Workers KV, and fires the publish workflow with the snapshot's hash; CI downloads that snapshot and builds from it. This removes the database credential from GitHub Actions and Go from publish runs, and stays on free plans with no card. R2 was rejected because it needs one. See ADR 0002 and
docs/research/publish-snapshot-source.md.Closes #7
The API publishes the snapshot (
internal/republish):Publisherimplements the existingNotifier, so the middleware andrepublish.Skip()are unchanged.snapshot:<hash>(30-day TTL) and thenlatest, and dispatches withclient_payload.hash.POST /site/republish. That route needs permissionsite.publishand sendsforceso an unchanged snapshot still deploys.KVis a small REST client for Workers KV.SNAPSHOT_KV_*set (local dev), writes dispatch as before.The workflow:
snapshot:<hash>, orlatestfor push and manual runs. It retries for about two minutes because KV is eventually consistent.Also in this PR:
fix(web). The committee "Terms" nav linked to terms with no committee, such as/committee/2019-20, which made the prerender fail with a 404. It now links only to terms that have a committee.How to check it
Run
EKMAN_TEST_DATABASE_URL=postgres://binary:binary@localhost:5433/binarysust?sslmode=disable go test -race ./...inapps/api.cmd/server/publish_test.gocovers write → store → dispatch, boot with KV in sync, bursts, unchanged content, KV failure and retry, the nightly run, republish-now, and the no-KV fallback.Before merging, do the setup in
docs/DEPLOY.mdstep 5, "Snapshot store":/etc/binarysust-api.envand add theSNAPSHOT_KV_NAMESPACE_ID/SNAPSHOT_KV_READ_TOKENsecrets.republish: published snapshot.Without the secrets, publish runs build the fixture and don't deploy.
After one successful publish from KV, delete the
SNAPSHOT_DATABASE_URLsecret and thesite_readerrole (docs/DEPLOY.mdstep 1).Known gaps (from review, deliberately left for later):
cmd/server, notinternal/testapp.Skip()route, a 403 for a non-admin on republish-now, and asserting the error log.NextRolloveris tested.The workflow change has only been checked with actionlint.
Checklist
feat(events): add waitlist emails); it becomes the squash commit.pnpm lint,pnpm typecheckandpnpm testpass locally.pnpm genand committedapps/api/openapi.jsonandpackages/api-client/src/schema.d.ts.NNNN_*.sql); no applied migration was edited. (No migrations.)docs/, READMEs,CONTRIBUTING.md).