mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
further reduce indirections for staged install
This commit is contained in:
@@ -20,7 +20,7 @@ from pyinfra.facts.systemd import SystemdEnabled
|
||||
from pyinfra.operations import apt, files, pip, server, systemd
|
||||
|
||||
from .acmetool import AcmetoolDeployer
|
||||
from .deployer import Deployer
|
||||
from .deployer import Deployer, Deployment
|
||||
from .www import build_webpages, find_merge_conflict, get_paths
|
||||
|
||||
|
||||
@@ -1136,14 +1136,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
||||
MtailDeployer(mtail_address=config.mtail_address),
|
||||
]
|
||||
|
||||
for deployer in all_deployers:
|
||||
deployer.install()
|
||||
|
||||
for deployer in all_deployers:
|
||||
deployer.configure()
|
||||
|
||||
for deployer in all_deployers:
|
||||
deployer.activate()
|
||||
Deployment().perform_stages(all_deployers)
|
||||
|
||||
files.directory(
|
||||
name="Ensure old logs on disk are deleted",
|
||||
|
||||
@@ -3,21 +3,12 @@ import os
|
||||
from pyinfra.operations import server
|
||||
|
||||
|
||||
class Deployer:
|
||||
|
||||
def __init__(self):
|
||||
default_stages = "install,configure,activate"
|
||||
self.stages = os.getenv("CMDEPLOY_STAGES", default_stages).split(",")
|
||||
self.need_restart = False
|
||||
|
||||
def install(self):
|
||||
if "install" not in self.stages:
|
||||
return
|
||||
|
||||
class Deployment:
|
||||
def install(self, deployer):
|
||||
# optional 'required_users' contains a list of (user, group, secondary-group-list) tuples.
|
||||
# If the group is None, no group is created corresponding to that user.
|
||||
# If the secondary group list is not None, all listed groups are created as well.
|
||||
required_users = getattr(self, "required_users", [])
|
||||
required_users = getattr(deployer, "required_users", [])
|
||||
for user, group, groups in required_users:
|
||||
if group is not None:
|
||||
server.group(
|
||||
@@ -36,7 +27,27 @@ class Deployer:
|
||||
system=True,
|
||||
)
|
||||
|
||||
self.need_restart |= bool(self.install_impl())
|
||||
deployer.need_restart |= bool(deployer.install_impl())
|
||||
|
||||
def configure(self, deployer):
|
||||
deployer.configure_impl()
|
||||
|
||||
def activate(self, deployer):
|
||||
deployer.activate_impl()
|
||||
|
||||
def perform_stages(self, deployers):
|
||||
default_stages = "install,configure,activate"
|
||||
stages = os.getenv("CMDEPLOY_STAGES", default_stages).split(",")
|
||||
|
||||
for stage in stages:
|
||||
for deployer in deployers:
|
||||
getattr(self, stage)(deployer)
|
||||
|
||||
|
||||
class Deployer:
|
||||
|
||||
def __init__(self):
|
||||
self.need_restart = False
|
||||
|
||||
#
|
||||
# If a subclass overrides this with a method that returns a true
|
||||
@@ -46,16 +57,8 @@ class Deployer:
|
||||
def install_impl():
|
||||
pass
|
||||
|
||||
def configure(self):
|
||||
if "configure" in self.stages:
|
||||
self.configure_impl()
|
||||
|
||||
def configure_impl(self):
|
||||
pass
|
||||
|
||||
def activate(self):
|
||||
if "activate" in self.stages:
|
||||
self.activate_impl()
|
||||
|
||||
def activate_impl(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user