Skip to content

Ship one nginx file installer for every deploy (CTR-8) - #10

Open
RyanEwen wants to merge 2 commits into
mainfrom
site-install
Open

RyanEwen wants to merge 2 commits into
mainfrom
site-install

Conversation

@RyanEwen

@RyanEwen RyanEwen commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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 to scripts/deploy/install-site-files.sh): runs on the server. Takes --dir, --backups, --container and 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 fails nginx -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 (default false): writes just those two files, for repos with their own deploy. generated.deploy always writes them. A repo taking only siteInstall needs no package.json, so a repo with no Node build can still use devkit-init --check through npx.
  • The generated deploy now uses the helper. Visible to apps after the pin bump: it refuses an already-broken live nginx config instead of installing and rolling back, the site file is always mode 644, and it is sent from the local checkout (the commit being deployed) instead of read from the server checkout. Apps regenerate two new files.

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.8 container (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 when DEVKIT_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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant