This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build. Co-authored-by: Cursor <cursoragent@cursor.com>
96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Upload web-console/out to the correct path on host03 and verify."""
|
|
from __future__ import annotations
|
|
|
|
import posixpath
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.3", "eric", "Xiao4669805"
|
|
BASE = "/opt/live/d2ypp"
|
|
OUT = Path(__file__).resolve().parent.parent / "web-console" / "out"
|
|
|
|
|
|
def mkdir_p(sftp: paramiko.SFTPClient, remote_dir: str) -> None:
|
|
remote_dir = remote_dir.replace("\\", "/").rstrip("/")
|
|
if not remote_dir or remote_dir == "/":
|
|
return
|
|
cur = ""
|
|
for part in [p for p in remote_dir.split("/") if p]:
|
|
cur = f"{cur}/{part}" if cur else f"/{part}"
|
|
try:
|
|
sftp.stat(cur)
|
|
except OSError:
|
|
try:
|
|
sftp.mkdir(cur)
|
|
except OSError:
|
|
pass
|
|
|
|
|
|
def put_tree(sftp: paramiko.SFTPClient, local_dir: Path, remote_dir: str) -> int:
|
|
count = 0
|
|
for path in sorted(local_dir.rglob("*")):
|
|
if not path.is_file():
|
|
continue
|
|
rel = path.relative_to(local_dir).as_posix()
|
|
remote = posixpath.join(remote_dir, rel)
|
|
mkdir_p(sftp, posixpath.dirname(remote))
|
|
sftp.put(str(path), remote)
|
|
count += 1
|
|
return count
|
|
|
|
|
|
def run(client: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str:
|
|
_, stdout, stderr = client.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout)
|
|
return (stdout.read() + stderr.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def safe_print(text: str) -> None:
|
|
try:
|
|
print(text)
|
|
except UnicodeEncodeError:
|
|
sys.stdout.buffer.write(text.encode("utf-8", errors="replace") + b"\n")
|
|
|
|
|
|
def main() -> int:
|
|
if not (OUT / "index.html").is_file():
|
|
raise SystemExit("missing local web-console/out — run: cd web-console && pnpm run build")
|
|
|
|
local_index = (OUT / "index.html").read_text(encoding="utf-8", errors="replace")
|
|
local_chunk = "371" if "371-" in local_index else "unknown"
|
|
safe_print(f"local index references chunk family: {local_chunk}")
|
|
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
client.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
sftp = client.open_sftp()
|
|
|
|
remote_out = f"{BASE}/web-console/out"
|
|
uploaded = put_tree(sftp, OUT, remote_out)
|
|
safe_print(f"uploaded {uploaded} files -> {remote_out}")
|
|
|
|
sftp.close()
|
|
|
|
verify_cmds = [
|
|
f"grep -o 'page-[a-z0-9]*\\.js' {remote_out}/index.html | head -1",
|
|
f"grep -o '371-[a-z0-9]*\\.js' {remote_out}/index.html | head -1",
|
|
f"grep -o '904-[a-z0-9]*\\.js' {remote_out}/index.html | head -1",
|
|
"curl -sS http://127.0.0.1:8001/ | grep -o '371-[a-z0-9]*\\.js\\|904-[a-z0-9]*\\.js' | head -3",
|
|
f"echo {PASS!r} | sudo -S -p '' systemctl restart live-console.service",
|
|
"sleep 6",
|
|
"curl -sf http://127.0.0.1:8001/health",
|
|
"curl -sS http://127.0.0.1:8001/ | grep -o '371-[a-z0-9]*\\.js\\|904-[a-z0-9]*\\.js' | head -3",
|
|
]
|
|
for cmd in verify_cmds:
|
|
out = run(client, cmd, timeout=180)
|
|
safe_print(f"\n$ {cmd}\n{out.strip()[:500]}")
|
|
|
|
client.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|