# -*- coding: utf-8 -*- """Deploy test1 downloads feature and publish Chrome + extension to S3.""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "107.173.30.245" REPO = "/opt/douyinWEB" BRANCH = "test1" PY = f"{REPO}/backend/.venv/bin/python" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd: str, timeout: int = 600) -> str: _, o, e = c.exec_command(cmd, timeout=timeout) out = o.read().decode("utf-8", "replace") err = e.read().decode("utf-8", "replace") return (out + err).strip() ts = int(time.time()) print("[backup]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_dl_{ts} && ls -lh /tmp/monitor.db.bak_dl_{ts}")) print("[fingerprint]", run(f"stat -c '%n %s' {REPO}/backend/data/monitor.db")) print("[git]", run(f"cd {REPO} && git fetch origin {BRANCH} && git checkout {BRANCH} && git pull --ff-only origin {BRANCH} && git log --oneline -2")) print("[restart api]") print(run("systemctl restart douyinweb-api; sleep 6; systemctl is-active douyinweb-api")) print("[npm build]") build = run(f"cd {REPO}/frontend && npm run build", timeout=360) for line in build.splitlines()[-25:]: print(line.encode("ascii", "replace").decode("ascii")) print("[restart web]", run("systemctl restart douyinweb-web; sleep 4; systemctl is-active douyinweb-web")) print("[publish downloads to S3]") pub = run( f"export DY_S3_ENABLED=true " f"DY_S3_ENDPOINT=http://127.0.0.1:8333 " f"DY_S3_PUBLIC_BASE=https://s3.nomadro.com " f"DY_S3_ACCESS_KEY=douyin " f"DY_S3_SECRET_KEY=douyinweb_s3_2026 " f"DY_S3_BUCKET=douyin-covers " f"DY_S3_REGION=us-east-1; " f"cd {REPO} && {PY} scripts/_publish_downloads.py", timeout=900, ) for line in pub.splitlines()[-50:]: print(line.encode("ascii", "replace").decode("ascii")) print("[api downloads]", run("curl -s http://127.0.0.1:8014/api/downloads | head -c 800")) print("[services]", run("systemctl is-active douyinweb-api douyinweb-web")) print("[db]", run(f"stat -c '%n %s' {REPO}/backend/data/monitor.db")) c.close() print("DONE")