1amends "../../config/Service.pkl"
2
3import "../../config/site.pkl" as site
4import "../postgres/service.pkl" as postgres
5import "pkl:json"
6
7local host = module.container.http.hostname
8local voice = new json.Parser {}.parse(read("voice-network.json").text)
9local voiceHost = "\(voice.subdomain).\(site.domain)"
10
11name = "Spacebar"
12tagline = "Discord-compatible chat"
13launcher = false
14stageIsolation = "fresh"
15healthyDeadline = "10m"
16prepare = if (site.preview) null else "prepare.py"
17
18requirements {
19 new postgres.Database { name = "spacebar" }
20}
21
22secrets {
23 ["jwt_secret"] {}
24 ["request_signature"] {}
25 ["cdn_signature"] {}
26}
27
28container {
29 build = "build"
30 restrictedEgress = true
31 cpu = 1000
32 memory = 3072
33
34 http {
35 containerPort = 3001
36 subdomain = "phoenix-selfhosted"
37 plainHostnames {
38 // A preview would request a certificate for a name with no DNS.
39 when (!site.preview) { "clozy.moe" }
40 }
41 checkPath = "/api/ping"
42 forwardRealIp = true
43 }
44
45 tcp {
46 when (!site.preview) {
47 new { name = "voice"; containerPort = voice.signaling; hostPort = containerPort }
48 new { name = "voice-media"; containerPort = voice.media; hostPort = containerPort; loopback = false }
49 new { name = "voice-native-media"; containerPort = voice.nativeMedia; hostPort = containerPort; loopback = false }
50 }
51 }
52
53 volumes {
54 ["/data"] {}
55 ["/work"] {}
56 // Shale keeps each repository under its UUID, which renaming and visibility changes leave alone.
57 ["/source.git"] { src = "\(site.root)/prod/shale/repositories_owned/006AH3H3QKH2KN318QXRNFBH4B"; readOnly = true }
58 // Production writes the server log into the sandbox workspace; previews keep their own.
59 ["/logs"] { when (!site.preview) { src = "\(site.root)/work/snowcord-server/logs" } }
60 }
61
62 env {
63 ["BRANCH"] = "main"
64 ["HOME"] = "/work"
65 ["CONFIG_PATH"] = "/spacebar/config.json"
66 ["CONFIG_READONLY"] = "true"
67 ["STORAGE_LOCATION"] = "/data/files"
68 ["PORT"] = "3001"
69 when (!site.preview) {
70 ["VOICE_PUBLIC_HOST"] = voiceHost
71 ["VOICE_SIGNALING_PORT"] = voice.signaling.toString()
72 ["VOICE_MEDIA_PORT"] = voice.media.toString()
73 ["VOICE_NATIVE_MEDIA_PORT"] = voice.nativeMedia.toString()
74 }
75 }
76
77 envTemplate = """
78 {{ with $db := nomadVar "nomad/jobs/\(module.id)/inputs/database" }}{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "postgres" }}DATABASE=postgres://{{ index $db "username" }}:{{ index $db "password" }}@\(module.nomadHostPort)/{{ index $db "name" }}{{ end }}{{ end }}
79 """
80
81 secretFiles {
82 ["/spacebar/config.json"] = """
83 {
84 "general": {
85 "instanceName": "Snow Globe",
86 "serverName": "\(host)"
87 },
88 "api": {
89 "endpointPublic": "https://\(host)"
90 },
91 "cdn": {
92 "endpointPublic": "https://\(host)",
93 "endpointPrivate": "http://127.0.0.1:3001"
94 },
95 "gateway": {
96 "endpointPublic": "wss://\(host)"
97 },
98 \(if (site.preview) "" else """
99 "regions": {
100 "default": "spacebar",
101 "available": [{
102 "id": "spacebar",
103 "name": "Spacebar",
104 "endpoint": "\(voiceHost):443",
105 "vip": false,
106 "custom": false,
107 "deprecated": false
108 }]
109 },
110 """)
111 "register": {
112 "requireCaptcha": false
113 },
114 "security": {
115 "forwardedFor": "X-Real-Ip",
116 "trustedProxies": "loopback,linklocal,uniquelocal",
117 "jwtSecret": "{{ with $own := nomadVar "nomad/jobs/\(module.id)" }}{{ index $own "jwt_secret" }}{{ end }}",
118 "requestSignature": "{{ with $own := nomadVar "nomad/jobs/\(module.id)" }}{{ index $own "request_signature" }}{{ end }}",
119 "cdnSignatureKey": "{{ with $own := nomadVar "nomad/jobs/\(module.id)" }}{{ index $own "cdn_signature" }}{{ end }}"
120 }
121 }
122 """
123 }
124}