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