Deploy: skrypty zdalne bez CRLF na Windows - bajtowy input do ssh + decode wyjscia (text mode wstrkiwal \r\n do bash)

This commit is contained in:
tisachi
2026-10-17 16:56:08 +02:00
parent f2c7f2d819
commit eceb06bced

View File

@@ -165,16 +165,23 @@ class Remote:
return cmd, env
def exec(self, script: str, timeout: int | None = None) -> str:
script = script.replace("\r\n", "\n")
cmd, env = self._wrap(["ssh", "-o", "ConnectTimeout=15", self.target, "bash -s"])
proc = subprocess.run(cmd, input=script, capture_output=True, text=True, env=env, timeout=timeout)
proc = subprocess.run(
cmd, input=script.encode("utf-8"), capture_output=True, env=env, timeout=timeout
)
out = proc.stdout.decode("utf-8", "replace")
if proc.returncode != 0:
detail = (proc.stderr or proc.stdout or "").strip()
detail = (proc.stderr.decode("utf-8", "replace") or out).strip()
die(f"polecenie zdalne nieudane (exit {proc.returncode}):\n{script}\n{detail}")
return proc.stdout
return out
def check(self, script: str) -> subprocess.CompletedProcess:
script = script.replace("\r\n", "\n")
cmd, env = self._wrap(["ssh", "-o", "ConnectTimeout=15", self.target, "bash -s"])
return subprocess.run(cmd, input=script, capture_output=True, text=True, env=env, timeout=60)
return subprocess.run(
cmd, input=script.encode("utf-8"), capture_output=True, env=env, timeout=60
)
def put(self, local: Path, remote: str) -> None:
cmd, env = self._wrap(
@@ -309,7 +316,7 @@ def wait_health(remote: Remote, remote_dir: str, api_port: str, max_wait_s: int
deadline = time.monotonic() + max_wait_s
while time.monotonic() < deadline:
res = remote.check(f"curl -fsS http://127.0.0.1:{api_port}/health")
if res.returncode == 0 and '"ok"' in res.stdout:
if res.returncode == 0 and '"ok"' in res.stdout.decode("utf-8", "replace"):
ok("API healthy")
return
time.sleep(3)