mirror of
https://github.com/chatmail/relay.git
synced 2026-09-07 07:53:14 +00:00
feat(mtail): deploy filtermail.mtail and gate mtail rule copy on mtail_address
Deploy filtermail.mtail program along delivered_mail.mtail, fetched from upstream; for this, refactor download_executable to accept mode, so we can use it to upload non-binaries. refactor: make hashes (for uniformity) and mtail version (for use by mtail deployer) module constants. Additionally, gate both mtail programs on mtail_address being set.
This commit is contained in:
@@ -227,7 +227,7 @@ class Deployer:
|
|||||||
res = files.directory(name=name, path=path, present=False, **kwargs)
|
res = files.directory(name=name, path=path, present=False, **kwargs)
|
||||||
return self._update_restart_signals(path, res)
|
return self._update_restart_signals(path, res)
|
||||||
|
|
||||||
def download_executable(self, url, dest, sha256sum, extract=None):
|
def download_executable(self, url, dest, sha256sum, extract=None, mode="755"):
|
||||||
existing = host.get_fact(Sha256File, dest)
|
existing = host.get_fact(Sha256File, dest)
|
||||||
if existing == sha256sum:
|
if existing == sha256sum:
|
||||||
return
|
return
|
||||||
@@ -244,7 +244,7 @@ class Deployer:
|
|||||||
f"({dl_cmd}"
|
f"({dl_cmd}"
|
||||||
f" && echo '{sha256sum} {tmp}' | sha256sum -c"
|
f" && echo '{sha256sum} {tmp}' | sha256sum -c"
|
||||||
f" && mv {tmp} {dest})",
|
f" && mv {tmp} {dest})",
|
||||||
f"chmod 755 {dest}",
|
f"chmod {mode} {dest}",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.need_restart = True
|
self.need_restart = True
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ from pyinfra import facts, host
|
|||||||
|
|
||||||
from cmdeploy.basedeploy import Deployer
|
from cmdeploy.basedeploy import Deployer
|
||||||
|
|
||||||
|
VERSION = "v0.7.4" # also gets used by mtail deployer
|
||||||
|
SHA256SUMS = {
|
||||||
|
"x86_64": "484cb8dff083134aefba9fce4a6b7ef4784a0f0e28e5108ecf8bb9e58a44fd2c",
|
||||||
|
"aarch64": "66aa0ca2ca9add7a12d92883d76f8786384092adfde24a3d3a1d0b1f30d23a9e",
|
||||||
|
}
|
||||||
|
MTAIL_PROGRAM_SHA256 = "948f688bb89ad47e6eb0fc8fa107e201a689f5adc264ff926be487a2a8562b51"
|
||||||
|
|
||||||
|
|
||||||
class FiltermailDeployer(Deployer):
|
class FiltermailDeployer(Deployer):
|
||||||
services = ["filtermail", "filtermail-incoming", "filtermail-transport"]
|
services = ["filtermail", "filtermail-incoming", "filtermail-transport"]
|
||||||
@@ -20,12 +27,8 @@ class FiltermailDeployer(Deployer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
arch = host.get_fact(facts.server.Arch)
|
arch = host.get_fact(facts.server.Arch)
|
||||||
url = f"https://github.com/chatmail/filtermail/releases/download/v0.7.4/filtermail-{arch}"
|
url = f"https://github.com/chatmail/filtermail/releases/download/{VERSION}/filtermail-{arch}"
|
||||||
sha256sum = {
|
self.download_executable(url, self.bin_path, SHA256SUMS[arch])
|
||||||
"x86_64": "484cb8dff083134aefba9fce4a6b7ef4784a0f0e28e5108ecf8bb9e58a44fd2c",
|
|
||||||
"aarch64": "66aa0ca2ca9add7a12d92883d76f8786384092adfde24a3d3a1d0b1f30d23a9e",
|
|
||||||
}[arch]
|
|
||||||
self.download_executable(url, self.bin_path, sha256sum)
|
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
for service in self.services:
|
for service in self.services:
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ from pyinfra import facts, host
|
|||||||
from pyinfra.operations import apt
|
from pyinfra.operations import apt
|
||||||
|
|
||||||
from cmdeploy.basedeploy import Deployer
|
from cmdeploy.basedeploy import Deployer
|
||||||
|
from cmdeploy.filtermail.deployer import (
|
||||||
|
MTAIL_PROGRAM_SHA256 as FILTERMAIL_MTAIL_SHA256,
|
||||||
|
VERSION as FILTERMAIL_VERSION,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MtailDeployer(Deployer):
|
class MtailDeployer(Deployer):
|
||||||
@@ -42,9 +46,16 @@ class MtailDeployer(Deployer):
|
|||||||
bin_path=self.bin_path,
|
bin_path=self.bin_path,
|
||||||
progs_dir=self.progs_dir,
|
progs_dir=self.progs_dir,
|
||||||
)
|
)
|
||||||
self.put_file(
|
if self.mtail_address:
|
||||||
"mtail/delivered_mail.mtail", f"{self.progs_dir}/delivered_mail.mtail"
|
self.put_file(
|
||||||
)
|
"mtail/delivered_mail.mtail", f"{self.progs_dir}/delivered_mail.mtail"
|
||||||
|
)
|
||||||
|
self.download_executable(
|
||||||
|
f"https://raw.githubusercontent.com/chatmail/filtermail/{FILTERMAIL_VERSION}/contrib/filtermail.mtail",
|
||||||
|
f"{self.progs_dir}/filtermail.mtail",
|
||||||
|
FILTERMAIL_MTAIL_SHA256,
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
active = bool(self.mtail_address)
|
active = bool(self.mtail_address)
|
||||||
|
|||||||
Reference in New Issue
Block a user