cmdeploy: get cmdeploy run --config working

This commit is contained in:
missytake
2023-12-13 15:10:32 +01:00
parent 5a178ed235
commit a9e55e3b25
3 changed files with 18 additions and 22 deletions

View File

@@ -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""" """Configures OpenDKIM"""
need_restart = False need_restart = False
@@ -359,13 +359,15 @@ def check_config(config):
return 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. """Deploy a chat-mail instance.
:param mail_domain: domain part of your future email addresses :param config_path: path to chatmail.ini
:param mail_server: the DNS name under which your mail server is reachable
:param dkim_selector:
""" """
config = read_config(config_path)
check_config(config)
mail_domain = config.mail_domain
from .www import build_webpages from .www import build_webpages
apt.update(name="apt update", cache_time=24 * 3600) 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 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( apt.packages(
name="Install Postfix", name="Install Postfix",
@@ -425,11 +427,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
packages=["fcgiwrap"], packages=["fcgiwrap"],
) )
pkg_root = importlib.resources.files(__package__) www_path = importlib.resources.files(__package__).joinpath("../../../www").resolve()
chatmail_ini = pkg_root.joinpath("../../../chatmail.ini").resolve()
config = read_config(chatmail_ini)
check_config(config)
www_path = pkg_root.joinpath("../../../www").resolve()
build_dir = www_path.joinpath("build") build_dir = www_path.joinpath("build")
src_dir = www_path.joinpath("src") 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 debug = False
dovecot_need_restart = _configure_dovecot(config, debug=debug) dovecot_need_restart = _configure_dovecot(config, debug=debug)
postfix_need_restart = _configure_postfix(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() mta_sts_need_restart = _install_mta_sts_daemon()
nginx_need_restart = _configure_nginx(mail_domain) nginx_need_restart = _configure_nginx(mail_domain)

View File

@@ -52,8 +52,8 @@ def run_cmd(args, out):
"""Deploy chatmail services on the remote server.""" """Deploy chatmail services on the remote server."""
env = os.environ.copy() env = os.environ.copy()
env["CHATMAIL_DOMAIN"] = args.config.mail_domain env["CHATMAIL_INI"] = args.inipath
deploy_path = "cmdeploy/src/cmdeploy/deploy.py" deploy_path = importlib.resources.files(__package__).joinpath("deploy.py").resolve()
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra" pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path}" cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path}"
out.check_call(cmd, env=env) out.check_call(cmd, env=env)

View File

@@ -1,18 +1,16 @@
import os import os
import importlib.resources
import pyinfra import pyinfra
from cmdeploy import deploy_chatmail from cmdeploy import deploy_chatmail
def main(): def main():
mail_domain = os.getenv("CHATMAIL_DOMAIN") config_path = os.getenv(
mail_server = os.getenv("CHATMAIL_SERVER", mail_domain) "CHATMAIL_INI",
dkim_selector = os.getenv("CHATMAIL_DKIM_SELECTOR", "dkim") importlib.resources.files("cmdeploy").joinpath("../../../chatmail.ini"),
)
assert mail_domain deploy_chatmail(config_path)
assert mail_server
assert dkim_selector
deploy_chatmail(mail_domain, mail_server, dkim_selector)
if pyinfra.is_cli: if pyinfra.is_cli: