mirror of
https://github.com/chatmail/relay.git
synced 2026-06-09 21:21:09 +00:00
fix(cmdeploy): docker: route test commands through container via CHATMAIL_DOCKER
Tests SSH into the host and run systemctl/journalctl/env directly, which fails on Docker deployments where services run inside the container. When CHATMAIL_DOCKER is set (to container name), Remote and SSHExec now wrap commands in `docker exec`. Without CHATMAIL_DOCKER, behavior is unchanged.
This commit is contained in:
@@ -50,6 +50,9 @@ class SSHExec:
|
||||
FuncError = FuncError
|
||||
|
||||
def __init__(self, host, verbose=False, python="python3", timeout=60):
|
||||
docker_container = os.environ.get("CHATMAIL_DOCKER")
|
||||
if docker_container:
|
||||
python = f"docker exec -i {docker_container} python3"
|
||||
self.gateway = execnet.makegateway(f"ssh=root@{host}//python={python}")
|
||||
self._remote_cmdloop_channel = bootstrap_remote(self.gateway, remote)
|
||||
self.timeout = timeout
|
||||
|
||||
@@ -402,6 +402,9 @@ class Remote:
|
||||
case "@local": command = []
|
||||
case "localhost": command = []
|
||||
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
||||
docker_container = os.environ.get("CHATMAIL_DOCKER")
|
||||
if docker_container:
|
||||
command += ["docker", "exec", docker_container]
|
||||
[command.append(arg) for arg in getjournal.split()]
|
||||
self.popen = subprocess.Popen(
|
||||
command,
|
||||
|
||||
Reference in New Issue
Block a user