Operations
CI and release runbook
Current state
Releases are automatic. A push to main that carries a feat, fix or perf
commit derives the next version, proves it, publishes the images and deploys to
https://dev.feelcouch.tech without a manual step. The deployed release is
verifiable from outside: every response carries X-Feelcouch-Release and
/api/version reports the same tag, and the deployment fails and rolls back
when the public URL serves anything else.
Repository Actions variables and secrets for the single production target are
configured. The dedicated root-owned server runner is still not installed; the
deployment uses scripts/deploy-dev.sh over the forced-command SSH gateway.
Workflow map
| Workflow | Trigger | Contract |
|---|---|---|
CI |
Pull request | Language policy, single version source, generated API reference, disposable PostgreSQL migration, typecheck, lint, focused tests |
Security |
Pull request, main push and weekly schedule |
Production dependency audit and repository-safe static checks; GHAS-only jobs are skipped while the repository is private on GitHub Free |
Release |
main push, or manual dispatch to force one |
One job: derives the next version, then proves the tree while it builds the application, assembles the images from that build, and publishes the commit, tag, GitHub Release and version-tagged images before deploying them |
Deploy production |
Called by Release, or guarded manual dispatch |
Verify release digests, run server preflight and backup, run expand migration, start the inactive slot, smoke-test the served release, promote and retain rollback metadata |
Quality checks |
Weekly schedule and manual | Production build, public route smoke, JavaScript budget, container runtime contracts and Compose model validation |
The gate and the application build are independent, so they run at the same time
inside the one job: npm run build:next runs in the background while the checks
and the tests run in the foreground, and the step fails if either does. The
images are built and pushed once, under a commit-scoped candidate tag; the
version tag is added to that same manifest only after the tag is published. A
failed gate therefore leaves no tag, no GitHub Release and no version-tagged
image behind.
All third-party workflow actions are pinned to full commit SHAs. Dependabot may propose reviewed SHA updates. The only accepted production architecture is build once in GitHub Actions and pull by digest on the server. Building source on the VPS is prohibited.
Required GitHub setup
- Create the repository, add
origin, push the release branch and verify GitHub Actions without importing unrelated secrets or history. - Merge only after the CI and Security workflows pass for the final SHA. GitHub Free does not provide protected environments or GHAS checks for this private repository; record the manual owner approval in the release checklist.
- Add repository variables
PRODUCTION_URL,PRODUCTION_SSH_HOST,PRODUCTION_SSH_PORTandPRODUCTION_SSH_USER. - Add repository secrets
PRODUCTION_SSH_KEYandPRODUCTION_SSH_KNOWN_HOSTS. Use a dedicated least-privilege SSH key. Generateknown_hostsfrom a trusted host-key fingerprint, not from an unauthenticated connection inside the workflow. - Give the server a read-only GHCR credential through its root-owned secret store. Never pass a registry token as a process argument or commit it.
- Install and audit
/usr/local/sbin/feelcouch-deploywith the exact root-owned command contract below. Restrict sudo to this executable and the deployment user; do not grant general passwordless sudo.
No custom GitHub token is needed by the workflows. The ephemeral GITHUB_TOKEN
publishes packages and releases. Repository Actions settings must permit
contents: write and packages: write for the release workflow.
Server runner contract
The root-owned runner rejects unknown commands, flags, image registries and
mutable image references. It accepts only the three approved Feelcouch Projects
GHCR packages with sha256 digests and a checksum-verified infrastructure bundle.
| Command | Required behavior |
|---|---|
deploy |
Validate bundle and digests, check capacity, pull images, verify a fresh backup, migrate, start the inactive slot, switch traffic and run route smoke |
rollback |
Start and verify the other configured runtime digest, switch traffic back and retain the expanded schema |
status |
Print the recorded release, active color, container health and public health result |
Migration failure stops before the traffic switch. Readiness, proxy reload or
route-smoke failure attempts an application rollback. Database rollback is not
automatic: release N-1 must remain compatible with the expanded schema from
release N during the rollback window.
Publishing a release
Nothing has to be run by hand. Push a feat, fix or perf commit to main
and the Release workflow does the rest: it derives the next version from the
Conventional Commit prefixes since the last tag, rewrites every derived file,
proves the result, builds and publishes the images, creates the commit, tag and
GitHub Release, and deploys.
Before pushing, the same evidence is available locally, including the checks that CI no longer runs per commit:
npm ci
npm run check:fast
Three manual escape hatches exist:
Releaseaccepts a manual dispatch withforce, which releases a patch even when only chores are pending.Deploy productionaccepts a manual dispatch with an existing tag and its digests, which redeploys or rolls forward without building anything.scripts/deploy-dev.sh rollbackon the host switches traffic back to the other colour.
The release workflow refuses an existing GitHub Release or an existing version tag in any GHCR package. A failed release after publication therefore requires investigation and a new patch version; it must not overwrite artifacts.
A manual deploy on the host is the one way a good release has been lost: it
ships whatever digests the host environment file happens to pin. The host now
refuses to replace a release with an older or unidentifiable image unless
DEV_ALLOW_DOWNGRADE=1 says so on purpose.
Rollback decision
Rollback immediately when readiness fails, smoke tests fail, error rate rises, or the active digest differs from the release record. Pause instead of promoting when migration results are incomplete or capacity is below the runner threshold. Never use an application rollback to hide a destructive or partially applied database migration.
Retention
Nothing in the release path grows without bound. Every depth below is counted, not dated: a count keeps exactly the promised history whether a step runs hourly or not at all for a fortnight, and a dated sweep does neither.
| Artifact | Depth | Enforced by |
|---|---|---|
| Release images in GHCR | 3 newest release tags, plus stable, plus the release the production URL reports |
scripts/prune-registry.mjs on the weekly Quality checks run |
| Release images on the host | 3 newest per repository | prune_release_images at the end of a successful deploy-dev.sh deploy |
| BuildKit layer cache in GHCR | the one live manifest per build target | the same prune, via CACHE_PACKAGE_NAMES |
| Verified daily backups | 14 per database | ops/server/backup-verified.sh |
| Pre-change backups | 3 per host | keep_newest_backups in scripts/deploy-dev.sh |
| Git tags and GitHub Releases | all | kept deliberately: they are the audit trail and cost no storage |
Backups are counted per database, not per host, because every tenant gets its own database in the same cluster. The backup script enumerates the cluster, so a new tenant is retained at full depth without being added to a list.
stable moves only after a deployment answers the public URL with its own
release identity. It is therefore the last release proven in production, which
makes it both the correct thing to pull in a fresh environment and a fixed point
the registry prune must never delete. The prune additionally pins whatever
/api/version reports, so a host left behind on an older release keeps the
image it runs.
The retained image depth is a rollback window, not a cache: rollback needs the release before the active one, and Docker refuses to remove an image a container still references.
The layer cache is the opposite: <repository>-buildcache holds one manifest per
build target, and every export leaves the previous manifest untagged and
unreachable. The prune deletes exactly those untagged versions, and refuses to
run against a package whose name does not end in -buildcache -- in an image
package the untagged versions are the SBOM and provenance manifests that
retained releases still need.
Where the work happens
The release images are copies of a finished build, not builds of their own.
scripts/stage-images.sh assembles two contexts -- build/runtime from the
Next.js standalone output, build/migrator from Prisma, the schema and the three
scripts that image runs -- and each image is a base image, a package install and
one COPY.
The migration context is bundled rather than installed. migrate deploy, the
production seed and the local bootstrap seed each become one file, everything the
bundles leave unreachable is removed from the dependency tree, and COPY --chown
sets ownership on the way in rather than in a second layer holding a second copy
of it. The image went from 1.24 GB to 588 MB, and building it from 26 s to 9 s.
Building inside Docker looked tidier and cost minutes. Every release installed
and built again on a runner that had just done both for the gate, and none of it
carried over: BuildKit cache mounts do not survive a runner, and the layer cache
the bake declared was a silent no-op, because that backend needs a runtime token
which is issued to composite and JavaScript actions and withheld from the run:
steps the bake runs in. One release reused four of its sixty-two layers.
What is cached now is what a runner can actually keep: the installed
node_modules and the Next.js incremental cache, both under actions/cache,
both keyed on a fingerprint that ignores the version the release itself rewrites.
Dockerfile builds the development image and nothing else. A local
docker compose build of the release images needs npm run image:stage first.
What a release costs
Measured on v1.4.6, from the push to the release serving traffic: 196 s to prove and publish, 78 s to deploy and prove the deployment. Where it goes:
| Seconds | Step | What it is |
|---|---|---|
| 110 | Prove the tree, build and push the release candidate | One chain in the background: Next.js build, image staging, then the three-image push with the SBOM scan the rollout contract requires. Every check -- audit, source language, version, docs, lint, migrations, tests, and the typecheck beside them -- runs in the foreground and finishes first. PostgreSQL and the BuildKit builder boot during the install. |
| 47 | Deploy with the rollback guard | Pull, migrate, start the inactive slot, wait for it to report healthy. |
| 20 | Set up Node.js, restore, generate | |
| 19 | Publish the tag, promote the digest, move stable |
Four things set the floor, and none of them is waste:
- The application build is a real compile of a real application. It shrinks when the application does, not when the pipeline is rearranged.
- Three images are built, attested and pushed.
architecture/rollouts.mdbinds the SBOM and provenance; dropping them would buy about 30 s and is a change to that contract, not to this pipeline. - Migrations run against the live database before traffic moves.
- The deployment is proved against the public URL before
stablemoves, and proving takes as long as it takes.
A minute is not reachable while all four hold. What was reachable has been taken: the build no longer happens twice, the checks no longer wait for it, and the images are copies rather than builds.