Skip to content

Commit

Permalink
Merge pull request #183 from flyingcircusio/FC-39624-mailpit
Browse files Browse the repository at this point in the history
[FC-39624] mailpit: init component
  • Loading branch information
Ma27 authored Aug 29, 2024
2 parents fe4a2e0 + 1e15f79 commit f8cedb4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.d/20240724_155934_mb_FC_39624_mailpit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- A new component `batou_ext.mail.Mailpit` has been added.
Mailpit is an alternative for Mailhog which is not maintained anymore.
41 changes: 41 additions & 0 deletions src/batou_ext/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,44 @@ def configure(self):
__name__, "resources/mailhog/mailhog.nix"
),
)


@batou_ext.nix.rebuild
class Mailpit(batou.component.Component):
_required_params_ = {
"public_name": "example.com",
}

public_name = batou.component.Attribute(str)
public_smtp_name = batou.component.Attribute(str, default=None)
ui_port = batou.component.Attribute(int, 8025)
smtp_port = batou.component.Attribute(int, 1025)

max = batou.component.Attribute(int, 500)

http_basic_auth = None

provide_as = None # (optional) str to self.provide()

def configure(self):
if self.provide_as:
self.provide(self.provide_as, self)

if not self.public_smtp_name:
self.public_smtp_name = self.host.fqdn

self.address = batou.utils.Address(
self.public_smtp_name, self.smtp_port
)

if self.http_basic_auth is None:
self.http_auth = self.require_one("http_basic_auth")
else:
self.http_auth = self.http_basic_auth

self += batou.lib.file.File(
"/etc/local/nixos/mailpit.nix",
content=pkg_resources.resource_string(
__name__, "resources/mailpit.nix"
),
)
22 changes: 22 additions & 0 deletions src/batou_ext/resources/mailpit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ lib, pkgs, ... }: {
systemd.services.mailpit = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
StateDirectory = "mailpit";
WorkingDirectory = "%S/mailpit";
ExecStart = "${lib.getExe pkgs.mailpit} -d mailpit.db -s \"[::]:{{component.smtp_port}}\" -l \"[::1]:{{component.ui_port}}\" --max {{component.max}}";
Restart = "on-failure";
};
};

flyingcircus.services.nginx.virtualHosts."{{ component.public_name }}" = {
forceSSL = true;
enableACME = true;
basicAuthFile = "{{component.http_auth.path}}";
locations."/" = {
proxyPass = "http://[::1]:8025";
proxyWebsockets = true;
};
};
}

0 comments on commit f8cedb4

Please sign in to comment.