diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 9877dd0e..9888b007 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -109,6 +109,8 @@ def run_cmd(args, out): cmd = f"{pyinf} --ssh-user root {ssh_host} {deploy_path} -y" if ssh_host in ["localhost", "@docker"]: + if ssh_host == "@docker": + env["CHATMAIL_DOCKER"] = "True" cmd = f"{pyinf} @local {deploy_path} -y" if version.parse(pyinfra.__version__) < version.parse("3"): diff --git a/cmdeploy/src/cmdeploy/deployers.py b/cmdeploy/src/cmdeploy/deployers.py index 5812aa28..d9a549d9 100644 --- a/cmdeploy/src/cmdeploy/deployers.py +++ b/cmdeploy/src/cmdeploy/deployers.py @@ -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. :param config_path: path to chatmail.ini :param disable_mail: whether to disable postfix & dovecot :param website_only: if True, only deploy the website + :param docker: whether it is running in a docker container """ config = read_config(config_path) 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") exit(1) - port_services = [ - (["master", "smtpd"], 25), - ("unbound", 53), - ("acmetool", 80), - (["imap-login", "dovecot"], 143), - ("nginx", 443), - (["master", "smtpd"], 465), - (["master", "smtpd"], 587), - (["imap-login", "dovecot"], 993), - ("iroh-relay", 3340), - ("mtail", 3903), - ("stats", 3904), - ("nginx", 8443), - (["master", "smtpd"], config.postfix_reinject_port), - (["master", "smtpd"], config.postfix_reinject_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}...") - running_service = host.get_fact(Port, port=port) - services = [service] if isinstance(service, str) else service - if running_service: - if running_service not in services: - Out().red( - f"Deploy failed: port {port} is occupied by: {running_service}" - ) - exit(1) + if not docker: + port_services = [ + (["master", "smtpd"], 25), + ("unbound", 53), + ("acmetool", 80), + (["imap-login", "dovecot"], 143), + ("nginx", 443), + (["master", "smtpd"], 465), + (["master", "smtpd"], 587), + (["imap-login", "dovecot"], 993), + ("iroh-relay", 3340), + ("mtail", 3903), + ("stats", 3904), + ("nginx", 8443), + (["master", "smtpd"], config.postfix_reinject_port), + (["master", "smtpd"], config.postfix_reinject_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}...") + running_service = host.get_fact(Port, port=port) + services = [service] if isinstance(service, str) else service + if running_service: + if running_service not in services: + Out().red( + f"Deploy failed: port {port} is occupied by: {running_service}" + ) + exit(1) tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"] diff --git a/cmdeploy/src/cmdeploy/run.py b/cmdeploy/src/cmdeploy/run.py index 0b0fc858..91f96d7d 100644 --- a/cmdeploy/src/cmdeploy/run.py +++ b/cmdeploy/src/cmdeploy/run.py @@ -15,8 +15,8 @@ def main(): ) disable_mail = bool(os.environ.get("CHATMAIL_DISABLE_MAIL")) website_only = bool(os.environ.get("CHATMAIL_WEBSITE_ONLY")) - - deploy_chatmail(config_path, disable_mail, website_only) + docker = bool(os.environ.get("CHATMAIL_DOCKER")) + deploy_chatmail(config_path, disable_mail, website_only, docker) if pyinfra.is_cli: