# -*- 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") with sftp.file("/tmp/_fe_build.sh", "w") as f: f.write( "#!/bin/bash\n" "cd /opt/douyinWEB/frontend || exit 1\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() cmds = [ f"echo '{PW}' | sudo -S -p '' install -m 644 /tmp/_up_page.tsx /opt/douyinWEB/frontend/src/app/network/page.tsx", f"echo '{PW}' | sudo -S -p '' chmod +x /tmp/_fe_build.sh", f"echo '{PW}' | sudo -S -p '' systemctl stop douyinweb-web", f"echo '{PW}' | sudo -S -p '' bash -c 'pkill -9 -f \"next build\" || true; pkill -9 -f \"npm run build\" || true'", f"echo '{PW}' | sudo -S -p '' rm -f /tmp/fe-net3.log", f"echo '{PW}' | sudo -S -p '' bash -c 'nohup /tmp/_fe_build.sh >/tmp/fe-net3-nohup.out 2>&1 & echo PID=$!; sleep 2; ls -l /tmp/fe-net3.log /tmp/_fe_build.sh'", ] for cmd in cmds: print(run(g, cmd, 30), 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 || echo 0; " "tail -n 4 /tmp/fe-net3.log 2>/dev/null; " "grep '^EXIT:' /tmp/fe-net3.log 2>/dev/null | tail -1; " "test -f /opt/douyinWEB/frontend/.next/BUILD_ID && echo HAS_BUILD || echo NO_BUILD", 25, ) g.close() print(f"[{i}] {st.strip()[-280:]}", flush=True) if "EXIT:0" in st and "HAS_BUILD" in st: break if "EXIT:" in st and "EXIT:0" not in st: g = ssh() print(run(g, "grep -nE 'Type error|Failed to compile|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)