From 0adeefbdd73c5bbb2b29e78e8203972151ddd3f4 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 6 Mar 2026 10:52:08 +0100 Subject: [PATCH] fix lxc-test to not re-run deploy when nothing changed + some other beautifications --- cmdeploy/src/cmdeploy/lxc/cli.py | 12 +++++------- cmdeploy/src/cmdeploy/lxc/incus.py | 13 ++++++------- cmdeploy/src/cmdeploy/util.py | 6 ++++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cmdeploy/src/cmdeploy/lxc/cli.py b/cmdeploy/src/cmdeploy/lxc/cli.py index 1718a74d..df536e02 100644 --- a/cmdeploy/src/cmdeploy/lxc/cli.py +++ b/cmdeploy/src/cmdeploy/lxc/cli.py @@ -37,15 +37,13 @@ def lxc_start_cmd_options(parser): def lxc_start_cmd(args, out): """Create/Ensure and start LXC relay and DNS containers.""" ix = Incus() - relays = [ix.get_container(n) for n in args.names] or [ - ix.get_container(RELAY_NAMES[0]) - ] out.green("Ensuring DNS container (ns-localchat) ...") dns_ct = ix.get_dns_container() dns_ct.ensure() - dns_ip = dns_ct.ipv4 - print(f" DNS container IP: {dns_ip}") + print(f" DNS container IP: {dns_ct.ipv4}") + names = args.names if args.names else RELAY_NAMES + relays = list(ix.get_container(n) for n in names) for ct in relays: out.green(f"Ensuring container {ct.name!r} ({ct.domain}) ...") ct.ensure() @@ -81,12 +79,12 @@ def lxc_start_cmd(args, out): print( f"Resetting DNS zones for {len(started)} domain(s) (A + AAAA records) ..." ) - dns_ct.reset_dns_records(dns_ip, started) + dns_ct.reset_dns_records(dns_ct.ipv4, started) for ct in relays: if ct.name in started_cnames: print(f" Configuring DNS in {ct.name} ...") - ct.configure_dns(dns_ip) + ct.configure_dns(dns_ct.ipv4) # Generate the unified SSH config out.green("Writing ssh-config ...") diff --git a/cmdeploy/src/cmdeploy/lxc/incus.py b/cmdeploy/src/cmdeploy/lxc/incus.py index 59d7a331..dd2bb6a5 100644 --- a/cmdeploy/src/cmdeploy/lxc/incus.py +++ b/cmdeploy/src/cmdeploy/lxc/incus.py @@ -120,7 +120,7 @@ class Incus: return json.loads(result.stdout) def run_output(self, args, check=True): - """Run an incus command and return its stdout. + """Run an incus command and return its stripped stdout. When *check* is False, returns *None* on non-zero exit instead of raising. @@ -128,7 +128,7 @@ class Incus: result = self.run(args, check=check) if result.returncode != 0: return None - return result.stdout + return result.stdout.strip() def _find_image(self, alias): """Return *alias* if an image with that alias exists, else None.""" @@ -396,9 +396,10 @@ class RelayContainer(Container): def configure_hosts(self, ip): """Set hostname and /etc/hosts inside the container.""" - self.bash(f"""\ + self.bash(f""" echo '{self.name}' > /etc/hostname hostname {self.name} + sed -i '/ {self.domain}$/d' /etc/hosts echo '{ip} {self.name} {self.domain}' >> /etc/hosts """) @@ -419,16 +420,14 @@ class RelayContainer(Container): def deployed_version(self): """Read /etc/chatmail-version, or None if absent.""" - output = self.bash("cat /etc/chatmail-version", check=False) - return output.strip() if output else None + return self.bash("cat /etc/chatmail-version", check=False) def deployed_domain(self): """Read the domain deployed on the container (postfix myhostname).""" - output = self.bash( + return self.bash( "postconf -h myhostname 2>/dev/null", check=False, ) - return output.strip() if output else None def verify_ssh(self, ssh_config): """Verify SSH connectivity to this container.""" diff --git a/cmdeploy/src/cmdeploy/util.py b/cmdeploy/src/cmdeploy/util.py index bd0b2fe3..9f2c2da0 100644 --- a/cmdeploy/src/cmdeploy/util.py +++ b/cmdeploy/src/cmdeploy/util.py @@ -57,7 +57,9 @@ def get_version_string(): """ git_hash = get_git_hash() or "unknown" try: - git_diff = shell("git diff", cwd=str(_project_root())).stdout + git_diff = shell("git diff", cwd=str(_project_root())).stdout.strip() except Exception: git_diff = "" - return git_hash + "\n" + git_diff + if git_diff: + return f"{git_hash}\n{git_diff}" + return git_hash