mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 04:48:06 +00:00
refactor: Add IrohDeployer
- This splits the existing deploy_iroh_relay() routine into methods for the install, configure, and activate stages.
This commit is contained in:
@@ -802,7 +802,13 @@ def deploy_mtail(config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def deploy_iroh_relay(config) -> None:
|
class IrohDeployer(Deployer):
|
||||||
|
def __init__(self, *, enable_iroh_relay, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.enable_iroh_relay = enable_iroh_relay
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def install_impl():
|
||||||
(url, sha256sum) = {
|
(url, sha256sum) = {
|
||||||
"x86_64": (
|
"x86_64": (
|
||||||
"https://github.com/n0-computer/iroh/releases/download/v0.35.0/iroh-relay-v0.35.0-x86_64-unknown-linux-musl.tar.gz",
|
"https://github.com/n0-computer/iroh/releases/download/v0.35.0/iroh-relay-v0.35.0-x86_64-unknown-linux-musl.tar.gz",
|
||||||
@@ -819,8 +825,6 @@ def deploy_iroh_relay(config) -> None:
|
|||||||
packages=["curl"],
|
packages=["curl"],
|
||||||
)
|
)
|
||||||
|
|
||||||
need_restart = False
|
|
||||||
|
|
||||||
existing_sha256sum = host.get_fact(Sha256File, "/usr/local/bin/iroh-relay")
|
existing_sha256sum = host.get_fact(Sha256File, "/usr/local/bin/iroh-relay")
|
||||||
if existing_sha256sum != sha256sum:
|
if existing_sha256sum != sha256sum:
|
||||||
server.shell(
|
server.shell(
|
||||||
@@ -830,8 +834,14 @@ def deploy_iroh_relay(config) -> None:
|
|||||||
"chmod 755 /usr/local/bin/iroh-relay",
|
"chmod 755 /usr/local/bin/iroh-relay",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
need_restart = True
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# This will set need_restart when called from an object's
|
||||||
|
# install() method.
|
||||||
|
#
|
||||||
|
return True
|
||||||
|
|
||||||
|
def configure_impl(self):
|
||||||
systemd_unit = files.put(
|
systemd_unit = files.put(
|
||||||
name="Upload iroh-relay systemd unit",
|
name="Upload iroh-relay systemd unit",
|
||||||
src=importlib.resources.files(__package__).joinpath("iroh-relay.service"),
|
src=importlib.resources.files(__package__).joinpath("iroh-relay.service"),
|
||||||
@@ -840,7 +850,7 @@ def deploy_iroh_relay(config) -> None:
|
|||||||
group="root",
|
group="root",
|
||||||
mode="644",
|
mode="644",
|
||||||
)
|
)
|
||||||
need_restart |= systemd_unit.changed
|
self.need_restart |= systemd_unit.changed
|
||||||
|
|
||||||
iroh_config = files.put(
|
iroh_config = files.put(
|
||||||
name="Upload iroh-relay config",
|
name="Upload iroh-relay config",
|
||||||
@@ -850,15 +860,17 @@ def deploy_iroh_relay(config) -> None:
|
|||||||
group="root",
|
group="root",
|
||||||
mode="644",
|
mode="644",
|
||||||
)
|
)
|
||||||
need_restart |= iroh_config.changed
|
self.need_restart |= iroh_config.changed
|
||||||
|
|
||||||
|
def activate_impl(self):
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="Start and enable iroh-relay",
|
name="Start and enable iroh-relay",
|
||||||
service="iroh-relay.service",
|
service="iroh-relay.service",
|
||||||
running=True,
|
running=True,
|
||||||
enabled=config.enable_iroh_relay,
|
enabled=self.enable_iroh_relay,
|
||||||
restarted=need_restart,
|
restarted=self.need_restart,
|
||||||
)
|
)
|
||||||
|
self.need_restart = False
|
||||||
|
|
||||||
|
|
||||||
def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
||||||
@@ -879,6 +891,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
unbound_deployer = UnboundDeployer()
|
unbound_deployer = UnboundDeployer()
|
||||||
|
iroh_deployer = IrohDeployer(enable_iroh_relay=config.enable_iroh_relay)
|
||||||
opendkim_deployer = OpendkimDeployer(mail_domain=mail_domain)
|
opendkim_deployer = OpendkimDeployer(mail_domain=mail_domain)
|
||||||
|
|
||||||
# Dovecot should be started before Postfix
|
# Dovecot should be started before Postfix
|
||||||
@@ -891,6 +904,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
|||||||
|
|
||||||
all_deployers = [
|
all_deployers = [
|
||||||
unbound_deployer,
|
unbound_deployer,
|
||||||
|
iroh_deployer,
|
||||||
opendkim_deployer,
|
opendkim_deployer,
|
||||||
dovecot_deployer,
|
dovecot_deployer,
|
||||||
postfix_deployer,
|
postfix_deployer,
|
||||||
@@ -970,7 +984,9 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
|||||||
unbound_deployer.configure()
|
unbound_deployer.configure()
|
||||||
unbound_deployer.activate()
|
unbound_deployer.activate()
|
||||||
|
|
||||||
deploy_iroh_relay(config)
|
iroh_deployer.install()
|
||||||
|
iroh_deployer.configure()
|
||||||
|
iroh_deployer.activate()
|
||||||
|
|
||||||
# Deploy acmetool to have TLS certificates.
|
# Deploy acmetool to have TLS certificates.
|
||||||
tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"]
|
tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"]
|
||||||
|
|||||||
Reference in New Issue
Block a user