feat(deployer): add deb package distribution and install via scp/apt

This commit is contained in:
2026-08-24 11:25:43 +08:00
parent e4d4319919
commit e7a139e2cb
5 changed files with 273 additions and 25 deletions
+29
View File
@@ -221,6 +221,35 @@ def rsync_ssh_args(info: dict) -> list[str]:
return ["-e", shlex.join(base)]
def scp_base_args(info: dict) -> list[str]:
"""scp 可执行文件及 -P / -i 选项(注意 scp 的端口是大写 P)。"""
args = ["scp"]
port = info.get("port")
if port is not None:
args.extend(["-P", str(port)])
identity_file = info.get("identity_file")
if identity_file:
args.extend(["-i", identity_file])
return args
def run_remote(info: dict, remote_command: str, *, remote_cwd: str | None = None) -> int:
"""在远程节点执行 shell 命令并返回退出码;remote_cwd 提供时先切换目录。"""
shell = f"cd {remote_cwd} && {remote_command}" if remote_cwd else remote_command
endpoint = info["node"]
if info.get("port") is not None:
endpoint += f":{info['port']}"
location = f"{endpoint} {remote_cwd}" if remote_cwd else endpoint
print(f"远程执行: {location}")
print(f"$ {remote_command}")
print("-" * 60)
try:
return subprocess.run(ssh_cmd(info, shell), check=False).returncode
except FileNotFoundError:
print("错误: ssh 命令未找到")
return 1
def node_from_parent_dir(service_dir: str) -> str | None:
"""父目录名若是 SSH Host 别名,则作为 node。"""
parent = Path(service_dir.rstrip("/")).parent.name