Repository navigation
ci(deploy): deploy main to production from a manual workflow - #81
Merged
Merged
Conversation
gh workflow run deploy.yml checks the commit is on main with green CI, then SSHes to the host with a key whose forced command is scripts/deploy.sh. The script builds in a second checkout, restarts Hocus, swaps .next and puts the old build back if Next.js does not answer.
…first run The script now fails before touching anything if bun, git, flock or curl is missing from the forced-command session's PATH, and runs as one function so a fast-forward cannot change it mid-run. The runbook adds the host checks, the main-only environment policy and the one-time pull that puts deploy.sh on the host before the first run.
# Conflicts: # CHANGELOG.md
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
A manual Deploy workflow for production,
.github/workflows/deploy.yml:On the runner (it never checks out or runs repo code; read-only token plus
actions: read):mainor whoseci.ymlrun onmaindidn't pass (it waits for a run still in progress);On the host, the key's
authorized_keysentry isrestrict,command="…/scripts/deploy.sh", so the key can only runscripts/deploy.sh. The script:origin/main;ecosystem.config.cjs, then swaps.next(keeping.next.prev) and restarts Next.js;Deploys are serialised by the workflow's concurrency group and a
flockon the host.Tests
tests/unit/ci/deploy-script.test.ts: the script is executable, and it rejects every non-SHA input (injection attempts included) with exit 2 before running anything.deploy.yml: read-only default token, no unpinned actions.shellcheckandactionlintare clean.bun run check,lint,typecheckandtestpass.Deploy note (one-time, operator)
These steps are in
docs/operations/deploy-runbook.md:ecosystem.config.cjs;productionenvironment, limited tomain, withDEPLOY_HOST,DEPLOY_USER,DEPLOY_SSH_KEYandDEPLOY_KNOWN_HOSTS(plusDEPLOY_PORTif needed);git pull --ff-onlyon the host, sodeploy.shexists before the first run.Builds on #80, so the highlight-rewrite flag is in the file every deploy restarts from.