diff --git a/sources/python/deploy.py b/sources/python/deploy.py index e60da71..7eb723a 100644 --- a/sources/python/deploy.py +++ b/sources/python/deploy.py @@ -10,7 +10,7 @@ CONF = f"{APP}/fw.conf" STATE = f"{APP}/state.json" DOCKER_DIR = f"{BASE}/docker" OFFLINE_DIR = f"{BASE}/offline" -WALLARM_IMAGE = os.environ.get("WALLARM_IMAGE", "wallarm/node:6.13.0") +WALLARM_IMAGE = os.environ.get("WALLARM_IMAGE", "wallarm/node:6.11.0-rc1") # Ensure Docker is in PATH os.environ["PATH"] = f"{DOCKER_DIR}/bin:{os.environ.get('PATH', '')}" @@ -126,33 +126,53 @@ def main(): if len(sys.argv) > 1 and sys.argv[1] == "--deploy-all": return deploy_all() - print(f"═══ Wallarm Docker Manager v{VERSION} ═══\n") - - # Check for fw.conf + print(f"═══ Wallarm Node Manager v{VERSION} ═══\n") + print("Preflight checks...") + if not shutil.which("docker"): + print(" ❌ Docker not found. Run setup.sh first.") + sys.exit(1) + print(" ✅ Docker ready\n") + cfg = load_config() - if not cfg: - print("No fw.conf found. Create one? [Y/n]: ", end="") - if input().strip().lower() in ("", "y", "yes"): - create_config() - cfg = load_config() - else: - print("Create /opt/fw/app/fw.conf manually or use the menu to add nodes.") + deployed = {n["name"] for n in load_state().get("nodes", [])} while True: - print("\n─── Menu ───") - print(" [1] Deploy all") - print(" [2] Add a node") - print(" [3] Status") - print(" [4] Remove a node") - print(" [5] Edit a node") + undeployed = [k for k in cfg if k not in deployed] + + print("─── Menu ───") + if undeployed: + print(f" Nodes ready to deploy: {', '.join(undeployed)}") + else: + print(" No nodes pending deployment.") + + if undeployed: + print(" [1] Deploy all pending nodes") + print(" [2] Add a new node") + if deployed: + print(" [3] Show status") + print(" [4] Remove a node") print(" [q] Quit") + c = input("\nChoice: ").strip() - if c == "1": deploy_all() - elif c == "2": add_node() - elif c == "3": container_status() - elif c == "4": remove_menu() - elif c == "5": edit_menu() - elif c.lower() == "q": break + + if c == "1" and undeployed: + for name in undeployed: + nc = cfg[name] + print(f"\nDeploying {name}...") + deploy_container(name, nc["token"], nc.get("cloud","EU"), + str(nc.get("port","8081")), nc.get("upstream_ip",""), + str(nc.get("upstream_port","80")), "", + nc.get("mode","monitoring")) + elif c == "2": + add_node() + cfg = load_config() + deployed = {n["name"] for n in load_state().get("nodes", [])} + elif c == "3" and deployed: + container_status() + elif c == "4" and deployed: + remove_menu() + elif c.lower() == "q": + break def create_config(): print("\n─── Create Node Config ───") @@ -175,16 +195,28 @@ def create_config(): print(f"✅ {name} added to fw.conf") def add_node(): - create_config() + print("\n─── Add New Node ───") + name = input("Node name: ").strip() + if not name: return + token = input("Wallarm token: ").strip() + if not token: print("Token required."); return + cloud = input("Cloud region [EU]: ").strip() or "EU" + port = input("Port [8081]: ").strip() or "8081" + upstream_ip = input("Upstream IP [127.0.0.1]: ").strip() or "127.0.0.1" + upstream_port = input("Upstream port [80]: ").strip() or "80" + mode = input("Mode [monitoring]: ").strip() or "monitoring" + + # Save to fw.conf cfg = load_config() - if cfg: - # Deploy just the newly added node - for name in list(cfg.keys()): - if not any(n["name"] == name for n in load_state().get("nodes", [])): - deploy_container(name, cfg[name]["token"], cfg[name].get("cloud","EU"), - str(cfg[name].get("port","8081")), cfg[name].get("upstream_ip",""), - str(cfg[name].get("upstream_port","80")), "", - cfg[name].get("mode","monitoring")) + cfg[name] = {"token": token, "cloud": cloud, "port": port, + "upstream_ip": upstream_ip, "upstream_port": upstream_port, + "labels": f"group={name}", "mode": mode} + os.makedirs(APP, exist_ok=True) + with open(CONF, "w") as f: json.dump(cfg, f, indent=2) + + # Deploy immediately + print(f"\nDeploying {name}...") + deploy_container(name, token, cloud, port, upstream_ip, upstream_port, f"group={name}", mode) def remove_menu(): s = load_state().get("nodes", [])