Skip to content

Commit 197c9e4

Browse files
committed
docker: disable port check if docker is running. fix #694
1 parent 287f173 commit 197c9e4

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

cmdeploy/src/cmdeploy/cmdeploy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def run_cmd(args, out):
100100

101101
cmd = f"{pyinf} --ssh-user root {ssh_host} {deploy_path} -y"
102102
if ssh_host in ["localhost", "@docker"]:
103+
if ssh_host == "@docker":
104+
env["CHATMAIL_DOCKER"] = "True"
103105
cmd = f"{pyinf} @local {deploy_path} -y"
104106

105107
if version.parse(pyinfra.__version__) < version.parse("3"):

cmdeploy/src/cmdeploy/deployers.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,12 @@ def activate(self):
10631063
)
10641064

10651065

1066-
def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
1066+
def deploy_chatmail(config_path: Path, disable_mail: bool, docker: bool) -> None:
10671067
"""Deploy a chat-mail instance.
10681068
10691069
:param config_path: path to chatmail.ini
10701070
:param disable_mail: whether to disable postfix & dovecot
1071+
:param docker: whether it is running in a docker container
10711072
"""
10721073
config = read_config(config_path)
10731074
check_config(config)
@@ -1080,31 +1081,32 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
10801081
line="nameserver 9.9.9.9",
10811082
)
10821083

1083-
port_services = [
1084-
(["master", "smtpd"], 25),
1085-
("unbound", 53),
1086-
("acmetool", 80),
1087-
(["imap-login", "dovecot"], 143),
1088-
("nginx", 443),
1089-
(["master", "smtpd"], 465),
1090-
(["master", "smtpd"], 587),
1091-
(["imap-login", "dovecot"], 993),
1092-
("iroh-relay", 3340),
1093-
("nginx", 8443),
1094-
(["master", "smtpd"], config.postfix_reinject_port),
1095-
(["master", "smtpd"], config.postfix_reinject_port_incoming),
1096-
("filtermail", config.filtermail_smtp_port),
1097-
("filtermail", config.filtermail_smtp_port_incoming),
1098-
]
1099-
for service, port in port_services:
1100-
print(f"Checking if port {port} is available for {service}...")
1101-
running_service = host.get_fact(Port, port=port)
1102-
if running_service:
1103-
if running_service not in service:
1104-
Out().red(
1105-
f"Deploy failed: port {port} is occupied by: {running_service}"
1106-
)
1107-
exit(1)
1084+
if not docker:
1085+
port_services = [
1086+
(["master", "smtpd"], 25),
1087+
("unbound", 53),
1088+
("acmetool", 80),
1089+
(["imap-login", "dovecot"], 143),
1090+
("nginx", 443),
1091+
(["master", "smtpd"], 465),
1092+
(["master", "smtpd"], 587),
1093+
(["imap-login", "dovecot"], 993),
1094+
("iroh-relay", 3340),
1095+
("nginx", 8443),
1096+
(["master", "smtpd"], config.postfix_reinject_port),
1097+
(["master", "smtpd"], config.postfix_reinject_port_incoming),
1098+
("filtermail", config.filtermail_smtp_port),
1099+
("filtermail", config.filtermail_smtp_port_incoming),
1100+
]
1101+
for service, port in port_services:
1102+
print(f"Checking if port {port} is available for {service}...")
1103+
running_service = host.get_fact(Port, port=port)
1104+
if running_service:
1105+
if running_service not in service:
1106+
Out().red(
1107+
f"Deploy failed: port {port} is occupied by: {running_service}"
1108+
)
1109+
exit(1)
11081110

11091111
tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"]
11101112

cmdeploy/src/cmdeploy/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def main():
1414
importlib.resources.files("cmdeploy").joinpath("../../../chatmail.ini"),
1515
)
1616
disable_mail = bool(os.environ.get("CHATMAIL_DISABLE_MAIL"))
17+
docker = bool(os.environ.get("CHATMAIL_DOCKER"))
1718

18-
deploy_chatmail(config_path, disable_mail)
19+
deploy_chatmail(config_path, disable_mail, docker)
1920

2021

2122
if pyinfra.is_cli:

0 commit comments

Comments
 (0)