mirror of
https://github.com/chatmail/relay.git
synced 2026-05-21 05:18:04 +00:00
run pyinfra command with environment variables, without inventory.py
This commit is contained in:
@@ -12,3 +12,9 @@ Dovecot listens on ports 143(imap) and 993 (imaps).
|
|||||||
## DNS
|
## DNS
|
||||||
|
|
||||||
For DKIM you must add a DNS entry as in /etc/opendkim/selector.txt (where selector is the opendkim_selector configured in the chatmail inventory).
|
For DKIM you must add a DNS entry as in /etc/opendkim/selector.txt (where selector is the opendkim_selector configured in the chatmail inventory).
|
||||||
|
|
||||||
|
## Run with pyinfra
|
||||||
|
|
||||||
|
```
|
||||||
|
CHATMAIL_DOMAIN=c1.testrun.org pyinfra c1.testrun.org deploy.py
|
||||||
|
```
|
||||||
|
|||||||
11
deploy.py
11
deploy.py
@@ -2,4 +2,13 @@ import os
|
|||||||
from pyinfra import host, facts
|
from pyinfra import host, facts
|
||||||
from chatmail import deploy_chatmail
|
from chatmail import deploy_chatmail
|
||||||
|
|
||||||
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", "2023")
|
||||||
|
|
||||||
|
deploy_chatmail(mail_domain, mail_server, dkim_selector)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -5,3 +5,6 @@ build-backend = "setuptools.build_meta"
|
|||||||
[project]
|
[project]
|
||||||
name = "chatmail"
|
name = "chatmail"
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
|
dependencies = [
|
||||||
|
"pyinfra",
|
||||||
|
]
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def _configure_postfix(domain: str) -> bool:
|
|||||||
return need_restart
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
def _configure_dovecot(domain: str) -> bool:
|
def _configure_dovecot(mail_server: str) -> bool:
|
||||||
"""Configures Dovecot IMAP server."""
|
"""Configures Dovecot IMAP server."""
|
||||||
need_restart = False
|
need_restart = False
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ def _configure_dovecot(domain: str) -> bool:
|
|||||||
user="root",
|
user="root",
|
||||||
group="root",
|
group="root",
|
||||||
mode="644",
|
mode="644",
|
||||||
config={"hostname": domain},
|
config={"hostname": mail_server},
|
||||||
)
|
)
|
||||||
need_restart |= main_config.changed
|
need_restart |= main_config.changed
|
||||||
|
|
||||||
@@ -115,9 +115,13 @@ def _configure_dovecot(domain: str) -> bool:
|
|||||||
return need_restart
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
def deploy_chatmail() -> None:
|
def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> None:
|
||||||
domain = host.data.domain
|
"""Deploy a chat-mail instance.
|
||||||
dkim_selector = host.data.dkim_selector
|
|
||||||
|
:param mail_domain: the domain part of your future email addresses, so "example.org" in user@example.org
|
||||||
|
:param mail_server: the DNS name under which your mail server is reachable
|
||||||
|
:param dkim_selector:
|
||||||
|
"""
|
||||||
|
|
||||||
apt.update(name="apt update")
|
apt.update(name="apt update")
|
||||||
server.group(name="Create vmail group", group="vmail", system=True)
|
server.group(name="Create vmail group", group="vmail", system=True)
|
||||||
@@ -132,7 +136,7 @@ def deploy_chatmail() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Deploy acmetool to have TLS certificates.
|
# Deploy acmetool to have TLS certificates.
|
||||||
deploy_acmetool(domains=[domain])
|
deploy_acmetool(domains=[mail_server])
|
||||||
|
|
||||||
apt.packages(
|
apt.packages(
|
||||||
name="Install Postfix",
|
name="Install Postfix",
|
||||||
@@ -157,9 +161,9 @@ def deploy_chatmail() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
_install_chatctl()
|
_install_chatctl()
|
||||||
dovecot_need_restart = _configure_dovecot(domain)
|
dovecot_need_restart = _configure_dovecot(mail_server)
|
||||||
postfix_need_restart = _configure_postfix(domain)
|
postfix_need_restart = _configure_postfix(mail_domain)
|
||||||
opendkim_need_restart = _configure_opendkim(domain, dkim_selector)
|
opendkim_need_restart = _configure_opendkim(mail_domain, dkim_selector)
|
||||||
|
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="Start and enable OpenDKIM",
|
name="Start and enable OpenDKIM",
|
||||||
|
|||||||
Reference in New Issue
Block a user