fix lxc-test to not re-run deploy when nothing changed + some other beautifications

This commit is contained in:
holger krekel
2026-03-06 10:52:08 +01:00
parent 49705863d3
commit b59417128c
3 changed files with 15 additions and 16 deletions

View File

@@ -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 ...")

View File

@@ -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."""

View File

@@ -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