mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 17:48:58 +00:00
further reduce indirections for staged install
This commit is contained in:
committed by
cliffmccarthy
parent
66daf3003b
commit
b0f247a41f
@@ -20,7 +20,7 @@ from pyinfra.facts.systemd import SystemdEnabled
|
|||||||
from pyinfra.operations import apt, files, pip, server, systemd
|
from pyinfra.operations import apt, files, pip, server, systemd
|
||||||
|
|
||||||
from .acmetool import AcmetoolDeployer
|
from .acmetool import AcmetoolDeployer
|
||||||
from .deployer import Deployer
|
from .deployer import Deployer, Deployment
|
||||||
from .www import build_webpages, find_merge_conflict, get_paths
|
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),
|
MtailDeployer(mtail_address=config.mtail_address),
|
||||||
]
|
]
|
||||||
|
|
||||||
for deployer in all_deployers:
|
Deployment().perform_stages(all_deployers)
|
||||||
deployer.install()
|
|
||||||
|
|
||||||
for deployer in all_deployers:
|
|
||||||
deployer.configure()
|
|
||||||
|
|
||||||
for deployer in all_deployers:
|
|
||||||
deployer.activate()
|
|
||||||
|
|
||||||
files.directory(
|
files.directory(
|
||||||
name="Ensure old logs on disk are deleted",
|
name="Ensure old logs on disk are deleted",
|
||||||
|
|||||||
@@ -3,21 +3,12 @@ import os
|
|||||||
from pyinfra.operations import server
|
from pyinfra.operations import server
|
||||||
|
|
||||||
|
|
||||||
class Deployer:
|
class Deployment:
|
||||||
|
def install(self, 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
|
|
||||||
|
|
||||||
# optional 'required_users' contains a list of (user, group, secondary-group-list) tuples.
|
# 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 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.
|
# 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:
|
for user, group, groups in required_users:
|
||||||
if group is not None:
|
if group is not None:
|
||||||
server.group(
|
server.group(
|
||||||
@@ -36,7 +27,27 @@ class Deployer:
|
|||||||
system=True,
|
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
|
# If a subclass overrides this with a method that returns a true
|
||||||
@@ -46,16 +57,8 @@ class Deployer:
|
|||||||
def install_impl():
|
def install_impl():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def configure(self):
|
|
||||||
if "configure" in self.stages:
|
|
||||||
self.configure_impl()
|
|
||||||
|
|
||||||
def configure_impl(self):
|
def configure_impl(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def activate(self):
|
|
||||||
if "activate" in self.stages:
|
|
||||||
self.activate_impl()
|
|
||||||
|
|
||||||
def activate_impl(self):
|
def activate_impl(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user