docker: disable port check if docker is running. fix #694

This commit is contained in:
missytake
2025-11-13 21:29:51 +01:00
committed by j4n
parent 615613bd66
commit 8bba78ebaf
3 changed files with 35 additions and 31 deletions

View File

@@ -109,6 +109,8 @@ def run_cmd(args, out):
cmd = f"{pyinf} --ssh-user root {ssh_host} {deploy_path} -y" cmd = f"{pyinf} --ssh-user root {ssh_host} {deploy_path} -y"
if ssh_host in ["localhost", "@docker"]: if ssh_host in ["localhost", "@docker"]:
if ssh_host == "@docker":
env["CHATMAIL_DOCKER"] = "True"
cmd = f"{pyinf} @local {deploy_path} -y" cmd = f"{pyinf} @local {deploy_path} -y"
if version.parse(pyinfra.__version__) < version.parse("3"): if version.parse(pyinfra.__version__) < version.parse("3"):

View File

@@ -535,12 +535,13 @@ class GithashDeployer(Deployer):
) )
def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -> None: def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool, docker: bool) -> None:
"""Deploy a chat-mail instance. """Deploy a chat-mail instance.
:param config_path: path to chatmail.ini :param config_path: path to chatmail.ini
:param disable_mail: whether to disable postfix & dovecot :param disable_mail: whether to disable postfix & dovecot
:param website_only: if True, only deploy the website :param website_only: if True, only deploy the website
:param docker: whether it is running in a docker container
""" """
config = read_config(config_path) config = read_config(config_path)
check_config(config) check_config(config)
@@ -566,34 +567,35 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -
Out().red(f"Deploy failed: mtail_address {config.mtail_address} is not available (VPN up?).\n") Out().red(f"Deploy failed: mtail_address {config.mtail_address} is not available (VPN up?).\n")
exit(1) exit(1)
port_services = [ if not docker:
(["master", "smtpd"], 25), port_services = [
("unbound", 53), (["master", "smtpd"], 25),
("acmetool", 80), ("unbound", 53),
(["imap-login", "dovecot"], 143), ("acmetool", 80),
("nginx", 443), (["imap-login", "dovecot"], 143),
(["master", "smtpd"], 465), ("nginx", 443),
(["master", "smtpd"], 587), (["master", "smtpd"], 465),
(["imap-login", "dovecot"], 993), (["master", "smtpd"], 587),
("iroh-relay", 3340), (["imap-login", "dovecot"], 993),
("mtail", 3903), ("iroh-relay", 3340),
("stats", 3904), ("mtail", 3903),
("nginx", 8443), ("stats", 3904),
(["master", "smtpd"], config.postfix_reinject_port), ("nginx", 8443),
(["master", "smtpd"], config.postfix_reinject_port_incoming), (["master", "smtpd"], config.postfix_reinject_port),
("filtermail", config.filtermail_smtp_port), (["master", "smtpd"], config.postfix_reinject_port_incoming),
("filtermail", config.filtermail_smtp_port_incoming), ("filtermail", config.filtermail_smtp_port),
] ("filtermail", config.filtermail_smtp_port_incoming),
for service, port in port_services: ]
print(f"Checking if port {port} is available for {service}...") for service, port in port_services:
running_service = host.get_fact(Port, port=port) print(f"Checking if port {port} is available for {service}...")
services = [service] if isinstance(service, str) else service running_service = host.get_fact(Port, port=port)
if running_service: services = [service] if isinstance(service, str) else service
if running_service not in services: if running_service:
Out().red( if running_service not in services:
f"Deploy failed: port {port} is occupied by: {running_service}" Out().red(
) f"Deploy failed: port {port} is occupied by: {running_service}"
exit(1) )
exit(1)
tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"] tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"]

View File

@@ -15,8 +15,8 @@ def main():
) )
disable_mail = bool(os.environ.get("CHATMAIL_DISABLE_MAIL")) disable_mail = bool(os.environ.get("CHATMAIL_DISABLE_MAIL"))
website_only = bool(os.environ.get("CHATMAIL_WEBSITE_ONLY")) website_only = bool(os.environ.get("CHATMAIL_WEBSITE_ONLY"))
docker = bool(os.environ.get("CHATMAIL_DOCKER"))
deploy_chatmail(config_path, disable_mail, website_only) deploy_chatmail(config_path, disable_mail, website_only, docker)
if pyinfra.is_cli: if pyinfra.is_cli: