cmdeploy: prepare for being able to run commands in docker containers

This commit is contained in:
missytake
2025-10-08 10:18:53 +02:00
parent 185757cf40
commit 79591adca4
2 changed files with 7 additions and 3 deletions

View File

@@ -99,7 +99,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"):
@@ -303,7 +303,7 @@ def add_ssh_host_option(parser):
parser.add_argument(
"--ssh-host",
dest="ssh_host",
help="Run commands on 'localhost' or a specific SSH host "
help="Run commands on 'localhost', via '@docker', or on a specific SSH host "
"instead of chatmail.ini's mail_domain.",
)
@@ -366,6 +366,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)

View File

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