douyinWEB/scripts/_fe_build_clean.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

108 lines
3.4 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import time
from pathlib import Path
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
PW = "4669805"
def ssh():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect("107.173.30.245", 4014, "eric", PW, timeout=45, banner_timeout=90, allow_agent=False, look_for_keys=False)
return c
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2)
raise RuntimeError("ssh")
def run(c, cmd, timeout=120):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
g = ssh()
sftp = g.open_sftp()
sftp.put(str(ROOT / "frontend/src/app/network/page.tsx"), "/tmp/_up_page.tsx")
# write a tiny build launcher
with sftp.file("/tmp/_fe_build.sh", "w") as f:
f.write(
"#!/bin/bash\n"
"set -e\n"
"cd /opt/douyinWEB/frontend\n"
"export DY_INTERNAL_API_URL=http://127.0.0.1:8014\n"
"export DY_PUBLIC_BASE_URL=https://dy.nomadro.com\n"
"npm run build > /tmp/fe-net3.log 2>&1\n"
"echo EXIT:$? >> /tmp/fe-net3.log\n"
)
sftp.close()
print(
run(
g,
f"echo '{PW}' | sudo -S -p '' bash -c '"
"install -m 644 /tmp/_up_page.tsx /opt/douyinWEB/frontend/src/app/network/page.tsx; "
"install -m 755 /tmp/_fe_build.sh /tmp/_fe_build.sh; "
"systemctl stop douyinweb-web || true; "
"pkill -9 -f \"next build\" || true; "
"pkill -9 -f \"npm run build\" || true; "
"sleep 1; "
"rm -f /tmp/fe-net3.log; "
"nohup /tmp/_fe_build.sh >/dev/null 2>&1 & "
"echo STARTED; sleep 1; ls -l /tmp/fe-net3.log /tmp/_fe_build.sh'"
),
flush=True,
)
g.close()
for i in range(50):
time.sleep(12)
g = ssh()
st = run(
g,
"wc -l /tmp/fe-net3.log 2>/dev/null; tail -n 5 /tmp/fe-net3.log 2>/dev/null; "
"grep -q '^EXIT:0' /tmp/fe-net3.log && echo OK || true; "
"grep -q '^EXIT:' /tmp/fe-net3.log && grep -v '^EXIT:0' /tmp/fe-net3.log | grep '^EXIT:' && echo BAD || true; "
"test -f /opt/douyinWEB/frontend/.next/BUILD_ID && echo HAS_BUILD || echo NO_BUILD",
25,
)
g.close()
print(f"[{i}] {st.strip()[-300:]}", flush=True)
if "OK" in st and "HAS_BUILD" in st:
break
if "BAD" in st or "Failed to compile" in st:
g = ssh()
print(run(g, "grep -nE 'Type error|Failed|Error:' /tmp/fe-net3.log | head -30"), flush=True)
g.close()
raise SystemExit("build failed")
else:
raise SystemExit("timeout")
g = ssh()
print(
run(
g,
f"echo '{PW}' | sudo -S -p '' bash -c '"
"systemctl reset-failed douyinweb-web; systemctl start douyinweb-web; sleep 4; "
"systemctl is-active douyinweb-web; "
"curl -sS -m 8 -o /dev/null -w local:%{http_code}\\\\n http://127.0.0.1:4015/network'"
),
flush=True,
)
g.close()
with httpx.Client(timeout=20.0, follow_redirects=False) as client:
print("public", client.get("https://dy.nomadro.com/network").status_code, flush=True)
print("dylive", client.get("https://dylive.nomadro.com/api/health").status_code, flush=True)
print("DONE", flush=True)