Keep Douyin homeVariant BMI router intact while restoring admin join-group controls, TLS-safe config fetch, and ntfy channel labels. Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
2.8 KiB
Python
95 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy track analytics + ntfy channel labels to nomadmini-api."""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import tarfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
REPO = Path(__file__).resolve().parents[3]
|
|
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
|
|
EBOOK = REPO / "apps" / "api" / "services" / "ebook_svc"
|
|
|
|
FILES = [
|
|
"routers/admin.py",
|
|
"services/track.py",
|
|
"services/store.py",
|
|
]
|
|
|
|
|
|
def to_app_pkg(text: str) -> str:
|
|
return text.replace("ebook_svc.", "app.")
|
|
|
|
|
|
REMOTE_SH = r"""
|
|
set -euo pipefail
|
|
cd /tmp
|
|
rm -rf ta-unpack && mkdir ta-unpack
|
|
tar -xzf ta-release.tar.gz -C ta-unpack
|
|
|
|
API_ROOT=$(systemctl show nomadmini-api -p WorkingDirectory --value 2>/dev/null || true)
|
|
if [ -z "$API_ROOT" ] || [ "$API_ROOT" = "/" ]; then
|
|
API_ROOT=/opt/nomadmini/backend
|
|
fi
|
|
echo API_ROOT=$API_ROOT
|
|
B=$API_ROOT/app
|
|
if [ ! -d "$B" ]; then B=$API_ROOT/backend/app; fi
|
|
sudo mkdir -p "$B/routers" "$B/services"
|
|
|
|
sudo cp ta-unpack/backend/routers/admin.py "$B/routers/"
|
|
sudo cp ta-unpack/backend/services/track.py "$B/services/"
|
|
sudo cp ta-unpack/backend/services/store.py "$B/services/"
|
|
|
|
sudo systemctl restart nomadmini-api
|
|
sleep 3
|
|
systemctl is-active nomadmini-api
|
|
echo "--- smoke ---"
|
|
curl -s -X POST http://127.0.0.1:8010/api/track \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"events":[{"name":"page_view","page":"pages/index/index","label":"deploy-test","props":{"channel":"tt"}}],"client":"tt"}'
|
|
echo
|
|
curl -s -X POST http://127.0.0.1:8010/api/track \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"events":[{"name":"join_group_show","label":"公众号","props":{"popup":"wechat","channel":"weapp"}}],"client":"weapp"}'
|
|
echo
|
|
rm -rf ta-unpack ta-release.tar.gz
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
buf = io.BytesIO()
|
|
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
|
for rel in FILES:
|
|
src = (EBOOK / rel).read_text(encoding="utf-8")
|
|
data = to_app_pkg(src).encode("utf-8")
|
|
info = tarfile.TarInfo(name=f"backend/{rel}")
|
|
info.size = len(data)
|
|
tar.addfile(info, io.BytesIO(data))
|
|
payload = buf.getvalue()
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=30)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/ta-release.tar.gz", "wb") as f:
|
|
f.write(payload)
|
|
with sftp.file("/tmp/ta-deploy.sh", "w") as f:
|
|
f.write(REMOTE_SH)
|
|
sftp.close()
|
|
|
|
print("uploaded, running remote…")
|
|
_, stdout, stderr = c.exec_command("bash /tmp/ta-deploy.sh", timeout=120)
|
|
print(stdout.read().decode("utf-8", errors="replace"))
|
|
err = stderr.read().decode("utf-8", errors="replace")
|
|
if err.strip():
|
|
print("STDERR:", err)
|
|
c.close()
|
|
print("done", time.strftime("%H:%M:%S"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|