Address Cody review round 6: executable runbook, static client install, README

CODY-011 deploy/install.sh performs the ownership-sensitive sequence: the
         release is copied to app.new, that one directory is given to the
         hermeven user, npm ci runs unprivileged, and the finished tree is
         handed back to root:root with group/other write removed. Secrets,
         state and model directories are never touched. The guide now gives
         exact commands, including the C/C++ toolchain a clean host needs
         (found by running it on one).
CODY-012 install.sh builds the phone page with the bridge address preset
         and installs it root-owned into /opt/hermeven/www for Caddy. The
         guide explains the web build versus the .ehpk package and when
         each is needed.
CODY-013 README states which commit was deployed, what was checked, and
         what remains unverified.

Also corrects a wrong diagnosis recorded in the previous commit: the phone
page that showed "Browser preview" had been opened in Chrome, not in the
Even app. Host detection keeps a short precautionary wait (2.5 s) and its
comments no longer claim an observed Even-app delay.

tests/deploy/runbook-proof.sh proves the guide on a disposable Ubuntu 24.04
host with systemd.

Not reviewed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 12:28:07 -08:00
co-authored by Claude Fable 5.2
parent e5559dc5e7
commit 65260911ae
8 changed files with 333 additions and 52 deletions
+103 -35
View File
@@ -46,30 +46,64 @@ accurate) and run `fetch-model` again.
## Steps
1. **Droplet and DNS.** Ubuntu LTS. Point a hostname at it (for example `bridge.example.com`).
Firewall: allow 22, 80 and 443 only.
2. **Packages.** Node.js 22.13 or later, git, Caddy.
3. **User and directories.**
Every command below is run as root on the server unless it says otherwise. Replace
`bridge.example.com` with your hostname throughout.
1. **Droplet and DNS.** Ubuntu 24.04. Point a hostname at it. Firewall: allow 22, 80 and 443 only.
The bridge (8787) and the Hermes API (8642) stay on loopback and are never opened.
2. **Packages.** Caddy, git and a C/C++ toolchain from Ubuntu, and Node.js 22 from nodejs.org
with its checksum verified, installed at `/opt/node` (where the unit and the install script
expect it). The toolchain is needed because the SQLite library compiles itself during
`npm ci` when no prebuilt binary is fetched for the machine:
```sh
useradd --system --home /opt/hermeven --shell /usr/sbin/nologin hermeven
mkdir -p /opt/hermeven /etc/hermeven
# The state directory is the service user's alone: mode 0700, set explicitly.
install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven
apt-get update && apt-get install -y caddy git curl xz-utils ca-certificates build-essential python3
V=$(curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt | grep -oE 'v22\.[0-9]+\.[0-9]+' | head -1)
cd /tmp && curl -fsSLO https://nodejs.org/dist/$V/node-$V-linux-x64.tar.xz
curl -fsSL https://nodejs.org/dist/$V/SHASUMS256.txt | grep " node-$V-linux-x64.tar.xz\$" | sha256sum -c -
mkdir -p /opt/node-$V && tar -xJf node-$V-linux-x64.tar.xz -C /opt/node-$V --strip-components=1
ln -sfn /opt/node-$V /opt/node && /opt/node/bin/node -v
```
The bridge also enforces this itself at every start. The directory that holds the database
must be owned by the user the bridge runs as: if it belongs to anyone else (including root)
the bridge refuses to start and leaves the directory exactly as it found it, even if its
mode is already 0700. If the owner is right but the mode is looser, the bridge sets it to
0700. So `-o hermeven` in the command above matters as much as `-m 0700`.
4. **Code.** Put the repository at `/opt/hermeven/app` (a clone, or `git archive <sha> | tar -x`),
then run `npm ci` there as the unprivileged `hermeven` user and hand the tree back to root
afterwards (`chown -R root:root /opt/hermeven/app`), so package install scripts never run as
root and the running service cannot modify its own code. (The dev dependencies are needed:
the bridge runs through `tsx`.) Node.js is expected at `/opt/node/bin/node`.
5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it
in, `chmod 600`, `chown hermeven`.
5a. **Speech model.** As root (not the service user), fetch and verify the pinned model into a
directory the service can read but not write:
3. **Get the release onto the server**, anywhere outside `/opt/hermeven`, for example:
```sh
git clone git@git.xylo.gg:Xylo-Digital/hermeven.git /root/hermeven-src
git -C /root/hermeven-src checkout <the commit you are deploying>
```
(or, from your own machine: `git archive <sha> | ssh root@server 'mkdir -p /root/hermeven-src && tar -x -C /root/hermeven-src'`).
4. **Install the application and the phone page.** One script does the ownership-sensitive part,
so it cannot be done in the wrong order:
```sh
/root/hermeven-src/deploy/install.sh --bridge-url https://bridge.example.com
```
In order, it: creates the `hermeven` system user, `/opt/hermeven`, `/etc/hermeven` and the
state directory (`install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven`); copies the
release to `/opt/hermeven/app.new` and **gives that one directory to `hermeven`**; runs
`npm ci` **as `hermeven`**, so no package install script runs as root; builds the phone page
with your bridge address preset; **gives the finished tree back to `root:root`** and removes
group/other write, so the running service cannot change its own code; installs the built page
into `/opt/hermeven/www` (root-owned, directories 0755, files 0644, readable by Caddy and not
writable by the service); swaps the tree into `/opt/hermeven/app` (keeping the previous one as
`app.old`); and installs the systemd unit without starting it.
It never touches `/etc/hermeven/*` (secrets), `/var/lib/hermeven/*` (state) or
`/opt/hermeven/models` (the speech model); no recursive ownership change reaches them.
The state directory must be owned by the user the bridge runs as. The bridge checks this at
every start: a directory owned by anyone else (including root) is refused and left exactly
as found, even at mode 0700; with the right owner and a looser mode it is set to 0700.
The dev dependencies are installed too: the bridge runs through `tsx`.
5. **Configuration.**
```sh
install -m 0600 -o hermeven -g hermeven /opt/hermeven/app/deploy/bridge.env.example /etc/hermeven/bridge.env
```
Then edit `/etc/hermeven/bridge.env`: set `HERMES_API_KEY` at least.
6. **Speech model.** Fetch and verify the pinned model, as root, into a directory the service can
read but not write:
```sh
cd /opt/hermeven/app/services/bridge
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts fetch-model
@@ -79,24 +113,58 @@ accurate) and run `fetch-model` again.
service never downloads anything: it re-verifies these files each time it loads the model and
refuses to load if one is missing or different. This is the only step that needs outbound
access to huggingface.co.
6. **Hermes.** Enable its API server with a key, bound to `127.0.0.1`. Use a read-only or test
profile first.
7. **Service.** Copy `deploy/hermeven-bridge.service` to `/etc/systemd/system/`, then
`systemctl daemon-reload && systemctl enable --now hermeven-bridge`. Watch
`journalctl -u hermeven-bridge -f` for `stt.ready`. `stt.load_failed` with `reason: missing`
or `mismatch` means step 5a was skipped or the files changed.
8. **TLS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, reload
Caddy, then check `curl https://bridge.example.com/healthz`.
9. **App build.** On your own machine:
`HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`.
10. **Pair.** On the droplet, as the service user with the same environment:
7. **Hermes.** Enable its API server with a key, bound to `127.0.0.1` (see `docs/setup.md`), and
put the same key in `bridge.env`. Use a read-only or test profile first.
8. **Start the bridge.**
```sh
systemctl enable --now hermeven-bridge
journalctl -u hermeven-bridge -f # wait for "stt.ready"
curl http://127.0.0.1:8787/healthz
```
`stt.load_failed` with `reason: missing` or `mismatch` means step 6 was skipped or the files
changed.
9. **HTTPS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, then:
```sh
caddy validate --config /etc/caddy/Caddyfile && systemctl reload caddy
curl https://bridge.example.com/healthz # the bridge, through Caddy
curl -I https://bridge.example.com/ # the phone page: 200, text/html
```
Caddy sends `/v1/*` and `/healthz` to the bridge and serves everything else from
`/opt/hermeven/www`.
10. **Pair.** As the service user:
```sh
cd /opt/hermeven/app/services/bridge
runuser -u hermeven -- env HOME=/var/lib/hermeven HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env \
/opt/node/bin/node --import tsx src/cli.ts pair
```
11. **Origin.** Open the phone page, read Diagnostics, "Page origin", put it in
`HERMEVEN_ALLOWED_ORIGINS`, restart the service.
Open `https://bridge.example.com/` in the Even app (see below) and enter the code.
11. **Allowed origins.** Leave `HERMEVEN_ALLOWED_ORIGINS` empty when the phone page is served
from the bridge's own hostname, as above: the page and the API share one origin, so no
cross-origin allowance is needed and none should be added. Only a page served from somewhere
else (a packaged `.ehpk`, whose origin inside the Even app is not documented) needs its exact
origin listed; read it from Diagnostics, "Page origin".
**Updating.** Repeat steps 3 and 4 with the new commit, then `systemctl restart hermeven-bridge`.
If a model manifest changed, repeat step 6 first.
## The two client artifacts: the web page and the `.ehpk`
Both come from the same source (`apps/even-client`) and you need only one of them at a time.
| Artifact | Made by | Lives | Used for |
|---|---|---|---|
| Web build (`dist/`) | `deploy/install.sh` on the server (`npm run client:build`) | `/opt/hermeven/www`, served by Caddy at `https://bridge.example.com/` | Loading Hermeven in the Even app by scanning a QR code for that address (`npx evenhub qr --url https://bridge.example.com`). This is the developer sideload path: nothing is uploaded to Even. Even's documentation says sideloaded apps stop when the phone locks. |
| Package (`hermeven.ehpk`) | `HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`, on your own machine | Uploaded to Even's portal by you (`evenhub create` / `upload`, then `promote --to beta`) | Installing Hermeven as a real app (beta channel), which is what the locked-phone test needs. The package carries its own copy of the page, with the bridge origin in its network whitelist; it does not use `/opt/hermeven/www`. |
For a first run on the glasses only the web build is needed, and the install script has already
produced it. The `.ehpk` is needed only when you move to a beta-channel install. Keeping the web
page in place afterwards is harmless (it is static and holds no secrets) and useful for
diagnostics, but a server that only serves packaged apps does not need it.
## Things to check on the droplet and write down