commit 59fa363f002e5003194799730cdf08b282b6ccda
parent de00864fc83a1fc51631258775b0e15fb76a9a0f
Author: ea <ea@ea.contact>
Date: Sun, 24 May 2026 20:58:05 +0000
docs: add README with Infrastructure section
Diffstat:
| A | README.md | | | 48 | ++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,48 @@
+# trtr
+
+BTC/USD trading simulator.
+
+## Infrastructure
+
+The application runs on `trtr.ea.contact` behind lighttpd.
+
+### Chroot Containers
+
+trtr is deployed into two minimal chroot containers under `/var/lib/trtr-container-a` and `/var/lib/trtr-container-b`. Each container contains only:
+
+- The compiled `trtr` binary
+- The `frontend/` directory (`index.html`)
+- The `data/btc/` CSV dataset
+- Required shared libraries copied via `ldd` discovery
+- Minimal device nodes (`/dev/null`, `/dev/zero`, `/dev/random`, `/dev/urandom`) and `/tmp`
+
+No bind mounts or directory passthroughs are used.
+
+### Zero-Downtime Deploy
+
+Two systemd services — `trtr-a.service` (port 3000) and `trtr-b.service` (port 3001) — run inside their respective chroots. lighttpd proxies `trtr.ea.contact` to whichever port is currently active.
+
+On every `git push`, the post-receive hook (`/srv/git/trtr.git/hooks/post-receive`):
+
+1. Rebuilds the project from a fresh clone in `/tmp/trtr-build` using `cargo build --release`
+2. Populates the *staging* chroot container with the new binary, frontend, and data
+3. Starts the staging service on the **inactive** port
+4. Performs a health check (`curl` to localhost)
+5. Flips the lighttpd proxy port in both `/etc/lighttpd/conf-available/trtr.conf` and `/etc/lighttpd/conf-available/ssl-vhosts.conf`
+6. Reloads lighttpd gracefully (`systemctl reload lighttpd`)
+7. Stops the old active service once traffic has switched over
+
+Because lighttpd handles the switch, existing requests finish on the old instance while new connections go to the new one. There is no interruption in service.
+
+### Failure Alerts
+
+If any step in the build or deploy fails, the hook captures the full log and sends it via Postfix (`/usr/sbin/sendmail`) to **ea@ea.contact**.
+
+### Scripts
+
+- `/home/debian/scripts/trtr-setup-container.sh` — builds a chroot from a release build directory
+- `/home/debian/scripts/trtr-deploy.sh` — orchestrates the blue/green port flip
+
+### Stagit
+
+The same post-receive hook also regenerates the stagit page at `https://git.ea.contact/trtr` after each push.