douyinWEB/scripts/_deploy_slots_fix.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

68 lines
2.1 KiB
Python

import paramiko, subprocess, time
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
LOCAL = "C:/Users/admin/Desktop/douyinWEB"
def run_local(args):
r = subprocess.run(args, capture_output=True, text=True, cwd=LOCAL)
return (r.stdout + r.stderr).strip()
def run_ssh(c, cmd, timeout=300):
_s, out, err = c.exec_command(cmd, timeout=timeout)
o = out.read().decode("utf-8", "replace").strip()
e = err.read().decode("utf-8", "replace").strip()
return o, e
# local commit & push
print(run_local(["git", "add", "frontend/src/app/slots/page.tsx"]))
print(run_local(["git", "commit", "-m", "Default slots page to douyin platform filter"]))
print(run_local(["git", "push", "origin", "dev"]))
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
# sftp upload changed files
sftp = c.open_sftp()
for local_rel, remote_path in [
("frontend/src/app/slots/page.tsx", f"{REPO}/frontend/src/app/slots/page.tsx"),
]:
print(f"uploading {local_rel}")
sftp.put(f"{LOCAL}/{local_rel}", remote_path)
sftp.close()
# also make sure db.py/main.py are current
sftp = c.open_sftp()
for local_rel, remote_path in [
("backend/app/db.py", f"{REPO}/backend/app/db.py"),
("backend/app/main.py", f"{REPO}/backend/app/main.py"),
]:
print(f"uploading {local_rel}")
sftp.put(f"{LOCAL}/{local_rel}", remote_path)
sftp.close()
# restart API
print("[restart api]")
c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5)
time.sleep(6)
o, _ = run_ssh(c, "systemctl is-active douyinweb-api", timeout=15)
print("api:", o)
# rebuild frontend
print("[npm build]")
o, _ = run_ssh(c, f"cd {REPO}/frontend && npm run build 2>&1 | tail -8", timeout=360)
print(o.encode("ascii", "replace").decode())
# restart web
print("[restart web]")
c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5)
time.sleep(4)
o, _ = run_ssh(c, "systemctl is-active douyinweb-web", timeout=15)
print("web:", o)
c.close()
print("DONE")