Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 1 | # Matrix server (synapse). |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 2 | # This needs a secret provisioned, create with: |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 3 | # ns=matrix |
| 4 | # kubectl -n $ns create secret generic synapse --from-literal=postgres_password=$(pwgen 24 1) --from-literal=macaroon_secret_key=$(pwgen 32 1) --from-literal=registration_shared_secret=$(pwgen 32 1) |
| 5 | # kubectl -n $ns create secret generic oauth2-cas-proxy --from-literal=oauth2_secret=... |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 6 | # |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 7 | # After starting, re-create the postgres database (because docker/postgres won't let you set ENCODING): |
| 8 | # postgres=# drop database synapse; |
| 9 | # DROP DATABASE |
| 10 | # postgres=# CREATE DATABASE synapse |
| 11 | # postgres-# ENCODING 'UTF8' |
| 12 | # postgres-# LC_COLLATE='C' |
| 13 | # postgres-# LC_CTYPE='C' |
| 14 | # postgres-# template=template0 |
| 15 | # postgres-# OWNER synapse; |
| 16 | # CREATE DATABASE |
| 17 | # |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 18 | # Sequencing appservices is fun. The appservice needs to run first (for |
| 19 | # instance, via a bootstrap job), and on startup it will spit out a |
| 20 | # registration file. This registration file then needs to be fed to synapse - |
| 21 | # this is done via specialy named secrets (appservice-X-registration, for X key |
| 22 | # in the appservices object). |
| 23 | # |
| 24 | # For appservice-irc instances, you can use this oneliner magic to get the |
| 25 | # registration YAML from logs. |
Piotr Dobrowolski | ee62857 | 2021-01-30 00:14:20 +0100 | [diff] [blame] | 26 | # kubectl -n matrix create secret generic appservice-irc-freenode-registration --from-file=registration.yaml=<(kubectl -n matrix logs job/appservice-irc-freenode-bootstrap | tail -n +4 | sed -r 's/(.*aliases:.*)/ group_id: "+freenode:hackerspace.pl"\n\1/') |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 27 | # |
| 28 | # For appservice-telegram instances, you can use this oneliner magic: |
| 29 | # kubectl -n matrix create secret generic appservice-telegram-prod-registration --from-file=registration.yaml=<(kubectl -n matrix logs job/appservice-telegram-prod-bootstrap | grep -A 100 SNIPSNIP | grep -v SNIPSNIP) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 30 | |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 31 | local kube = import "../../../kube/kube.libsonnet"; |
| 32 | local postgres = import "../../../kube/postgres.libsonnet"; |
Serge Bazanski | cdba291 | 2020-08-24 19:11:10 +0000 | [diff] [blame] | 33 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 34 | { |
| 35 | local app = self, |
| 36 | local cfg = app.cfg, |
| 37 | cfg:: { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 38 | namespace: error "cfg.namespace must be set", |
| 39 | # webDomain is the domain name at which element will run |
| 40 | webDomain: error "cfg.webDomain must be set", |
| 41 | # serverName is the server part of the MXID this homeserver will cover |
| 42 | serverName: error "cfg.serverName must be set", |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 43 | storageClassName: "waw-hdd-redundant-3", |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 44 | |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 45 | images: { |
Norbert Szulc | a5e8c33 | 2021-07-08 15:10:43 +0200 | [diff] [blame] | 46 | synapse: "matrixdotorg/synapse:v1.37.1", |
Serge Bazanski | d67635d | 2020-12-29 23:25:54 +0100 | [diff] [blame] | 47 | riot: "vectorim/riot-web:v1.7.16", |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 48 | casProxy: "registry.k0.hswaw.net/q3k/oauth2-cas-proxy:0.1.4", |
| 49 | appserviceIRC: "matrixdotorg/matrix-appservice-irc:release-0.17.1", |
Serge Bazanski | c3ca295 | 2021-04-10 11:15:30 +0000 | [diff] [blame] | 50 | # :latest tag on 2021/04/10. |
| 51 | appserviceTelegram: "dock.mau.dev/tulir/mautrix-telegram@sha256:c6e25cb57e1b67027069e8dc2627338df35d156315c004a6f2b34b6aeaa79f77", |
Piotr Dobrowolski | 63244ca | 2021-01-30 00:14:02 +0100 | [diff] [blame] | 52 | wellKnown: "registry.k0.hswaw.net/q3k/wellknown:1611960794-adbf560851a46ad0e58b42f0daad7ef19535687c", |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 53 | }, |
| 54 | |
Norbert Szulc | c67abc2 | 2020-11-08 16:46:56 +0100 | [diff] [blame] | 55 | # Central Authentication Scheme, a single-sign-on system. Note: this flow is now called 'SSO' in Matrix, we keep this name for legacy reasons. |
| 56 | # Refer to https://matrix.org/docs/spec/client_server/r0.6.1#sso-client-login |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 57 | cas: { |
| 58 | # whether to enable the CAS proxy (ie. connect to hswaw sso via OAuth) |
| 59 | enable: false, |
Norbert Szulc | 014c9cd | 2020-11-08 16:44:48 +0100 | [diff] [blame] | 60 | # generate client ID and secret in with your OAuth2 provider, refer to https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/ |
| 61 | oauth2: { |
| 62 | clientID: error "cas.oauth2.clientID must be set", |
| 63 | clientSecret: error "cas.oauth2.clientSecret must be set", |
| 64 | scope: error "cas.oauth2.scope must be set", |
| 65 | authorizeURL: error "cas.oauth2.authorizeURL must be set", |
| 66 | tokenURL: error "cas.oauth2.tokenURL must be set", |
| 67 | userinfoURL: error "cas.oauth2.userinfoURL must be set", |
| 68 | }, |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 69 | }, |
Piotr Dobrowolski | 63244ca | 2021-01-30 00:14:02 +0100 | [diff] [blame] | 70 | |
| 71 | wellKnown: false, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 72 | }, |
| 73 | |
| 74 | metadata(component):: { |
Piotr Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 75 | namespace: cfg.namespace, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 76 | labels: { |
| 77 | "app.kubernetes.io/name": "matrix", |
| 78 | "app.kubernetes.io/managed-by": "kubecfg", |
| 79 | "app.kubernetes.io/component": component, |
| 80 | }, |
| 81 | }, |
| 82 | |
Piotr Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 83 | namespace: kube.Namespace(cfg.namespace), |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 84 | |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 85 | postgres3: postgres { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 86 | cfg+: { |
| 87 | namespace: cfg.namespace, |
| 88 | appName: "synapse", |
| 89 | database: "synapse", |
| 90 | username: "synapse", |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 91 | prefix: "waw3-", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 92 | password: { secretKeyRef: { name: "synapse", key: "postgres_password" } }, |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 93 | storageClassName: cfg.storageClassName, |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 94 | storageSize: "100Gi", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 95 | }, |
| 96 | }, |
| 97 | |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 98 | dataVolume: kube.PersistentVolumeClaim("synapse-data-waw3") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 99 | metadata+: app.metadata("synapse-data"), |
| 100 | spec+: { |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 101 | storageClassName: cfg.storageClassName, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 102 | accessModes: [ "ReadWriteOnce" ], |
| 103 | resources: { |
| 104 | requests: { |
| 105 | storage: "50Gi", |
| 106 | }, |
| 107 | }, |
| 108 | }, |
| 109 | }, |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 110 | |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 111 | // homeserver.yaml that will be used to run synapse (in synapseConfigMap). |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 112 | // This is based off of //app/matrix/lib/synapse/homeserver.yaml with some fields overriden per |
| 113 | // deployment. |
| 114 | // Note this is a templated yaml - {{}}/{%%} style. This templatization is consumed by the Docker |
| 115 | // container startup magic. |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 116 | synapseConfig:: (std.native("parseYaml"))(importstr "synapse/homeserver.yaml")[0] { |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 117 | server_name: cfg.serverName, |
| 118 | public_baseurl: "https://%s" % [cfg.webDomain], |
| 119 | signing_key_path: "/data/%s.signing.key" % [cfg.serverName], |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 120 | app_service_config_files: [ |
| 121 | "/appservices/%s/registration.yaml" % [k] |
| 122 | for k in std.objectFields(app.appservices) |
| 123 | ], |
| 124 | } + (if cfg.cas.enable then { |
| 125 | cas_config: { |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 126 | enabled: true, |
| 127 | server_url: "https://%s/_cas" % [cfg.webDomain], |
| 128 | service_url: "https://%s" % [cfg.webDomain], |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 129 | }, |
| 130 | } else {}), |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 131 | |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 132 | synapseConfigMap: kube.ConfigMap("synapse") { |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 133 | metadata+: app.metadata("synapse"), |
| 134 | data: { |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 135 | "homeserver.yaml": std.manifestYamlDoc(app.synapseConfig), |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 136 | "log.config": importstr "synapse/log.config", |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 137 | }, |
| 138 | }, |
| 139 | |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 140 | casDeployment: if cfg.cas.enable then kube.Deployment("oauth2-cas-proxy") { |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 141 | metadata+: app.metadata("oauth2-cas-proxy"), |
| 142 | spec+: { |
| 143 | replicas: 1, |
| 144 | template+: { |
| 145 | spec+: { |
| 146 | containers_: { |
| 147 | proxy: kube.Container("oauth2-cas-proxy") { |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 148 | image: cfg.images.casProxy, |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 149 | ports_: { |
| 150 | http: { containerPort: 5000 }, |
| 151 | }, |
| 152 | env_: { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 153 | BASE_URL: "https://%s" % [cfg.webDomain], |
| 154 | SERVICE_URL: "https://%s" % [cfg.webDomain], |
Norbert Szulc | 014c9cd | 2020-11-08 16:44:48 +0100 | [diff] [blame] | 155 | OAUTH2_CLIENT: cfg.cas.oauth2.clientID, |
| 156 | OAUTH2_SECRET: cfg.cas.oauth2.clientSecret, |
| 157 | OAUTH2_SCOPE: cfg.cas.oauth2.scope, |
| 158 | OAUTH2_AUTHORIZE: cfg.cas.oauth2.authorizeURL, |
| 159 | OAUTH2_TOKEN: cfg.cas.oauth2.tokenURL, |
| 160 | OAUTH2_USERINFO: cfg.cas.oauth2.userinfoURL, |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 161 | }, |
| 162 | }, |
| 163 | }, |
| 164 | }, |
| 165 | }, |
| 166 | }, |
| 167 | }, |
| 168 | |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 169 | casSvc: if cfg.cas.enable then kube.Service("oauth2-cas-proxy") { |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 170 | metadata+: app.metadata("oauth2-cas-proxy"), |
| 171 | target_pod:: app.casDeployment.spec.template, |
| 172 | }, |
| 173 | |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 174 | synapseDeployment: kube.Deployment("synapse") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 175 | metadata+: app.metadata("synapse"), |
| 176 | spec+: { |
| 177 | replicas: 1, |
| 178 | template+: { |
| 179 | spec+: { |
| 180 | volumes_: { |
| 181 | data: kube.PersistentVolumeClaimVolume(app.dataVolume), |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 182 | config: kube.ConfigMapVolume(app.synapseConfigMap), |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 183 | } + { |
| 184 | [k]: { secret: { secretName: "appservice-%s-registration" % [k] } } |
| 185 | for k in std.objectFields(app.appservices) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 186 | }, |
| 187 | containers_: { |
| 188 | web: kube.Container("synapse") { |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 189 | image: cfg.images.synapse, |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 190 | command: ["/bin/sh", "-c", "/start.py migrate_config && exec /start.py"], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 191 | ports_: { |
| 192 | http: { containerPort: 8008 }, |
Serge Bazanski | 1230ac3 | 2020-09-12 22:09:46 +0000 | [diff] [blame] | 193 | metrics: { containerPort: 9092 }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 194 | }, |
| 195 | env_: { |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 196 | SYNAPSE_CONFIG_DIR: "/tmp/config", |
| 197 | SYNAPSE_CONFIG_PATH: "/tmp/config/homeserver.yaml", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 198 | |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 199 | # These values are not used in a template, but |
| 200 | # are required by /start.py migrate_config |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 201 | SYNAPSE_SERVER_NAME: cfg.serverName, |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 202 | SYNAPSE_REPORT_STATS: "no", |
| 203 | |
| 204 | SYNAPSE_MACAROON_SECRET_KEY: { secretKeyRef: { name: "synapse", key: "macaroon_secret_key" } }, |
| 205 | SYNAPSE_REGISTRATION_SHARED_SECRET: { secretKeyRef: { name: "synapse", key: "registration_shared_secret" } }, |
| 206 | POSTGRES_PASSWORD: { secretKeyRef: { name: "synapse", key: "postgres_password" } }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 207 | }, |
| 208 | volumeMounts_: { |
| 209 | data: { mountPath: "/data" }, |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 210 | config: { mountPath: "/conf", }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 211 | } + { |
| 212 | [k]: { mountPath: "/appservices/%s" % [k] } |
| 213 | for k in std.objectFields(app.appservices) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 214 | }, |
| 215 | }, |
| 216 | }, |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 217 | securityContext: { |
| 218 | runAsUser: 991, |
| 219 | runAsGroup: 991, |
| 220 | fsGroup: 991, |
| 221 | }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 222 | }, |
| 223 | }, |
| 224 | }, |
| 225 | }, |
| 226 | |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 227 | synapseSvc: kube.Service("synapse") { |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 228 | metadata+: app.metadata("synapse"), |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 229 | target_pod:: app.synapseDeployment.spec.template, |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 230 | }, |
| 231 | |
Norbert Szulc | 1ef5600 | 2020-11-08 16:13:58 +0100 | [diff] [blame] | 232 | riotConfig:: { |
| 233 | "default_hs_url": "https://%s" % [cfg.webDomain], |
| 234 | "disable_custom_urls": false, |
| 235 | "disable_guests": false, |
| 236 | "disable_login_language_selector": false, |
| 237 | "disable_3pid_login": true, |
| 238 | "brand": "Riot", |
| 239 | "integrations_ui_url": "https://scalar.vector.im/", |
| 240 | "integrations_rest_url": "https://scalar.vector.im/api", |
| 241 | "integrations_jitsi_widget_url": "https://scalar.vector.im/api/widgets/jitsi.html", |
| 242 | |
| 243 | "bug_report_endpoint_url": "https://riot.im/bugreports/submit", |
| 244 | "features": { |
| 245 | "feature_groups": "labs", |
| 246 | "feature_pinning": "labs", |
| 247 | "feature_reactions": "labs" |
| 248 | }, |
| 249 | "default_federate": true, |
| 250 | "default_theme": "light", |
| 251 | "roomDirectory": { |
| 252 | "servers": [ |
| 253 | cfg.serverName, |
| 254 | ] |
| 255 | }, |
| 256 | "welcomeUserId": "@riot-bot:matrix.org", |
| 257 | "enable_presence_by_hs_url": { |
| 258 | "https://matrix.org": false |
| 259 | } |
| 260 | }, |
| 261 | |
| 262 | riotConfigMap: kube.ConfigMap("riot-web-config") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 263 | metadata+: app.metadata("riot-web-config"), |
| 264 | data: { |
Norbert Szulc | 1ef5600 | 2020-11-08 16:13:58 +0100 | [diff] [blame] | 265 | "config.json": std.manifestJsonEx(app.riotConfig, ""), |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 266 | // Standard nginx.conf, made to work when running as unprivileged user. |
| 267 | "nginx.conf": ||| |
| 268 | worker_processes auto; |
| 269 | |
| 270 | error_log /tmp/nginx_error.log warn; |
| 271 | pid /tmp/nginx.pid; |
| 272 | |
| 273 | events { |
| 274 | worker_connections 1024; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | http { |
| 279 | client_body_temp_path /tmp/nginx_client_temp; |
| 280 | proxy_temp_path /tmp/nginx_proxy_temp; |
| 281 | fastcgi_temp_path /tmp/nginx_fastcgi_temp; |
| 282 | uwsgi_temp_path /tmp/nginx_uwsgi_temp; |
| 283 | scgi_temp_path /tmp/nginx_scgi_temp; |
| 284 | |
| 285 | include /etc/nginx/mime.types; |
| 286 | default_type application/octet-stream; |
| 287 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 288 | '$status $body_bytes_sent "$http_referer" ' |
| 289 | '"$http_user_agent" "$http_x_forwarded_for"'; |
| 290 | access_log /tmp/nginx_access.log main; |
| 291 | sendfile on; |
| 292 | keepalive_timeout 65; |
| 293 | |
| 294 | server { |
| 295 | listen 8080; |
| 296 | server_name localhost; |
| 297 | |
| 298 | location / { |
| 299 | root /usr/share/nginx/html; |
| 300 | index index.html index.htm; |
| 301 | } |
| 302 | |
| 303 | error_page 500 502 503 504 /50x.html; |
| 304 | location = /50x.html { |
| 305 | root /usr/share/nginx/html; |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |||, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 310 | }, |
| 311 | }, |
| 312 | |
| 313 | riotDeployment: kube.Deployment("riot-web") { |
| 314 | metadata+: app.metadata("riot-web"), |
| 315 | spec+: { |
| 316 | replicas: 1, |
| 317 | template+: { |
| 318 | spec+: { |
| 319 | volumes_: { |
Norbert Szulc | 1ef5600 | 2020-11-08 16:13:58 +0100 | [diff] [blame] | 320 | config: kube.ConfigMapVolume(app.riotConfigMap), |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 321 | }, |
| 322 | containers_: { |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 323 | web: kube.Container("riot-web") { |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 324 | image: cfg.images.riot, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 325 | ports_: { |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 326 | http: { containerPort: 8080 }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 327 | }, |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 328 | volumeMounts: [ |
| 329 | { |
| 330 | name: "config", |
Piotr Dobrowolski | aca7e28 | 2020-03-21 22:14:38 +0100 | [diff] [blame] | 331 | mountPath: "/app/config.json", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 332 | subPath: "config.json", |
| 333 | }, |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 334 | { |
| 335 | name: "config", |
| 336 | mountPath: "/etc/nginx/nginx.conf", |
| 337 | subPath: "nginx.conf", |
| 338 | }, |
| 339 | ], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 340 | }, |
| 341 | }, |
Serge Bazanski | 21a9616 | 2020-11-03 23:34:36 +0100 | [diff] [blame] | 342 | securityContext: { |
| 343 | // nginx:nginx |
| 344 | runAsUser: 101, |
| 345 | runAsGroup: 101, |
| 346 | }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 347 | }, |
| 348 | }, |
| 349 | }, |
| 350 | }, |
| 351 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 352 | riotSvc: kube.Service("riot-web") { |
| 353 | metadata+: app.metadata("riot-web"), |
| 354 | target_pod:: app.riotDeployment.spec.template, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 355 | }, |
| 356 | |
Piotr Dobrowolski | 63244ca | 2021-01-30 00:14:02 +0100 | [diff] [blame] | 357 | wellKnown: if cfg.wellKnown then { |
| 358 | deployment: kube.Deployment("wellknown") { |
| 359 | metadata+: app.metadata("wellknown"), |
| 360 | spec+: { |
| 361 | replicas: 1, |
| 362 | template+: { |
| 363 | spec+: { |
| 364 | containers_: { |
| 365 | web: kube.Container("wellknown") { |
| 366 | image: cfg.images.wellKnown, |
| 367 | ports_: { |
| 368 | http: { containerPort: 8080 }, |
| 369 | }, |
| 370 | command: ["/app/matrix/wellknown"], |
| 371 | args: ["-hspki_disable", "-domain", cfg.webDomain], |
| 372 | }, |
| 373 | }, |
| 374 | securityContext: { |
| 375 | runAsUser: 101, |
| 376 | runAsGroup: 101, |
| 377 | }, |
| 378 | }, |
| 379 | }, |
| 380 | }, |
| 381 | }, |
| 382 | svc: kube.Service("wellknown") { |
| 383 | metadata+: app.metadata("wellknown"), |
| 384 | target_pod:: app.wellKnown.deployment.spec.template, |
| 385 | }, |
| 386 | } else {}, |
| 387 | |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 388 | // Any appservice you add here will require an appservice-X-registration |
| 389 | // secret containing a registration.yaml file. Adding something to this |
| 390 | // dictionary will cause Synapse to not start until that secret is |
| 391 | // available - so change things carefully! |
| 392 | // If bootstrapping a new appservice, just keep it out of this dictionary |
| 393 | // until it spits you a registration YAML and you feed that to a secret. |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 394 | appservices: {}, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 395 | |
| 396 | ingress: kube.Ingress("matrix") { |
| 397 | metadata+: app.metadata("matrix") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 398 | annotations+: { |
| 399 | "kubernetes.io/tls-acme": "true", |
| 400 | "certmanager.k8s.io/cluster-issuer": "letsencrypt-prod", |
| 401 | "nginx.ingress.kubernetes.io/proxy-body-size": "0", |
| 402 | }, |
| 403 | }, |
| 404 | spec+: { |
| 405 | tls: [ |
| 406 | { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 407 | hosts: [cfg.webDomain], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 408 | secretName: "synapse-tls", |
| 409 | }, |
| 410 | ], |
| 411 | rules: [ |
| 412 | { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 413 | host: cfg.webDomain, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 414 | http: { |
| 415 | paths: [ |
| 416 | { path: "/", backend: app.riotSvc.name_port }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 417 | { path: "/_matrix", backend: app.synapseSvc.name_port }, |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 418 | ] + (if cfg.cas.enable then [ |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 419 | { path: "/_cas", backend: app.casSvc.name_port }, |
Piotr Dobrowolski | 63244ca | 2021-01-30 00:14:02 +0100 | [diff] [blame] | 420 | ] else []) + (if cfg.wellKnown then [ |
| 421 | { path: "/.well-known/matrix", backend: app.wellKnown.svc.name_port }, |
Serge Bazanski | ace32c0 | 2020-11-03 22:04:06 +0100 | [diff] [blame] | 422 | ] else []) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 423 | }, |
| 424 | } |
| 425 | ], |
| 426 | }, |
| 427 | }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 428 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 429 | } |