From a9e55e3b2501bf2d9eb49e436b75164537d21085 Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 13 Dec 2023 15:10:32 +0100 Subject: [PATCH] cmdeploy: get cmdeploy run --config working --- cmdeploy/src/cmdeploy/__init__.py | 22 ++++++++++------------ cmdeploy/src/cmdeploy/cmdeploy.py | 4 ++-- cmdeploy/src/cmdeploy/deploy.py | 14 ++++++-------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 3e3a7082..cdde08cd 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -114,7 +114,7 @@ def _install_remote_venv_with_chatmaild(config) -> None: ) -def _configure_opendkim(domain: str, dkim_selector: str) -> bool: +def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool: """Configures OpenDKIM""" need_restart = False @@ -359,13 +359,15 @@ def check_config(config): return config -def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> None: +def deploy_chatmail(config_path: Path) -> None: """Deploy a chat-mail instance. - :param mail_domain: domain part of your future email addresses - :param mail_server: the DNS name under which your mail server is reachable - :param dkim_selector: + :param config_path: path to chatmail.ini """ + config = read_config(config_path) + check_config(config) + mail_domain = config.mail_domain + from .www import build_webpages apt.update(name="apt update", cache_time=24 * 3600) @@ -395,7 +397,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N ) # Deploy acmetool to have TLS certificates. - deploy_acmetool(nginx_hook=True, domains=[mail_server, f"mta-sts.{mail_server}"]) + deploy_acmetool(nginx_hook=True, domains=[mail_domain, f"mta-sts.{mail_domain}"]) apt.packages( name="Install Postfix", @@ -425,11 +427,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N packages=["fcgiwrap"], ) - pkg_root = importlib.resources.files(__package__) - chatmail_ini = pkg_root.joinpath("../../../chatmail.ini").resolve() - config = read_config(chatmail_ini) - check_config(config) - www_path = pkg_root.joinpath("../../../www").resolve() + www_path = importlib.resources.files(__package__).joinpath("../../../www").resolve() build_dir = www_path.joinpath("build") src_dir = www_path.joinpath("src") @@ -440,7 +438,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N debug = False dovecot_need_restart = _configure_dovecot(config, debug=debug) postfix_need_restart = _configure_postfix(config, debug=debug) - opendkim_need_restart = _configure_opendkim(mail_domain, dkim_selector) + opendkim_need_restart = _configure_opendkim(mail_domain) mta_sts_need_restart = _install_mta_sts_daemon() nginx_need_restart = _configure_nginx(mail_domain) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index d717f74a..0f78c64b 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -52,8 +52,8 @@ def run_cmd(args, out): """Deploy chatmail services on the remote server.""" env = os.environ.copy() - env["CHATMAIL_DOMAIN"] = args.config.mail_domain - deploy_path = "cmdeploy/src/cmdeploy/deploy.py" + env["CHATMAIL_INI"] = args.inipath + deploy_path = importlib.resources.files(__package__).joinpath("deploy.py").resolve() pyinf = "pyinfra --dry" if args.dry_run else "pyinfra" cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path}" out.check_call(cmd, env=env) diff --git a/cmdeploy/src/cmdeploy/deploy.py b/cmdeploy/src/cmdeploy/deploy.py index dfd44216..d7d4e03b 100644 --- a/cmdeploy/src/cmdeploy/deploy.py +++ b/cmdeploy/src/cmdeploy/deploy.py @@ -1,18 +1,16 @@ import os +import importlib.resources import pyinfra from cmdeploy import deploy_chatmail def main(): - mail_domain = os.getenv("CHATMAIL_DOMAIN") - mail_server = os.getenv("CHATMAIL_SERVER", mail_domain) - dkim_selector = os.getenv("CHATMAIL_DKIM_SELECTOR", "dkim") + config_path = os.getenv( + "CHATMAIL_INI", + importlib.resources.files("cmdeploy").joinpath("../../../chatmail.ini"), + ) - assert mail_domain - assert mail_server - assert dkim_selector - - deploy_chatmail(mail_domain, mail_server, dkim_selector) + deploy_chatmail(config_path) if pyinfra.is_cli: