Repository navigation
Conversation
Four repos had their own copy of the same server step: compare, back up to site-backups/, install, nginx -t, reload, restore on failure. They had started to drift (only one refused an already-broken live config, only one rolled back a deploy that stopped partway, modes differed). templates/install-site-files.sh is now the one implementation. It runs on the server, takes any number of --file <source> <installed path> pairs that install and roll back as a set, refuses when the live config already fails nginx -t, backs up to a folder the caller names, installs 644, tests, and reloads or restores. A trap puts files back if it stops partway. It never deletes its sources. templates/install-site-files.mjs builds the bash lines a Node deploy needs to send it, with the files, inside one ssh command. devkit-init writes both beside the generated deploy, which now uses them, and alone through the new generated.siteInstall option (default false) for repos with their own deploy. A repo that takes only siteInstall needs no package.json. The generated deploy now sends the site file from the local checkout and refuses an already-broken live config. Tests cover the installer with a fake docker (multi-file rollback, partial stop, refusals, argument checks) and against a scratch nginx:1.29.8 container when DEVKIT_TEST_NGINX=1, which CI now sets.
A restore that hit one missing backup stopped under set -e with the other files still replaced, and the trap path could report "back in place" when an early copy had failed. restore_previous now tries every file and returns non-zero if any failed, and both callers say to check the folder by hand. The Node helper also refuses files too large to travel inside one ssh command (Linux caps one argument at 128 KiB), naming the alternative.
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.
The step "install an nginx file on the shared server: compare, back up to
site-backups/, install,nginx -t, reload, restore on failure" existed in four copies (this repo's generated deploy, and three app repos' own deploys), and they had started to drift. This makes it one generated implementation.What changes
templates/install-site-files.sh(generated toscripts/deploy/install-site-files.sh): runs on the server. Takes--dir,--backups,--containerand any number of--file <source> <installed path>pairs, which install and roll back as one set. It skips everything when nothing differs, refuses when the live config already failsnginx -t, backs up replaced files, installs them 644, tests, then reloads or restores every file (removing new ones) and re-checks the restore. A trap restores files if it stops partway for any other reason. Exit 0 installed or unchanged, 1 nothing installed, 2 usage. It never deletes its sources.templates/install-site-files.mjs(generated beside it):installSiteFilesLines({ files, dir, backups?, container?, failureNote? })returns bash lines that carry the files and the installer inside one ssh command, run the installer as its own process, clean up, and stop the caller with the installer's status.generated.siteInstall(defaultfalse): writes just those two files, for repos with their own deploy.generated.deployalways writes them. A repo taking onlysiteInstallneeds nopackage.json, so a repo with no Node build can still usedevkit-init --checkthroughnpx.Tests
Fake-docker tests cover multi-file rollback, a stop partway through installing, the broken-live-config refusal, a failed reload, argument refusals and the Node helper. A real-nginx test runs the installer against a scratch
nginx:1.29.8container (no network, 128 MB): a site plus include install and reload, a broken include rolls both files back and the restored config passes, and a broken live config is refused. It runs whenDEVKIT_TEST_NGINX=1, which CI now sets. A mutation check (removing the restore) fails three tests including the real-nginx one. shellcheck v0.11.0 is clean.Not released: the release and the consumers' adoption follow separately.
AI disclosure: this comment and the related code were written with the assistance of AI.