nomadro/apps/admin/deploy/_deploy_admin_com_us.py
Eric b06a14b6aa Ship social admin nested menus with list/detail CRUD, soft-archive UGC, and PocketBase-ready stores.
admin.nomadro.com gets sidebar L1/L2 social ops (paginated lists + entity detail); API adds soft-delete archives/stats and shared nomadro_pb for social/coffee/notify/work.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 16:41:43 +08:00

105 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
"""Build apps/com/admin and deploy static dist to admin.nomadro.com (US VPS)."""
from __future__ import annotations
import io
import subprocess
import tarfile
import time
from pathlib import Path
import paramiko
US = ("108.174.50.68", "root", "Xiao4669805")
ROOT = Path(__file__).resolve().parents[3]
ADMIN_COM = ROOT / "apps" / "com" / "admin"
REMOTE_ROOT = "/www/wwwroot/admin.nomadro.com"
def build() -> Path:
subprocess.run(
["pnpm", "--filter", "@nomadro/admin-com", "build"],
cwd=str(ROOT),
check=True,
shell=True,
)
dist = ADMIN_COM / "dist"
if not dist.is_dir():
raise SystemExit("dist missing")
return dist
def pack(dist: Path) -> bytes:
buf = io.BytesIO()
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
for p in dist.rglob("*"):
if p.is_file():
tar.add(p, arcname=p.relative_to(dist).as_posix())
return buf.getvalue()
def main() -> int:
print("=== build ===", flush=True)
dist = build()
blob = pack(dist)
print("pack", len(blob), "bytes", flush=True)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host, user, password = US
c.connect(host, 22, user, password, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/admin-com.tgz", "wb") as f:
f.write(blob)
sftp.close()
remote = rf"""
set -euo pipefail
mkdir -p {REMOTE_ROOT}
ts=$(date +%Y%m%d%H%M%S)
if [ -d {REMOTE_ROOT} ] && [ "$(ls -A {REMOTE_ROOT} 2>/dev/null)" ]; then
mkdir -p /www/wwwroot/_bak_admin_com
tar -C {REMOTE_ROOT} -czf /www/wwwroot/_bak_admin_com/admin-$ts.tgz . || true
fi
rm -rf {REMOTE_ROOT}.new
mkdir -p {REMOTE_ROOT}.new
tar -xzf /tmp/admin-com.tgz -C {REMOTE_ROOT}.new
# atomic swap
rm -rf {REMOTE_ROOT}.old
mv {REMOTE_ROOT} {REMOTE_ROOT}.old 2>/dev/null || true
mv {REMOTE_ROOT}.new {REMOTE_ROOT}
rm -rf {REMOTE_ROOT}.old
# spa fallback already in nginx; smoke
curl -sk -o /dev/null -w "admin_home %{{http_code}}\n" https://admin.nomadro.com/
curl -sk https://admin.nomadro.com/ | tr '\n' ' ' | grep -o 'Nomadro' | head -1 || true
# keep API up
systemctl is-active nomadmini-api
curl -sS -o /tmp/login.json -w "login %{{http_code}}\n" --max-time 10 -X POST https://api.nomadro.com/api/admin/login \
-H 'content-type: application/json' \
-d '{{"username":"hackrobot","password":"Xiao4669805@"}}'
head -c 120 /tmp/login.json; echo
echo DEPLOY_ADMIN_COM_OK
"""
chan = c.get_transport().open_session()
chan.settimeout(180)
chan.get_pty()
chan.exec_command(remote)
buf = []
end = time.time() + 180
while time.time() < end:
if chan.recv_ready():
buf.append(chan.recv(65536).decode("utf-8", "replace"))
if chan.exit_status_ready():
while chan.recv_ready():
buf.append(chan.recv(65536).decode("utf-8", "replace"))
break
time.sleep(0.05)
print("".join(buf)[-5000:], flush=True)
code = chan.recv_exit_status()
c.close()
return code
if __name__ == "__main__":
raise SystemExit(main())