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>
114 lines
3.8 KiB
Python
114 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy project reliability fixes (Neko + assign UI) to dy.nomadro.live."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "108.174.50.68"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
APP = "/opt/douyinWEB"
|
|
|
|
FILES = [
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/config.py",
|
|
"backend/app/main.py",
|
|
"backend/app/yt_assign_db.py",
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
]
|
|
|
|
REMOTE = r"""#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Pin NAT + public base for ICE / studio URLs (avoid compose thrash)
|
|
grep -q '^DY_NEKO_NAT1TO1=' /etc/douyinweb.env 2>/dev/null \
|
|
|| echo 'DY_NEKO_NAT1TO1=108.174.50.68' >> /etc/douyinweb.env
|
|
grep -q '^DY_PUBLIC_BASE_URL=' /etc/douyinweb.env 2>/dev/null \
|
|
|| echo 'DY_PUBLIC_BASE_URL=https://dy.nomadro.live' >> /etc/douyinweb.env
|
|
# Also ensure systemd unit has NAT (EnvironmentFile may already load /etc/douyinweb.env)
|
|
if [[ -f /etc/systemd/system/douyinweb-api.service ]]; then
|
|
if ! grep -q 'DY_NEKO_NAT1TO1' /etc/systemd/system/douyinweb-api.service; then
|
|
sed -i '/Environment=DY_PUBLIC_BASE_URL=/a Environment=DY_NEKO_NAT1TO1=108.174.50.68' \
|
|
/etc/systemd/system/douyinweb-api.service || true
|
|
fi
|
|
systemctl daemon-reload
|
|
fi
|
|
|
|
echo "=== restart api ==="
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
|
|
echo "=== neko smoke (read-only status) ==="
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app import youtube_neko, yt_assign_db
|
|
groups = yt_assign_db.list_groups(include_urls=False)
|
|
print("desired_db", youtube_neko._desired_from_db())
|
|
# sync once on deploy (not on status poll)
|
|
r = youtube_neko.sync_for_groups(groups)
|
|
print("sync", {k: r.get(k) for k in ("ok","desired","created","changed","compose_up","nat1to1","error")})
|
|
st = youtube_neko.status_summary(desired=0)
|
|
print("status_running", st.get("running"), "hint", st.get("login_hint"))
|
|
for i in st.get("instances") or []:
|
|
print("inst", i.get("id"), i.get("status"), "ready", i.get("ready"), i.get("studio_url"))
|
|
assert "credentials" not in st
|
|
assert "user_pass" not in (st.get("instances") or [{}])[0]
|
|
PY
|
|
|
|
echo "=== build web ==="
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-web
|
|
echo DONE
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
print(f"upload {rel}")
|
|
sftp.put(str(ROOT / rel), f"{APP}/{rel}")
|
|
with sftp.file("/tmp/deploy_project_opt.sh", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.chmod("/tmp/deploy_project_opt.sh", 0o755)
|
|
sftp.close()
|
|
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(900)
|
|
chan.get_pty(width=160, height=40)
|
|
chan.exec_command("bash /tmp/deploy_project_opt.sh")
|
|
buf = []
|
|
while True:
|
|
if chan.recv_ready():
|
|
chunk = chan.recv(65535).decode("utf-8", "replace")
|
|
buf.append(chunk)
|
|
print(chunk, end="", flush=True)
|
|
if chan.recv_stderr_ready():
|
|
chunk = chan.recv_stderr(65535).decode("utf-8", "replace")
|
|
buf.append(chunk)
|
|
print(chunk, end="", flush=True)
|
|
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
|
|
break
|
|
time.sleep(0.25)
|
|
while chan.recv_ready():
|
|
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
code = chan.recv_exit_status()
|
|
c.close()
|
|
print(f"\nexit {code}")
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|