Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion dev2/dev2-edge
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dev2-edge: pit.world and the Moshpit names on Caddy, every other dev2 site on ng
dev2-edge render [--out DIR] [--off] write the box files for edge.json into DIR (nothing touches dev2)
dev2-edge apply --yes cut over: backup, baseline sweep, install, switch, sweep again;
any site whose status changed rolls the whole box back
dev2-edge reload --yes Caddyfile only (validate as caddy, backup, reload; no sweeps):
for edge.json changes that only touch Caddy sites, e.g. upstream_host
dev2-edge route on|off point the routed names at Caddy (on) or back at nginx (off),
one nginx reload, no other change: the fast way back
dev2-edge rollback [TARBALL] restore /etc/nginx from the apply's backup, stop Caddy
Expand Down Expand Up @@ -227,6 +229,18 @@ def render_cert_sources(s):
return "\n".join(out) + "\n"


UPSTREAM_HOST_RE = re.compile(r"^(127\.0\.0\.1|100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3})$")


def upstream(site):
"""host:port for a proxy site. upstream_host (default 127.0.0.1) moves an app off dev2:
a Tailscale 100.64.0.0/10 address only, so the edge never proxies over the public net."""
host = site.get("upstream_host", "127.0.0.1")
if not UPSTREAM_HOST_RE.match(host):
die(f"edge.json: {site['hosts']} upstream_host {host!r} must be 127.0.0.1 or a Tailscale 100.64.0.0/10 address")
return f"{host}:{int(site['proxy'])}"


def caddy_site(site, s):
tls = "edge_tls_moshpit" if site.get("moshpit") else "edge_tls"
lines = [", ".join(f"https://{h}" for h in site["hosts"]) + " {", f"\timport {tls}"]
Expand All @@ -248,8 +262,10 @@ def caddy_site(site, s):
if "proxy" in site and site.get("retry"):
# While the app restarts (a deploy), hold the request and keep dialing instead of
# answering 502: webhooks that drive live calls (Telnyx) must not fail mid-call.
lines += [f"\treverse_proxy 127.0.0.1:{int(site['proxy'])} {{", "\t\theader_up X-Real-IP {remote_host}",
lines += [f"\treverse_proxy {upstream(site)} {{", "\t\theader_up X-Real-IP {remote_host}",
"\t\tstream_close_delay 1h", f"\t\tlb_try_duration {site['retry']}", "\t\tlb_try_interval 250ms", "\t}"]
elif "proxy" in site and site.get("upstream_host"):
lines.append(f"\timport edge_proxy_host {upstream(site)}")
elif "proxy" in site:
lines.append(f"\timport edge_proxy {int(site['proxy'])}")
elif "root" in site:
Expand Down Expand Up @@ -306,6 +322,14 @@ def render_caddyfile(s):
\t}}
}}

# Same, for an app moved off dev2 (edge.json upstream_host): args[0] is host:port on the tailnet.
(edge_proxy_host) {{
\treverse_proxy {{args[0]}} {{
\t\theader_up X-Real-IP {{remote_host}}
\t\tstream_close_delay 1h
\t}}
}}

""" + "\n".join(caddy_site(site, s) for site in s["sites"])


Expand Down Expand Up @@ -420,6 +444,24 @@ def cmd_apply(a):
sys.exit(r.returncode)


def cmd_reload(a):
"""Caddyfile only: for edge.json changes that touch nothing but Caddy sites (an upstream
moved, a proxy port changed). Validates as caddy, keeps a backup, reloads; no sweeps."""
if not a.yes:
die("this reloads production Caddy on dev2: re-run with --yes")
remote = ship(with_caddy=False)
ts = os.path.basename(remote)
cmd = (f"set -e; install -m 0644 {remote}/root/etc/caddy/Caddyfile /etc/caddy/Caddyfile.next; "
"runuser -u caddy -- env HOME=/var/lib/caddy /usr/local/bin/caddy validate "
"--config /etc/caddy/Caddyfile.next --adapter caddyfile >/dev/null 2>&1 "
"|| { echo 'caddy validate failed: nothing changed' >&2; rm -f /etc/caddy/Caddyfile.next; exit 1; }; "
f"cp -p /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak-reload-{ts}; "
"mv /etc/caddy/Caddyfile.next /etc/caddy/Caddyfile; systemctl reload caddy.service; "
f"sleep 2; systemctl is-active --quiet caddy.service; echo 'caddy reloaded; previous: /etc/caddy/Caddyfile.bak-reload-{ts}'")
r = subprocess.run(SSH + [f"root@{DEV2_HOST}", cmd])
sys.exit(r.returncode)


def cmd_route(a):
remote = ship(on=(a.state == "on"), with_caddy=False)
r = subprocess.run(SSH + [f"root@{DEV2_HOST}", f"{remote}/root/usr/local/sbin/edge-box route {remote}"])
Expand All @@ -446,6 +488,7 @@ def main():
sub = ap.add_subparsers(dest="cmd", required=True)
p = sub.add_parser("render"); p.add_argument("--out"); p.add_argument("--off", action="store_true"); p.set_defaults(fn=cmd_render)
p = sub.add_parser("apply"); p.add_argument("--yes", action="store_true"); p.set_defaults(fn=cmd_apply)
p = sub.add_parser("reload"); p.add_argument("--yes", action="store_true"); p.set_defaults(fn=cmd_reload)
p = sub.add_parser("route"); p.add_argument("state", choices=["on", "off"]); p.set_defaults(fn=cmd_route)
p = sub.add_parser("rollback"); p.add_argument("tarball", nargs="?"); p.set_defaults(fn=cmd_rollback)
sub.add_parser("sweep").set_defaults(fn=cmd_sweep)
Expand Down
8 changes: 4 additions & 4 deletions dev2/edge/edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{"hosts": ["aiornot.pwa.pit.world"], "proxy": 3269, "max_body": "64MiB", "gzip": true},
{"hosts": ["avenasea.pwa.pit.world"], "proxy": 3224, "max_body": "64MiB", "gzip": true},
{"hosts": ["bg0ne.pwa.pit.world"], "proxy": 3201, "max_body": "64MiB", "gzip": true},
{"hosts": ["brisk.pwa.pit.world"], "proxy": 3238, "max_body": "64MiB", "gzip": true},
{"hosts": ["brisk.pwa.pit.world"], "proxy": 3238, "upstream_host": "100.115.66.111", "max_body": "64MiB", "gzip": true},
{"hosts": ["c0ncerts.pwa.pit.world"], "proxy": 3278, "max_body": "64MiB", "gzip": true},
{"hosts": ["c0upons.pwa.pit.world"], "proxy": 3231, "max_body": "64MiB", "gzip": true},
{"hosts": ["cigarunderground.pwa.pit.world"], "proxy": 3203, "max_body": "64MiB", "gzip": true},
Expand All @@ -53,17 +53,17 @@
{"hosts": ["opensourcelegends.pwa.pit.world"], "proxy": 3232, "max_body": "64MiB", "gzip": true},
{"hosts": ["recipepdfs.pwa.pit.world"], "proxy": 3263, "max_body": "64MiB", "gzip": true},
{"hosts": ["ringhuman.pwa.pit.world"], "proxy": 3233, "max_body": "64MiB", "gzip": true},
{"hosts": ["saasrow.pwa.pit.world"], "proxy": 3276, "max_body": "64MiB", "gzip": true},
{"hosts": ["saasrow.pwa.pit.world"], "proxy": 3276, "upstream_host": "100.115.66.111", "max_body": "64MiB", "gzip": true},
{"hosts": ["submitfleet.pwa.pit.world"], "proxy": 3380, "max_body": "8MiB", "gzip": true},
{"hosts": ["sysops.pwa.pit.world"], "proxy": 3330, "max_body": "1MiB", "gzip": true},
{"hosts": ["tleehealth.pwa.pit.world"], "proxy": 3295, "max_body": "25MiB", "gzip": true},
{"hosts": ["tsbb.pwa.pit.world"], "proxy": 3255, "max_body": "64MiB", "gzip": true},
{"hosts": ["typeheard.pwa.pit.world"], "proxy": 3294, "max_body": "1100MiB", "gzip": true},
{"hosts": ["weedforcrypto.pwa.pit.world"], "proxy": 3243, "max_body": "64MiB", "gzip": true},
{"hosts": ["brisk-supabase.pwa.pit.world"], "proxy": 8238, "max_body": "64MiB", "gzip": true},
{"hosts": ["brisk-supabase.pwa.pit.world"], "proxy": 8238, "upstream_host": "100.115.66.111", "max_body": "64MiB", "gzip": true},
{"hosts": ["c0ncerts-supabase.pwa.pit.world"], "proxy": 8278, "max_body": "64MiB", "gzip": true},
{"hosts": ["icemap-supabase.pwa.pit.world"], "proxy": 8262, "max_body": "64MiB", "gzip": true},
{"hosts": ["saasrow-supabase.pwa.pit.world"], "proxy": 8276, "max_body": "64MiB", "gzip": true},
{"hosts": ["saasrow-supabase.pwa.pit.world"], "proxy": 8276, "upstream_host": "100.115.66.111", "max_body": "64MiB", "gzip": true},
{"hosts": ["weedforcrypto-supabase.pwa.pit.world"], "proxy": 8243, "max_body": "64MiB", "gzip": true},
{"hosts": ["c0upons-bbs.pwa.pit.world"], "proxy": 3293, "max_body": "64MiB", "gzip": true},
{ "hosts": ["built.indie"], "proxy": 8798, "max_body": "1MiB", "moshpit": true },
Expand Down
4 changes: 3 additions & 1 deletion dev2/sites.d/brisk.news.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
"vault_skip": [
"X402_PRIVATE_KEY"
],
"env_overrides_note": "2026-11-09: c0mpute tuning for CPU-only nodes (the abliterated 9B is skipped by nodes with uncensored house models off). C0MPUTE_SPEECH_TOKEN lives only in app.env (copied from crawlproof)."
"env_overrides_note": "2026-11-09: c0mpute tuning for CPU-only nodes (the abliterated 9B is skipped by nodes with uncensored house models off). C0MPUTE_SPEECH_TOKEN lives only in app.env (copied from crawlproof).",
"moved_to": "vienna",
"moved_note": "2026-11-22 dev2 offload batch 1: app + its own supabase stack run on vienna (seed2) from /mnt/vdb/www/brisk.news (symlink ~/www/brisk.news), published on the tailnet 100.115.66.111 only via docker-compose.vienna.yml overrides; dev2 edge proxies there (edge.json upstream_host). dev2 copy stopped (restart=no), deploy.env renamed deploy.env.moved-to-vienna-20261122, 'Deploy to dev2' workflow disabled. Rollback: edge upstream back to 127.0.0.1 + compose up on dev2 after a reverse rsync of anything written since."
}
4 changes: 3 additions & 1 deletion dev2/sites.d/saasrow.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
"SITE_URL",
"STRIPE_SECRET_KEY",
"STRIPE_WEBHOOK_SECRET"
]
],
"moved_to": "vienna",
"moved_note": "2026-11-22 dev2 offload batch 1: app + its own supabase stack run on vienna (seed2) from /mnt/vdb/www/saasrow.com (symlink ~/www/saasrow.com), published on the tailnet 100.115.66.111 only via docker-compose.vienna.yml overrides; dev2 edge proxies there (edge.json upstream_host). dev2 copy stopped (restart=no), deploy.env renamed deploy.env.moved-to-vienna-20261122, 'Deploy to dev2' workflow disabled. Rollback: edge upstream back to 127.0.0.1 + compose up on dev2 after a reverse rsync of anything written since."
}
Loading