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>
95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy YouTube assign UX + exclusive/time-slot decouple to physical."""
|
|
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]
|
|
PASS = "4669805"
|
|
FILES = [
|
|
("backend/app/youtube_relay_pipeline.py", "/opt/douyinWEB/backend/app/youtube_relay_pipeline.py", "_ux_pipeline.py"),
|
|
("frontend/src/components/YtRelayOpsHero.tsx", "/opt/douyinWEB/frontend/src/components/YtRelayOpsHero.tsx", "_ux_hero.tsx"),
|
|
("frontend/src/components/YtAssignPanel.tsx", "/opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx", "_ux_assign.tsx"),
|
|
(
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"/opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"_ux_pro.tsx",
|
|
),
|
|
("frontend/src/app/youtube/page.tsx", "/opt/douyinWEB/frontend/src/app/youtube/page.tsx", "_ux_yt_page.tsx"),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
TS=$(date +%s)
|
|
ins(){ cp -a "$2" "$2.bak-ux-$TS" 2>/dev/null || true; install -m 644 "$1" "$2"; }
|
|
ins /tmp/_ux_pipeline.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
ins /tmp/_ux_hero.tsx /opt/douyinWEB/frontend/src/components/YtRelayOpsHero.tsx
|
|
ins /tmp/_ux_assign.tsx /opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx
|
|
ins /tmp/_ux_pro.tsx /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx
|
|
ins /tmp/_ux_yt_page.tsx /opt/douyinWEB/frontend/src/app/youtube/page.tsx
|
|
cd /opt/douyinWEB/backend && .venv/bin/python -m py_compile app/youtube_relay_pipeline.py && echo COMPILE_OK
|
|
systemctl restart douyinweb-api
|
|
sleep 3
|
|
systemctl is-active douyinweb-api
|
|
systemctl stop douyinweb-web || true
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-web
|
|
echo BUILD_OK
|
|
"""
|
|
|
|
|
|
def main():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2 + i)
|
|
else:
|
|
raise SystemExit("ssh fail")
|
|
sftp = c.open_sftp()
|
|
for rel, _dst, tmp in FILES:
|
|
with sftp.file(f"/tmp/{tmp}", "w") as f:
|
|
f.write((ROOT / rel).read_text(encoding="utf-8"))
|
|
print("up", rel, flush=True)
|
|
with sftp.file("/tmp/_ux_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_ux_deploy.sh", timeout=900)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-14000:] if len(out) > 14000 else out, flush=True)
|
|
c.close()
|
|
if "COMPILE_OK" not in out or "BUILD_OK" not in out:
|
|
return 1
|
|
for url in ("https://dy.nomadro.com/api/health", "https://dy.nomadro.cn/api/health"):
|
|
try:
|
|
r = httpx.get(url, timeout=20)
|
|
print(url, r.status_code, flush=True)
|
|
except Exception as ex:
|
|
print(url, ex, flush=True)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|