| 1 | amends "../../config/Service.pkl" |
| 2 | |
| 3 | import "../../config/site.pkl" as site |
| 4 | import "../ddns-updater/service.pkl" as dns |
| 5 | import "pkl:json" |
| 6 | |
| 7 | local network = new json.Parser {}.parse(read("network.json").text) |
| 8 | local host = read?("prop:hostname") ?? "xmpp.\(site.domain)" |
| 9 | local accountDomain = if (site.preview) host else site.domain |
| 10 | |
| 11 | name = "XMPP" |
| 12 | launcher = false |
| 13 | stageIsolation = "fresh" |
| 14 | healthyDeadline = "10m" |
| 15 | setup = "setup.py" |
| 16 | |
| 17 | requirements = if (site.domain.endsWith(".test")) new Listing {} else new Listing { |
| 18 | new dns.DnsCredentials { |
| 19 | srv = if (site.preview) new Listing {} else new Listing { |
| 20 | new dns.SrvRecord { name = "_xmpp-client._tcp.\(site.domain)"; target = host; port = network.c2s } |
| 21 | new dns.SrvRecord { name = "_xmpps-client._tcp.\(site.domain)"; target = host; port = network.c2s_tls } |
| 22 | new dns.SrvRecord { name = "_xmpp-server._tcp.\(site.domain)"; target = host; port = network.s2s } |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | secrets { ["password"] {}; ["turn"] {} } |
| 27 | |
| 28 | containers { |
| 29 | ["certificates"] { |
| 30 | build = "." |
| 31 | entrypoint = "/usr/bin/python3" |
| 32 | args { "/snowglobe/run.py"; "certificates" } |
| 33 | hostNetwork = true |
| 34 | lifecycle = "prestartSidecar" |
| 35 | cpu = 100 |
| 36 | memory = 256 |
| 37 | volumes { ["/tls"] {}; ["/snowglobe"] { config = "runtime" } } |
| 38 | env { |
| 39 | ["XMPP_DOMAIN"] = accountDomain |
| 40 | ["XMPP_HOST"] = host |
| 41 | ["OWNER_EMAIL"] = site.ownerEmail |
| 42 | ["DNS_TOKEN"] = if (site.domain.endsWith(".test")) "" else "${secret.dns.api_token}" |
| 43 | } |
| 44 | } |
| 45 | ["prosody"] { |
| 46 | build = "." |
| 47 | entrypoint = "/usr/bin/python3" |
| 48 | args { "/snowglobe/run.py"; "prosody" } |
| 49 | hostNetwork = true |
| 50 | http { containerPort = 5280; hostname = host; loopback = true; checkPath = "/health"; forwardRealIp = true } |
| 51 | tcp { |
| 52 | new { name = "c2s"; containerPort = network.c2s; hostPort = containerPort; loopback = false } |
| 53 | new { name = "c2stls"; containerPort = network.c2s_tls; hostPort = containerPort; loopback = false } |
| 54 | new { name = "s2s"; containerPort = network.s2s; hostPort = containerPort; loopback = false } |
| 55 | } |
| 56 | volumes { |
| 57 | ["/var/lib/prosody"] {} |
| 58 | ["/tls"] { readOnly = true } |
| 59 | ["/snowglobe"] { config = "runtime" } |
| 60 | ["/etc/prosody/prosody.cfg.lua"] { config = "prosody.cfg.lua" } |
| 61 | } |
| 62 | env { |
| 63 | ["XMPP_DOMAIN"] = accountDomain |
| 64 | ["XMPP_HOST"] = host |
| 65 | ["XMPP_PASSWORD"] = "${secret.own.password}" |
| 66 | ["TURN_SECRET"] = "${secret.own.turn}" |
| 67 | } |
| 68 | envTemplate = """ |
| 69 | HTTP_PORT={{ env "NOMAD_PORT_prosody_http" }} |
| 70 | """ |
| 71 | } |
| 72 | ["turn"] { |
| 73 | build = "." |
| 74 | entrypoint = "/usr/bin/python3" |
| 75 | args { "/snowglobe/run.py"; "turn" } |
| 76 | hostNetwork = true |
| 77 | memory = 256 |
| 78 | tcp { |
| 79 | new { name = "turn"; containerPort = network.turn; hostPort = containerPort; loopback = false } |
| 80 | new { name = "turntls"; containerPort = network.turn_tls; hostPort = containerPort; loopback = false } |
| 81 | for (port in IntSeq(network.relay_first, network.relay_last)) { |
| 82 | new { name = "relay-\(port)"; containerPort = port; hostPort = port; loopback = false } |
| 83 | } |
| 84 | } |
| 85 | volumes { ["/tls"] { readOnly = true }; ["/snowglobe"] { config = "runtime" } } |
| 86 | env { ["XMPP_HOST"] = host; ["TURN_SECRET"] = "${secret.own.turn}" } |
| 87 | } |
| 88 | } |