douyinWEB/scripts/_deploy.py
eric faf576c151 fix: remove fetchJson generic args for JS api helper build
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-23 08:09:45 -05:00

49 lines
1.4 KiB
Python

"""Standard deploy: server git pull dev + restart API + rebuild frontend + restart web."""
import paramiko, time
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
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)
def run(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
print("[git pull origin test1]")
o, e = run(
f"cd {REPO} && git stash push -u -m pre-deploy-test1 2>/dev/null; "
f"git fetch origin test1 && git checkout test1 && git pull --ff-only origin test1 2>&1",
timeout=120,
)
print(o or e)
print("[git log]")
o, _ = run(f"cd {REPO} && git log --oneline -2")
print(o)
print("[restart api]")
c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5)
time.sleep(8)
o, _ = run("systemctl is-active douyinweb-api")
print("api:", o)
print("[npm build]")
o, _ = run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -6", timeout=360)
print(o.encode("ascii", "replace").decode())
print("[restart web]")
c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5)
time.sleep(5)
o, _ = run("systemctl is-active douyinweb-web")
print("web:", o)
c.close()
print("DONE")