nomadro/apps/admin/deploy/_deploy_books_live_82.py
Eric 1c2486a9c5 Hot-sync ebook and VIP offer changes from admin to clients within 1-2s.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-22 11:33:00 +08:00

51 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy books_live + admin router (offer hot bump) to api.nomadro.cn."""
from __future__ import annotations
from pathlib import Path
import paramiko
REPO = Path(__file__).resolve().parents[3]
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
FILES = [
(
REPO / "apps/api/services/ebook_svc/services/books_live.py",
"/opt/nomadmini/backend/app/services/books_live.py",
),
(
REPO / "apps/api/services/ebook_svc/routers/admin.py",
"/opt/nomadmini/backend/app/routers/admin.py",
),
]
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for src, dest in FILES:
data = src.read_text(encoding="utf-8").replace("ebook_svc.", "app.").encode("utf-8")
tmp = f"/tmp/{Path(dest).name}"
with sftp.file(tmp, "wb") as rf:
rf.write(data)
print("up", src.name, len(data))
sftp.close()
_, o, e = c.exec_command(
"sudo cp /tmp/books_live.py /opt/nomadmini/backend/app/services/books_live.py && "
"sudo cp /tmp/admin.py /opt/nomadmini/backend/app/routers/admin.py && "
"sudo systemctl restart nomadmini-api.service && sleep 2 && "
"systemctl is-active nomadmini-api.service && curl -s http://127.0.0.1:8010/health",
timeout=60,
)
print(o.read().decode())
err = e.read().decode()
if err:
print("STDERR", err[-800:])
c.close()
if __name__ == "__main__":
main()