douyinWEB/scripts/_deploy_opsneko_pairing_ui.py
2026-09-13 22:10:49 -05:00

90 lines
3.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Deploy ops-neko pairing UI/API to VPS + physical."""
from __future__ import annotations
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
LOCAL = Path(__file__).resolve().parents[1]
FILES = [
"backend/app/ops_neko.py",
"backend/app/ops_neko_db.py",
"backend/app/main.py",
"backend/app/session_auth.py",
"frontend/src/components/OpsNekoHubCredentialsCard.tsx",
"frontend/src/components/YtRelayOpsHero.tsx",
"frontend/src/components/YtRelayProStatusPanel.tsx",
"frontend/src/components/YtAssignPanel.tsx",
"frontend/src/app/neko/page.tsx",
]
def put(c, root: str, sudo_pw: str | None = None):
sftp = c.open_sftp()
for rel in FILES:
src = LOCAL / rel
if not src.is_file():
print("skip missing", rel)
continue
tmp = f"/tmp/_pair_{Path(rel).name}"
with sftp.file(tmp, "wb") as f:
f.write(src.read_bytes())
dst = f"{root}/{rel}"
if sudo_pw:
cmd = f"echo '{sudo_pw}' | sudo -S -p '' bash -lc \"mkdir -p $(dirname {dst}); install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}\""
else:
cmd = f"mkdir -p $(dirname {dst}); install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}"
_i, o, e = c.exec_command(cmd, timeout=30)
err = (e.read() + o.read()).decode("utf-8", "replace")
print(("ok " if not err.strip() or "password" in err.lower() else err[:120]), rel, flush=True)
sftp.close()
def main():
# physical
p = paramiko.SSHClient()
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
print("=== PHYS ===", flush=True)
put(p, "/opt/douyinWEB", "4669805")
_i, o, e = p.exec_command(
"echo '4669805' | sudo -S -p '' bash -lc '"
"systemctl restart douyinweb-api; "
"cd /opt/douyinWEB/frontend && npm run build >/tmp/fe_pair.log 2>&1 && echo FE_OK || (echo FE_FAIL; tail -25 /tmp/fe_pair.log); "
"systemctl restart douyinweb-web; "
"systemctl is-active douyinweb-api douyinweb-web"
"'",
timeout=600,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
p.close()
# vps
v = paramiko.SSHClient()
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
print("=== VPS ===", flush=True)
put(v, "/opt/douyinWEB")
_i, o, e = v.exec_command(
"systemctl restart douyinweb-api; "
"cd /opt/douyinWEB/frontend && npm run build >/tmp/fe_pair.log 2>&1 && echo FE_OK || (echo FE_FAIL; tail -25 /tmp/fe_pair.log); "
"systemctl restart douyinweb-web; "
"sleep 2; "
"systemctl is-active douyinweb-api douyinweb-web; "
"curl -sS -m 12 -o /dev/null -w 'dylive=%{http_code}\\n' https://dylive.nomadro.com/api/health; "
"curl -sS -m 12 -o /dev/null -w 'dy=%{http_code}\\n' https://dy.nomadro.com/api/health",
timeout=600,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
v.close()
print("DONE deploy pairing", flush=True)
if __name__ == "__main__":
main()