From 3e3a85523d642d1fccae498b8ee8542e2cb99105 Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 8 Oct 2025 10:18:53 +0200 Subject: [PATCH] cmdeploy: prepare for being able to run commands in docker containers --- cmdeploy/src/cmdeploy/cmdeploy.py | 8 +++++--- cmdeploy/src/cmdeploy/dns.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 8ae2481b..8f0bfbf0 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -61,7 +61,7 @@ def run_cmd_options(parser): parser.add_argument( "--ssh-host", dest="ssh_host", - help="Deploy to 'localhost' or to a specific SSH host", + help="Deploy to 'localhost', via 'docker', or to a specific SSH host", ) @@ -83,7 +83,7 @@ def run_cmd(args, out): pyinf = "pyinfra --dry" if args.dry_run else "pyinfra" cmd = f"{pyinf} --ssh-user root {ssh_host} {deploy_path} -y" - if ssh_host == "localhost": + if ssh_host in ["localhost", "docker"]: cmd = f"{pyinf} @local {deploy_path} -y" if version.parse(pyinfra.__version__) < version.parse("3"): @@ -125,7 +125,7 @@ def dns_cmd_options(parser): parser.add_argument( "--ssh-host", dest="ssh_host", - help="Run the DNS queries on 'localhost' or on a specific SSH host", + help="Run the DNS queries on 'localhost', via 'docker', or on a specific SSH host", ) @@ -344,6 +344,8 @@ def get_parser(): def get_sshexec(ssh_host: str, verbose=True): if ssh_host in ["localhost", "@local"]: return "localhost" + elif ssh_host == "docker": + return "docker" if verbose: print(f"[ssh] login to {ssh_host}") return SSHExec(ssh_host, verbose=verbose) diff --git a/cmdeploy/src/cmdeploy/dns.py b/cmdeploy/src/cmdeploy/dns.py index 6277d158..0562181a 100644 --- a/cmdeploy/src/cmdeploy/dns.py +++ b/cmdeploy/src/cmdeploy/dns.py @@ -9,6 +9,8 @@ from . import remote def get_initial_remote_data(sshexec, mail_domain): if sshexec == "localhost": result = remote.rdns.perform_initial_checks(mail_domain) + elif sshexec == "docker": + result = remote.rdns.perform_initial_checks(mail_domain, pre_command="docker exec chatmail ") else: result = sshexec.logged( call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain) @@ -48,7 +50,7 @@ def check_full_zone(sshexec, remote_data, out, zonefile) -> int: """Check existing DNS records, optionally write them to zone file and return (exitcode, remote_data) tuple.""" - if sshexec == "localhost": + if sshexec in ["localhost", "docker"]: required_diff, recommended_diff = remote.rdns.check_zonefile( zonefile=zonefile, verbose=False )