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

76 lines
2.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Deploy yt-long progress bar fix (uploaded-based) to dy + dylive."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
LOCAL = ROOT / "frontend" / "src" / "app" / "yt-long" / "page.tsx"
PASS = "Xiao4669805"
HOSTS = [("dy", "108.174.50.68"), ("dylive", "107.173.30.245")]
REMOTE = r'''#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
src=Path('/tmp/_yt_long_page.tsx')
dst=Path('/opt/douyinWEB/frontend/src/app/yt-long/page.tsx')
data=src.read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n')
dst.write_bytes(data)
text=data.decode('utf-8','replace')
assert '上传 {progress}' in text or '上传 {progress}/' in text or 'progress = Number(ch.uploaded' in text
print('PUT_OK', dst, 'bytes', len(data))
print('has_uploaded_progress', 'ch.uploaded' in text and 'progress' in text)
PY
cd /opt/douyinWEB/frontend
npm run build 2>&1 | tail -30
systemctl restart douyinweb-web.service
sleep 2
systemctl is-active douyinweb-web.service
'''
def connect(host: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(host, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=90)
return c
except Exception as e:
print(f"ssh_retry {host} {i}: {e}", flush=True)
time.sleep(2 + i)
raise SystemExit(f"ssh_fail {host}")
def deploy(label: str, host: str):
print(f"\n===== {label} {host} =====", flush=True)
c = connect(host)
sftp = c.open_sftp()
data = LOCAL.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
with sftp.file("/tmp/_yt_long_page.tsx", "wb") as f:
f.write(data)
with sftp.file("/tmp/_deploy_yt_long_progress.sh", "w") as f:
f.write(REMOTE.replace("\r\n", "\n"))
sftp.close()
_, o, e = c.exec_command("bash /tmp/_deploy_yt_long_progress.sh", timeout=600)
print((o.read() + e.read()).decode("utf-8", "replace")[-4000:], flush=True)
c.close()
def main():
if not LOCAL.is_file():
raise SystemExit(f"missing {LOCAL}")
for label, host in HOSTS:
deploy(label, host)
if __name__ == "__main__":
main()