#!/usr/bin/env python3 # -*- coding: utf-8 -*- """同步 Higress 补丁到 207 并执行 Compose standalone 部署。""" from __future__ import annotations import sys from pathlib import Path import _bootstrap # noqa: F401 import _config as C from dify_api import Dify ROOT = Path(__file__).resolve().parents[2] LOCAL_PATCH = ROOT / "patches_cursor" / "Higress部署" LOCAL_SH = ROOT / "scripts_bash_cursor" / "Higress部署" / "Higress_01_部署.sh" REMOTE_PATCH = C.HIGRESS_PATCH_DIR def sync_dir(d: Dify, local: Path, remote: str) -> None: d.sh(f"mkdir -p '{remote}'") for fp in local.rglob("*"): if not fp.is_file(): continue if fp.name.startswith(".") and fp.name not in (".env",): continue rel = fp.relative_to(local).as_posix() rpath = f"{remote}/{rel}" parent = "/".join(rpath.split("/")[:-1]) d.sh(f"mkdir -p '{parent}'") d.sftp.put(str(fp), rpath) print(f" put {rel}") def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: try: d.login() except Exception as e: # noqa: BLE001 print("[WARN] Dify login 跳过:", e) print("[INFO] sync patch →", REMOTE_PATCH) sync_dir(d, LOCAL_PATCH, REMOTE_PATCH) remote_sh = "/tmp/Higress_01_部署.sh" d.sftp.put(str(LOCAL_SH), remote_sh) d.sh(f"sed -i 's/\\r$//' '{remote_sh}' && chmod +x '{remote_sh}'") out, err = d.sh(f"bash '{remote_sh}'") print(out or "") if err: print(err) raw, _ = d.sh( f"curl -sS -o /dev/null -w '%{{http_code}}' http://127.0.0.1:{C.HIGRESS_CONSOLE_PORT}/ || echo FAIL" ) print("[DEBUG] console http_code:", raw) if "FAIL" in (raw or "") or (raw or "").strip() in ("000", ""): print("[FAIL] Higress Console 未就绪") return 1 print("[OK] Higress", C.HIGRESS_BASE, "| Console", C.HIGRESS_CONSOLE) return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())