feat(deploy): one-command deploy of the App and the Daemon #3

Merged babariviere.com
targeting main from feat/deploy-one-command-deploy-of-the-app-and-the-daemon
Merged opened by babariviere.com
targeting main from feat/deploy-one-command-deploy-of-the-app-and-the-daemon

Summary #

just deploy runs scripts/deploy.sh. It always deploys the Owner's Pilot and ignores PILOT_PROFILE.

deploy
  check Node >= 22.19              # else: clear message, nothing changes
  nsh package --target macos       # ad hoc signed Pilot.app
  stage program.next + npm ci      # a failure here leaves the old Daemon running
  readOrCreateAddress('owner')     # daemon.json: created once, kept on upgrade
  launchctl bootout
  fail if the port still answers   # another program holds 47110
  program.next -> program
  write LaunchAgent (RunAtLoad, KeepAlive, PATH, log)
  launchctl enable + bootstrap
  replace /Applications/Pilot.app  # a running App is closed, then opened again
  wait until the Daemon answers 426
 ~/Library/Application Support/com.babariviere.pilot/
   daemon.json        # kept
   pilot.sqlite       # kept
+  program/           # the Daemon's code, replaced on each deploy
+~/Library/LaunchAgents/com.babariviere.pilot.daemon.plist
+~/Library/Logs/com.babariviere.pilot/daemon.log

The token code moved from daemon/src/main.ts to daemon/src/address.ts. The deploy and the Daemon use the same code. The Daemon still creates the file on its first start, because the development Daemon needs that.

Evidence #

  • Before: there was no deploy. The Daemon ran only from npm --prefix daemon start. After: daemon/test/deploy.test.ts runs the script in a throwaway home, with fake nsh, npm, launchctl and curl:
    ✔ the deploy fails with a clear message when Node is older than 22.19, and installs nothing
    ✔ a first deploy installs the App, creates the Daemon's token and starts the Daemon at login under launchd
    ✔ a second deploy upgrades both and keeps the Daemon's token and data
    ✔ a deploy that fails before the restart leaves the installed Daemon as it was
    ✔ the deploy fails with the log's path when the Daemon does not answer
    ✔ the deploy fails when another program already listens on the Daemon's port
    
    just check passes. just test passes: 11 Daemon tests and 24 App tests.
  • On a real Mac: the first real deploy failed with Bootstrap failed: 5. An older app had left the label disabled. After adding launchctl enable:
    just deploy             -> Pilot is deployed. Its Daemon listens on 127.0.0.1:47110
    kill -9 <daemon pid>    -> launchd started a new pid
    just deploy (x2)        -> daemon.json unchanged, pilot.sqlite kept
    lsof :47110             -> node <-> Pilot, connected
    

Merge Danger #

Door: two-way

The deploy only writes Pilot's own files. To undo it: launchctl bootout gui/$UID/com.babariviere.pilot.daemon, then delete the plist, program/ and Pilot.app. Running just deploy again upgrades both.

Blast Radius: local

Only the Owner's Mac and CI. The Daemon's CI job now installs gnused. Known limits:

  • The agent runs the node and the PATH found at deploy time. After you change Node, deploy again.
  • Nothing rotates daemon.log.
  • Each ad hoc signature is new, so macOS may ask again for the notification permission after an upgrade.
Commits 1

feat(deploy): one-command deploy of the App and the Daemon
Sign up or Sign in to add to the discussion.