mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 20:08:21 +00:00
fix lxc-test to not re-run deploy when nothing changed + some other beautifications
This commit is contained in:
@@ -37,15 +37,13 @@ def lxc_start_cmd_options(parser):
|
|||||||
def lxc_start_cmd(args, out):
|
def lxc_start_cmd(args, out):
|
||||||
"""Create/Ensure and start LXC relay and DNS containers."""
|
"""Create/Ensure and start LXC relay and DNS containers."""
|
||||||
ix = Incus()
|
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) ...")
|
out.green("Ensuring DNS container (ns-localchat) ...")
|
||||||
dns_ct = ix.get_dns_container()
|
dns_ct = ix.get_dns_container()
|
||||||
dns_ct.ensure()
|
dns_ct.ensure()
|
||||||
dns_ip = dns_ct.ipv4
|
print(f" DNS container IP: {dns_ct.ipv4}")
|
||||||
print(f" DNS container IP: {dns_ip}")
|
|
||||||
|
|
||||||
|
names = args.names if args.names else RELAY_NAMES
|
||||||
|
relays = list(ix.get_container(n) for n in names)
|
||||||
for ct in relays:
|
for ct in relays:
|
||||||
out.green(f"Ensuring container {ct.name!r} ({ct.domain}) ...")
|
out.green(f"Ensuring container {ct.name!r} ({ct.domain}) ...")
|
||||||
ct.ensure()
|
ct.ensure()
|
||||||
@@ -81,12 +79,12 @@ def lxc_start_cmd(args, out):
|
|||||||
print(
|
print(
|
||||||
f"Resetting DNS zones for {len(started)} domain(s) (A + AAAA records) ..."
|
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:
|
for ct in relays:
|
||||||
if ct.name in started_cnames:
|
if ct.name in started_cnames:
|
||||||
print(f" Configuring DNS in {ct.name} ...")
|
print(f" Configuring DNS in {ct.name} ...")
|
||||||
ct.configure_dns(dns_ip)
|
ct.configure_dns(dns_ct.ipv4)
|
||||||
|
|
||||||
# Generate the unified SSH config
|
# Generate the unified SSH config
|
||||||
out.green("Writing ssh-config ...")
|
out.green("Writing ssh-config ...")
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class Incus:
|
|||||||
return json.loads(result.stdout)
|
return json.loads(result.stdout)
|
||||||
|
|
||||||
def run_output(self, args, check=True):
|
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
|
When *check* is False, returns *None* on non-zero exit
|
||||||
instead of raising.
|
instead of raising.
|
||||||
@@ -128,7 +128,7 @@ class Incus:
|
|||||||
result = self.run(args, check=check)
|
result = self.run(args, check=check)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
return None
|
return None
|
||||||
return result.stdout
|
return result.stdout.strip()
|
||||||
|
|
||||||
def _find_image(self, alias):
|
def _find_image(self, alias):
|
||||||
"""Return *alias* if an image with that alias exists, else None."""
|
"""Return *alias* if an image with that alias exists, else None."""
|
||||||
@@ -396,9 +396,10 @@ class RelayContainer(Container):
|
|||||||
|
|
||||||
def configure_hosts(self, ip):
|
def configure_hosts(self, ip):
|
||||||
"""Set hostname and /etc/hosts inside the container."""
|
"""Set hostname and /etc/hosts inside the container."""
|
||||||
self.bash(f"""\
|
self.bash(f"""
|
||||||
echo '{self.name}' > /etc/hostname
|
echo '{self.name}' > /etc/hostname
|
||||||
hostname {self.name}
|
hostname {self.name}
|
||||||
|
sed -i '/ {self.domain}$/d' /etc/hosts
|
||||||
echo '{ip} {self.name} {self.domain}' >> /etc/hosts
|
echo '{ip} {self.name} {self.domain}' >> /etc/hosts
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@@ -419,16 +420,14 @@ class RelayContainer(Container):
|
|||||||
|
|
||||||
def deployed_version(self):
|
def deployed_version(self):
|
||||||
"""Read /etc/chatmail-version, or None if absent."""
|
"""Read /etc/chatmail-version, or None if absent."""
|
||||||
output = self.bash("cat /etc/chatmail-version", check=False)
|
return self.bash("cat /etc/chatmail-version", check=False)
|
||||||
return output.strip() if output else None
|
|
||||||
|
|
||||||
def deployed_domain(self):
|
def deployed_domain(self):
|
||||||
"""Read the domain deployed on the container (postfix myhostname)."""
|
"""Read the domain deployed on the container (postfix myhostname)."""
|
||||||
output = self.bash(
|
return self.bash(
|
||||||
"postconf -h myhostname 2>/dev/null",
|
"postconf -h myhostname 2>/dev/null",
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
return output.strip() if output else None
|
|
||||||
|
|
||||||
def verify_ssh(self, ssh_config):
|
def verify_ssh(self, ssh_config):
|
||||||
"""Verify SSH connectivity to this container."""
|
"""Verify SSH connectivity to this container."""
|
||||||
|
|||||||
@@ -57,7 +57,9 @@ def get_version_string():
|
|||||||
"""
|
"""
|
||||||
git_hash = get_git_hash() or "unknown"
|
git_hash = get_git_hash() or "unknown"
|
||||||
try:
|
try:
|
||||||
git_diff = shell("git diff", cwd=str(_project_root())).stdout
|
git_diff = shell("git diff", cwd=str(_project_root())).stdout.strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
git_diff = ""
|
git_diff = ""
|
||||||
return git_hash + "\n" + git_diff
|
if git_diff:
|
||||||
|
return f"{git_hash}\n{git_diff}"
|
||||||
|
return git_hash
|
||||||
|
|||||||
Reference in New Issue
Block a user