Files
hermeven/docs/deploy-droplet.md
T
2026-11-21 13:34:42 -08:00

184 lines
10 KiB
Markdown

# Running the bridge on a DigitalOcean droplet
**Status: run once, on 2026-11-21**, on the existing Hermes droplet rather than a new one. What
was actually done, including where it differed from the steps below, is recorded in
`docs/evidence/droplet/2026-11-21.md`. The steps below have been corrected to match.
## What runs where
```
phone (Even app) --HTTPS--> Caddy :443 --> bridge 127.0.0.1:8787 --> Hermes 127.0.0.1:8642
|
built-in Whisper (in the bridge process)
```
The bridge listens on loopback only. Caddy is the only thing exposed, and it provides the
certificate. Speech is transcribed inside the bridge, so recordings never leave the droplet.
Hermes can run on the same droplet (shown above) or elsewhere; if elsewhere, `HERMES_BASE_URL`
must be `https://`.
## Sizing
Measured on the development desktop (Intel i7-13850HX), bridge with `whisper-base`, 8-bit
weights:
| Measurement | Value |
|---|---|
| Memory after loading the model | about 0.5 GB |
| Memory after transcribing | about 0.8 GB |
| 11 s of speech, process pinned to one core | about 1.7 s |
| Same, `whisper-tiny` | about 1.2 s, about 0.6 GB |
| Model download at deploy time (`fetch-model`) | 79 MB (`whisper-base`), 4 s on the desktop's connection |
| Longest pause of the bridge's event loop while transcribing | 3 ms (the model runs in a worker thread) |
Pinning to one core made no difference to speed, so extra cores will not help; a single droplet
vCPU is the relevant unit. **A shared droplet vCPU is slower than that desktop core by an amount
that has not been measured.** If it were three times slower, 11 s of speech would take about 5 s,
well inside the 30 s deadline.
Suggested starting point, to be confirmed by measuring on the droplet: **2 GB RAM, 1 to 2 vCPU**
for the bridge alone. 1 GB is likely too tight alongside the OS. If Hermes shares the droplet,
add whatever Hermes needs; that was not measured.
If transcription is too slow on the droplet, set `STT_MODEL=whisper-tiny` (faster, less
accurate) and run `fetch-model` again.
## Steps
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
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
```
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
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts verify-model
```
Every file is checked against the SHA-256 committed in `services/bridge/models/`. The running
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.
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
```
Open `https://bridge.example.com/` in the Even app (see below) and enter the code.
11. **Allowed origins.** A page served from the bridge's own hostname (the QR sideload path)
shares the API's origin and needs no entry. An app **installed** through Even Hub does: the
Even phone app serves it from `http://127.0.0.1:<port>` and uses a different port on each
launch (seen on a real phone: 40315, then another), so no exact origin can be listed. Set
`HERMEVEN_ALLOWED_ORIGINS=http://127.0.0.1:*`, the one wildcard the bridge accepts: any port,
loopback only, plain http only. It lets a page running on the phone itself read the bridge's
replies; it grants no access, since every request still needs the device credential.
**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
- Time from `stt.loading` to `stt.ready`, and memory of the service after a few questions.
- `transcribe_ms` for a few real questions (the phone page shows it per question).
- That `curl http://<droplet-ip>:8787/healthz` from outside **fails** (bridge not exposed).
- `stat -c '%a' /var/lib/hermeven /var/lib/hermeven/hermeven.sqlite*` shows `700` and `600`.
- That the unit's hardening options do not stop the model loading. `ProtectSystem=strict` and
`MemoryMax` in particular are untested with ONNX Runtime.
## Not covered yet
Backups of `/var/lib/hermeven`, log rotation, upgrades, monitoring, and a compiled build that
would remove the need for dev dependencies on the droplet.