trtr

Trading simulator and techanalysis gym
git clone https://git.ea.contact/trtr
Log | Files | Refs | README

README.md (2136B)


      1 # trtr
      2 
      3 BTC/USD trading simulator.
      4 
      5 ## Infrastructure
      6 
      7 The application runs on `trtr.ea.contact` behind lighttpd.
      8 
      9 ### Chroot Containers
     10 
     11 trtr is deployed into two minimal chroot containers under `/var/lib/trtr-container-a` and `/var/lib/trtr-container-b`. Each container contains only:
     12 
     13 - The compiled `trtr` binary
     14 - The `frontend/` directory (`index.html`)
     15 - The `data/btc/` CSV dataset
     16 - Required shared libraries copied via `ldd` discovery
     17 - Minimal device nodes (`/dev/null`, `/dev/zero`, `/dev/random`, `/dev/urandom`) and `/tmp`
     18 
     19 No bind mounts or directory passthroughs are used.
     20 
     21 ### Zero-Downtime Deploy
     22 
     23 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.
     24 
     25 On every `git push`, the post-receive hook (`/srv/git/trtr.git/hooks/post-receive`):
     26 
     27 1. Rebuilds the project from a fresh clone in `/tmp/trtr-build` using `cargo build --release`
     28 2. Populates the *staging* chroot container with the new binary, frontend, and data
     29 3. Starts the staging service on the **inactive** port
     30 4. Performs a health check (`curl` to localhost)
     31 5. Flips the lighttpd proxy port in both `/etc/lighttpd/conf-available/trtr.conf` and `/etc/lighttpd/conf-available/ssl-vhosts.conf`
     32 6. Reloads lighttpd gracefully (`systemctl reload lighttpd`)
     33 7. Stops the old active service once traffic has switched over
     34 
     35 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.
     36 
     37 ### Failure Alerts
     38 
     39 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**.
     40 
     41 ### Scripts
     42 
     43 - `/home/debian/scripts/trtr-setup-container.sh` — builds a chroot from a release build directory
     44 - `/home/debian/scripts/trtr-deploy.sh` — orchestrates the blue/green port flip
     45 
     46 ### Stagit
     47 
     48 The same post-receive hook also regenerates the stagit page at `https://git.ea.contact/trtr` after each push.