Files
encyclopedia-knowledge-graph/docs/VPS-AND-GIT-OPERATOR-DEPLOYMENT-GUIDE.md
T

233 lines
17 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Production VPS & Git Operator Deployment Guide (`v2.0.0` Major Milestone Release — Direct Per-Repository Install Directory & Untracked `.gitignore` Artifact Edition)
- **Document ID:** `VPS-AND-GIT-OPERATOR-DEPLOYMENT-GUIDE` (`v2.0.0`)
- **Target Domain:** `https://hyperstitionstud.io` (and `https://www.hyperstitionstud.io` -> `308` redirect)
- **Upstream Git Forge:** `git.libre.audio` (`https://git.libre.audio/seasharp/<repo-slug>.git`)
- **Bundled Deployment Automation (`hyperstitionstudio-core/deploy/`):**
- `deploy/sync-vps-repos.sh` — Pulls from `git.libre.audio`, automatically supplies untracked `haiperdohp-jemaytreeah/.gitignore` runtime files (`config.js`, `db.json`, `db_lite.json`) if absent, runs `hs-doctor` and 6-gate Knowledge Graph verification, syncs per-repo install directories into RAM (`/var/www/hyperstitionstud.io/repos`), creates relative route symlinks (`/`, `/learn`, `/quant`, `/graph`, `/encyclopedia`, `/zoology`, `/archive`, `/calc`, `/ci`, `/schemas`), pre-compresses `.br` (Brotli-11) and `.gz` (Gzip-9) sidecars, and idempotently syncs `Caddyfile`, `systemd` units, and `/etc/logrotate.d/hyperstition-sqlite-meta`.
- `deploy/Caddyfile` — Production Caddy 2 configuration (`HTTP/3 QUIC` + `precompressed br gzip` + direct per-repo `handle_path` routing + `/mcp` and `/api/v1/*` reverse proxy to `127.0.0.1:8095`).
- `deploy/hyperstition-tmpfs-sync.service` — `systemd` unit that hydrates `/var/www/hyperstitionstud.io/repos` on VPS boot before Caddy starts.
- `deploy/hyperstition-mcp.service` — `systemd` unit running `hs-mcp --transport http --host 127.0.0.1 --port 8095` in strict read-only mode while populating `/tmp/hyperstition-api-telemetry.db` (`HYPERSTITION_SQLITE_MAX_MB=100`).
- `deploy/logrotate.d/hyperstition-sqlite-meta` — Quiescent `logrotate.d` rule (`size 100M` default, `rotate 12`, `compress`, `delaycompress`, configurable via `HYPERSTITION_SQLITE_MAX_MB` / `HYPERSTITION_SQLITE_MAX_BYTES`) that compresses a consistent point-in-time SQLite snapshot (`<db>.1.gz` .. `<db>.12.gz`) and truncates the active SQLite REST/MCP API metadata database via `hs-db-build --truncate-quiescent --compress-archive` (`BEGIN EXCLUSIVE` + `PRAGMA wal_checkpoint(TRUNCATE)` + `VACUUM` + `PRAGMA integrity_check`).
- `deploy/test-first-deployment.sh` — Automated static route + `/mcp` + `/api/v1/*` + SQLite `logrotate.d` quiescent truncation verification harness.
- **Bundled CLI Entrypoints (`hyperstitionstudio-core/pyproject.toml`):** `hs-doctor`, `hs-citations`, `hs-pdf-build`, `hs-kg-build`, `hs-quant-harvest` (`--mode us-closing-bell` default), `hs-mcp`, `hs-sync-version`, and `hs-db-build`.
---
## 1. Master 1-to-1 Mapping: `git.libre.audio` Repository -> VPS Install Dir -> Web Route
Each sibling repository on `git.libre.audio` is cloned into `/srv/hyperstitionstud.io/repos/<repo-slug>` on NVMe and synced 1-to-1 into the `512 MB` RAM-backed `tmpfs` mount at `/var/www/hyperstitionstud.io/repos/<repo-slug>`:
| # | Repository Slug (`seasharp/<repo>`) | Public HTTPS Clone URL (`git.libre.audio`) | Persistent VPS Clone (`/srv/hyperstitionstud.io/repos/*`) | Direct Web Route(s) on `https://hyperstitionstud.io` |
| :- | :--- | :--- | :--- | :--- |
| **1** | `hyperstitionstudio-core` (`v2.0.18`) | `https://git.libre.audio/seasharp/hyperstitionstudio-core.git` | `/srv/hyperstitionstud.io/repos/hyperstitionstudio-core` | • `/` (`site/index.html` Portal Homepage)<br/>• `/learn/*` (`site/learn/index.html` + `learn-app.js` Interactive Curriculum)<br/>• `/quant/*` (`site/quant/index.html` + `quant-app.js` + `quant-timeseries-data.js` Interactive Time-Series Workbench & TradingView Launcher)<br/>• `/schemas/*` (`schemas/v1/*.schema.json`)<br/>• `/mcp` & `/api/v1/*` (Stateless Read-Only MCP JSON-RPC & REST API v1 + `/api/v1/openapi.json` on `127.0.0.1:8095`)<br/>*(Note: `/gallery/*` is staged in `site/gallery/` as a long-term plan and disabled in `Caddyfile`/`sync-vps-repos.sh` for now)* |
| **2** | `ingglish-hyperdope-gematria` (`main`) | `https://git.libre.audio/seasharp/ingglish-hyperdope-gematria.git` | `/srv/hyperstitionstud.io/repos/ingglish-hyperdope-gematria` | • `/archive/*` (`ingglish-aq-archive/`) |
| **3** | `technocapital-singularity-zoology` (`v1.7.0`) | `https://git.libre.audio/seasharp/technocapital-singularity-zoology.git` | `/srv/hyperstitionstud.io/repos/technocapital-singularity-zoology` | • `/encyclopedia/*` (`encyclopedia/`)<br/>• `/technocapital-singularity-zoology/*` (sibling PDF link target)<br/>• `/zoology/*` (root reports, tier list, glossary, `dossiers/`) |
| **4** | `encyclopedia-knowledge-graph` (`v1.0.0`) | `https://git.libre.audio/seasharp/encyclopedia-knowledge-graph.git` | `/srv/hyperstitionstud.io/repos/encyclopedia-knowledge-graph` | • `/graph/*` (`index.html`, `graph-data.js`, `atlas-mode*.png`, `.json`, `.graphml`, `.gexf`, `.canvas`, `docs/`) |
| **5** | `haiperdohp-jemaytreeah` (`main`) | `https://git.libre.audio/seasharp/haiperdohp-jemaytreeah.git` | `/srv/hyperstitionstud.io/repos/haiperdohp-jemaytreeah` | • `/calc/*` (`index.html`, `config.js`, `calc/*.js`, `db.json`, `db_lite.json` — confluence of `hyperdope-ci-build` output & upstream `hyperdope-gematria`) |
| **6** | `ingglish-hyperdope-ci` (`feat/ingglish-aq-corpus`) | `https://git.libre.audio/seasharp/ingglish-hyperdope-ci.git` | `/srv/hyperstitionstud.io/repos/ingglish-hyperdope-ci` | • `/ci/*` (`ONBOARDING-INGGLISH-AQ.pdf`, `ci-audit-report.json`, `db.txt`, `db_ingglish_entries.txt`) |
---
## 2. Supplying Untracked Runtime Files Listed in `haiperdohp-jemaytreeah/.gitignore`
Because `haiperdohp-jemaytreeah/.gitignore` intentionally excludes three runtime files from Git version control to avoid bloating repository clones with `100 MB` of compiled JSON binaries, a fresh `git clone` of `haiperdohp-jemaytreeah` must be supplied with those three files before serving `/calc/`:
| Untracked File in `haiperdohp-jemaytreeah/.gitignore` | Size | Tracked Source File in Git | How It Is Supplied for `/calc/*` |
| :--- | :--- | :--- | :--- |
| **`config.js`** | `3.3 KB` | `config.default.js` | Copied directly from `config.default.js`:<br/>`cp config.default.js config.js` |
| **`db.json`** | `80.7 MB` | `db.txt` (`231,615` entries) + `tools/generate_db_json.py` | Precomputed 82-cipher JSON database; generated by running:<br/>`python3 tools/generate_db_json.py db.txt db.json` |
| **`db_lite.json`** | `19.4 MB` | `db.txt` (`231,615` entries) + `tools/generate_db_json.py` | Precomputed 16-cipher progressive first-paint database; automatically written alongside `db.json` by the same `python3 tools/generate_db_json.py db.txt db.json` command. |
Operators can supply these three untracked files on the target machine using **either Option A (Self-Contained Local Generation)** or **Option B (Direct `rsync` from Workstation)**:
- **Option A — Generate on the Target Machine / VPS from Tracked Git Files (Automatic in `sync-vps-repos.sh`):**
```bash
cd /srv/hyperstitionstud.io/repos/haiperdohp-jemaytreeah
cp -n config.default.js config.js
python3 tools/generate_db_json.py db.txt db.json
cd /srv/hyperstitionstud.io/repos
```
*(Note: `deploy/sync-vps-repos.sh` checks for `config.js`, `db.json`, and `db_lite.json` automatically and runs both commands if any of the three files is missing).*
- **Option B — Fast `rsync` Transfer of Pre-Built Files from Workstation to VPS (Skips ~3-Min CPU Build):**
```bash
rsync -avP /workspace/haiperdohp-jemaytreeah/{config.js,db.json,db_lite.json} \
<user>@<LINODE_IP>:/srv/hyperstitionstud.io/repos/haiperdohp-jemaytreeah/
```
---
## 3. Testing the First Deployment Locally (Zero VPS / Zero Root Required)
Before touching a production VPS, any operator or new user can test the complete deployment hydration, untracked `haiperdohp-jemaytreeah` file check (`config.js`, `db_lite.json`, `db.json`), route mapping, and all 28 portal & deep-link routes locally in **one command**:
```bash
# Hydrates /tmp/hyperstition-live-repos, starts a local HTTP server on 127.0.0.1:18090,
# and verifies HTTP 200 OK across all 28 routes (including /calc/config.js, /calc/db_lite.json, /calc/db.json):
./hyperstitionstudio-core/deploy/test-first-deployment.sh
```
To keep the hydrated local deployment running on `http://127.0.0.1:8090` for interactive browser inspection:
```bash
LIVE_REPOS=/tmp/hyperstition-live-repos ./hyperstitionstudio-core/deploy/sync-vps-repos.sh --no-pull
python3 -m http.server 8090 --bind 127.0.0.1 --directory /tmp/hyperstition-live-repos
# Open in browser: http://127.0.0.1:8090/
```
---
## 4. Production Linode / Akamai VPS First Deployment (Sequential Steps 1–7)
Follow Steps 1 through 7 in order on a fresh **Debian 12 (Bookworm)** or **Ubuntu 24.04 LTS** Linode VPS (`2 GB` or `4 GB` RAM plan):
### Step 1: Push Latest Verified Commits to `git.libre.audio` (On Workstation)
```bash
./push-all-to-git-libre-audio.sh
```
### Step 2: Configure Linode Cloud Firewall & DNS Records
1. **Linode Cloud Firewall:** Allow inbound `TCP 443`, `UDP 443` (**HTTP/3 QUIC**), `TCP 80`, and restricted `TCP 22`.
2. **Linode DNS Manager (`hyperstitionstud.io`):**
- `A` (`@` and `www`) -> `<LINODE_IPV4>`
- `AAAA` (`@` and `www`) -> `<LINODE_IPV6>`
- `CAA` (`@`) -> `0 issue "letsencrypt.org"`
- `HTTPS` (`@`) -> `1 . alpn="h3,h2"`
### Step 3: Refresh Caddy GPG Keyring, Install OS Packages & Apply Kernel TCP BBR / QUIC Tuning (On VPS)
```bash
# Refresh Caddy's official Cloudsmith GPG keyring (resolves rotated key ABA1F9B8875A6661 if present)
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor --yes -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null
sudo chmod a+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg /etc/apt/sources.list.d/caddy-stable.list
sudo apt update && sudo apt install -y git python3 python3-venv python3-pip brotli rsync curl logrotate caddy fonts-dejavu-core
sudo tee /etc/sysctl.d/99-hyperstition-fastnet.conf >/dev/null <<'EOF'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_slow_start_after_idle = 0
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 2097152
net.core.wmem_default = 2097152
EOF
sudo sysctl --system
```
### Step 4: Create Persistent Repo Root (`/srv/...`) & RAM-Backed `tmpfs` Mount (`/var/www/...`)
```bash
sudo mkdir -p /srv/hyperstitionstud.io/repos /var/www/hyperstitionstud.io/repos
sudo chown -R "$USER:$USER" /srv/hyperstitionstud.io
# Add 512 MB tmpfs mount to /etc/fstab (idempotent) and mount immediately
grep -q '/var/www/hyperstitionstud.io/repos' /etc/fstab || \
echo 'tmpfs /var/www/hyperstitionstud.io/repos tmpfs defaults,size=512M,mode=0755 0 0' | sudo tee -a /etc/fstab
sudo mount -a
```
### Step 5: Clone All 6 `git.libre.audio` Repositories, Supply `.gitignore` Files & Initialize `.venv`
```bash
cd /srv/hyperstitionstud.io/repos
FORGE_HTTPS="https://git.libre.audio/seasharp"
git clone "${FORGE_HTTPS}/hyperstitionstudio-core.git"
git clone "${FORGE_HTTPS}/ingglish-hyperdope-gematria.git"
git clone "${FORGE_HTTPS}/technocapital-singularity-zoology.git"
git clone "${FORGE_HTTPS}/encyclopedia-knowledge-graph.git"
git clone "${FORGE_HTTPS}/haiperdohp-jemaytreeah.git"
git clone -b feat/ingglish-aq-corpus "${FORGE_HTTPS}/ingglish-hyperdope-ci.git"
# Supply untracked runtime files listed in haiperdohp-jemaytreeah/.gitignore (config.js, db.json, db_lite.json)
cp haiperdohp-jemaytreeah/config.default.js haiperdohp-jemaytreeah/config.js
(cd haiperdohp-jemaytreeah && python3 tools/generate_db_json.py db.txt db.json)
cp hyperstitionstudio-core/workspace.example.toml ./workspace.toml
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install -r hyperstitionstudio-core/requirements.txt
.venv/bin/pip install --no-deps -e ./hyperstitionstudio-core
# Verify environment & all 6 Knowledge Graph CI gates
.venv/bin/hs-doctor
.venv/bin/python3 hyperstitionstudio-core/tests/test_core_suite.py
```
### Step 6: Hydrate RAM Mount, Enable Boot Persistence & Reload Caddy
```bash
# 1. Hydrate /var/www/hyperstitionstud.io/repos and pre-compress (.br / .gz)
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh --no-pull
# 2. Install systemd boot-time tmpfs hydration unit, read-only MCP HTTP server unit (127.0.0.1:8095), and quiescent SQLite logrotate rule
sudo cp /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/hyperstition-tmpfs-sync.service \
/etc/systemd/system/hyperstition-tmpfs-sync.service
sudo cp /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/hyperstition-mcp.service \
/etc/systemd/system/hyperstition-mcp.service
sudo cp /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/logrotate.d/hyperstition-sqlite-meta \
/etc/logrotate.d/hyperstition-sqlite-meta
sudo chmod 0644 /etc/logrotate.d/hyperstition-sqlite-meta
sudo systemctl daemon-reload
sudo systemctl enable hyperstition-tmpfs-sync.service
sudo systemctl enable --now hyperstition-mcp.service
# 3. Install Caddyfile (with /mcp reverse_proxy -> 127.0.0.1:8095), validate syntax, and reload Caddy
sudo cp /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/Caddyfile /etc/caddy/Caddyfile
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy
```
### Step 7: Verify Live Production Deployment (`test-first-deployment.sh`)
```bash
# Verify all 28 routes (including /calc/config.js, /calc/db_lite.json, /calc/db.json) return HTTP 200 OK
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/test-first-deployment.sh https://hyperstitionstud.io
# Measure DNS, QUIC/TLS handshake, and sub-15ms TTFB
curl -o /dev/null -s -w "DNS: %{time_namelookup}s | TLS/QUIC: %{time_appconnect}s | TTFB: %{time_starttransfer}s | Total: %{time_total}s\n" https://hyperstitionstud.io/
```
---
## 5. Procedure for Reflecting Updated Content from `git pull` on `https://hyperstitionstud.io`
Because Caddy serves `https://hyperstitionstud.io` from the RAM-backed `tmpfs` mount (`/var/www/hyperstitionstud.io/repos/<repo>`) using pre-compressed `.br` (Brotli-11) and `.gz` (Gzip-9) sidecars rather than directly from the NVMe Git working trees (`/srv/hyperstitionstud.io/repos/<repo>`), reflecting updated Git content on the live site follows one of the two workflows below:
### 5.1 Workflow A: If You Already Ran `git pull` Manually in `/srv/hyperstitionstud.io/repos/<repo>`
Sync the updated working tree(s) into the RAM mount and regenerate the `.br` / `.gz` sidecars without fetching again:
```bash
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh --no-pull
```
### 5.2 Workflow B: Pull from `git.libre.audio` and Update the Live RAM Mount in One Step
```bash
# Update all 6 repositories at once, run 6-gate audit, sync to RAM, and pre-compress (.br / .gz):
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh all
# Or update a single repository in < 1.5s (e.g., hyperstitionstudio-core or encyclopedia-knowledge-graph):
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh hyperstitionstudio-core
/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/deploy/sync-vps-repos.sh encyclopedia-knowledge-graph
```
*(Note: If a remote tag was force-updated earlier and `git fetch --tags` rejects it with `would clobber existing tag` before `hyperstitionstudio-core` has pulled commit `b767f8a`, run `git -C /srv/hyperstitionstud.io/repos/hyperstitionstudio-core fetch --force origin main --tags && git -C /srv/hyperstitionstud.io/repos/hyperstitionstudio-core merge --ff-only origin/main` once first).*
### 5.3 Automatic Idempotent `Caddyfile`, `systemd` & `logrotate.d` Sync (Default vs. `--no-caddy`)
- **Idempotent by Default (`DO_CADDY=1`):**
Every run of `sync-vps-repos.sh` (unless `--no-caddy` or `--no-services` is passed) automatically compares `deploy/Caddyfile` against `/etc/caddy/Caddyfile`, `deploy/*.service` against `/etc/systemd/system/*.service`, and `deploy/logrotate.d/hyperstition-sqlite-meta` against `/etc/logrotate.d/hyperstition-sqlite-meta` using `cmp -s`:
1. If `/etc/caddy/Caddyfile` is already byte-identical to `deploy/Caddyfile`, it prints `[5/5] /etc/caddy/Caddyfile is already identical to deploy/Caddyfile (no reload needed)` and performs zero unnecessary reloads.
2. If `deploy/Caddyfile` changed, it validates the new config first via `sudo caddy validate --config ... --adapter caddyfile`, copies it to `/etc/caddy/Caddyfile`, and executes a zero-downtime `sudo systemctl reload caddy`.
3. If `hyperstition-tmpfs-sync.service` or `hyperstition-mcp.service` changed, it updates `/etc/systemd/system/`, runs `sudo systemctl daemon-reload`, and ensures `hyperstition-mcp.service` is active.
4. If `/etc/logrotate.d/hyperstition-sqlite-meta` is missing or differs from `deploy/logrotate.d/hyperstition-sqlite-meta`, it installs the rule with `0644` permissions so the SQLite REST/MCP metadata database (`/tmp/hyperstition-api-telemetry.db`) is quiescently truncated at the configurable `100 MB` limit (`size 100M`, `HYPERSTITION_SQLITE_MAX_MB=100`).
- **Negating Service/Caddy Sync (`--no-caddy` / `--no-services`):**
Pass `--no-caddy` (e.g., `sync-vps-repos.sh --no-pull --no-caddy`) to sync only the RAM-backed webroot files and `.br`/`.gz` sidecars without touching `/etc/caddy/Caddyfile` or `systemd`.
- **Browser Cache Note:** `HTML`/`JS`/`JSON` routes carry `Cache-Control: public, max-age=300` (5 minutes); press `Ctrl+Shift+R` (`Cmd+Shift+R` on macOS) in your browser to bypass the 5-minute client cache immediately after syncing.