107 lines
3.4 KiB
Python
107 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy timeslot test rotate (API + FE) to dylive.nomadro.com."""
|
|
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]
|
|
|
|
|
|
def ssh():
|
|
last = None
|
|
for i in range(6):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print("retry", i, ex, flush=True)
|
|
time.sleep(3)
|
|
raise SystemExit(last)
|
|
|
|
|
|
def run(c, cmd, t=600):
|
|
print(f"\n$ {cmd[:260]}", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
code = o.channel.recv_exit_status()
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-20000:] if len(out) > 20000 else out, flush=True)
|
|
return code, out
|
|
|
|
|
|
c = ssh()
|
|
sftp = c.open_sftp()
|
|
files = [
|
|
("backend/app/db.py", "/tmp/db.py"),
|
|
("backend/app/yt_assign_db.py", "/tmp/yt_assign_db.py"),
|
|
("backend/app/youtube_relay_pipeline.py", "/tmp/youtube_relay_pipeline.py"),
|
|
("backend/app/main.py", "/tmp/main.py"),
|
|
("frontend/src/components/YtAssignPanel.tsx", "/tmp/YtAssignPanel.tsx"),
|
|
]
|
|
for rel, remote in files:
|
|
sftp.put(str(ROOT / rel), remote)
|
|
sftp.close()
|
|
|
|
code, _ = run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
install -m 0644 /tmp/db.py /opt/douyinWEB/backend/app/db.py
|
|
install -m 0644 /tmp/yt_assign_db.py /opt/douyinWEB/backend/app/yt_assign_db.py
|
|
install -m 0644 /tmp/youtube_relay_pipeline.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
install -m 0644 /tmp/main.py /opt/douyinWEB/backend/app/main.py
|
|
install -m 0644 /tmp/YtAssignPanel.tsx /opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx
|
|
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python -m py_compile app/db.py app/yt_assign_db.py app/youtube_relay_pipeline.py app/main.py
|
|
./.venv/bin/python - <<'PY'
|
|
from app.yt_assign_db import overlay_timeslot_test_schedule
|
|
from app.youtube_relay_pipeline import YoutubeRelayPipeline
|
|
assert hasattr(YoutubeRelayPipeline, "set_timeslot_test_mode")
|
|
assert hasattr(YoutubeRelayPipeline, "timeslot_test_next")
|
|
print("api_ok", overlay_timeslot_test_schedule({"channels":[]}, test_on=False)["test_mode"])
|
|
PY
|
|
|
|
systemctl restart douyinweb-api
|
|
for i in $(seq 1 50); do
|
|
curl -sS -m 2 http://127.0.0.1:8014/api/health >/dev/null 2>&1 && break
|
|
sleep 1
|
|
done
|
|
|
|
# FE rebuild
|
|
cd /opt/douyinWEB/frontend
|
|
if [ -f package.json ]; then
|
|
npm run build
|
|
systemctl restart douyinweb-web || systemctl restart douyinweb-frontend || true
|
|
fi
|
|
|
|
CS=$(mktemp)
|
|
curl -sS -m 20 -c "$CS" -b "$CS" -X POST http://127.0.0.1:8014/api/auth/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"username":"hackrobot","password":"Xiao4669805@"}' >/dev/null
|
|
echo '=== endpoints ==='
|
|
curl -sS -m 15 -b "$CS" -X POST http://127.0.0.1:8014/api/youtube/relay/timeslot-test \
|
|
-H 'Content-Type: application/json' -d '{"enabled":false}' | python3 -c 'import sys,json;d=json.load(sys.stdin);print("test_off", d.get("settings",{}).get("youtube_relay_timeslot_test"))'
|
|
echo DONE
|
|
""",
|
|
t=900,
|
|
)
|
|
c.close()
|
|
raise SystemExit(code)
|