From 62b57c19f9baa687789b7db8878106f5eb9ea8a6 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 16 Dec 2024 16:52:47 +0100 Subject: [PATCH] feat(bridge): Add discord --- README.md | 4 +- manifests/bridges/discord/create_db.sh | 14 ++++++ manifests/bridges/discord/job.yaml | 46 ++++++++++++++++++++ manifests/bridges/discord/kustomization.yaml | 18 ++++++++ manifests/bridges/discord/service.yaml | 16 +++++++ manifests/bridges/discord/statefulset.yaml | 36 +++++++++++++++ manifests/bridges/kustomization.yaml | 1 + manifests/deployment.yaml | 6 +++ 8 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 manifests/bridges/discord/create_db.sh create mode 100644 manifests/bridges/discord/job.yaml create mode 100644 manifests/bridges/discord/kustomization.yaml create mode 100644 manifests/bridges/discord/service.yaml create mode 100644 manifests/bridges/discord/statefulset.yaml diff --git a/README.md b/README.md index 2036828..3eefb5b 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ ## Bridges - [x] Signal -- [ ] Telegram +- [x] Telegram - [x] Facebook Messenger - [x] WhatsApp - [x] Instagram -- [ ] Discord +- [x] Discord diff --git a/manifests/bridges/discord/create_db.sh b/manifests/bridges/discord/create_db.sh new file mode 100644 index 0000000..03148b7 --- /dev/null +++ b/manifests/bridges/discord/create_db.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +echo "Checking if $DISCORD_DB database exists..." + +if psql -lqt | cut -d \| -f 1 | grep -qw $DISCORD_DB; then + echo "Database exists, skipping creation" +else + echo "Database does not exist, creating..." + createdb $DISCORD_DB + createuser $DISCORD_USER + psql -c "ALTER USER $DISCORD_USER WITH ENCRYPTED PASSWORD '$DISCORD_PASSWORD';" + psql -c "GRANT ALL PRIVILEGES ON DATABASE $DISCORD_DB TO $DISCORD_USER;" + psql -c "ALTER DATABASE $DISCORD_DB OWNER TO $DISCORD_USER;" +fi diff --git a/manifests/bridges/discord/job.yaml b/manifests/bridges/discord/job.yaml new file mode 100644 index 0000000..90917e0 --- /dev/null +++ b/manifests/bridges/discord/job.yaml @@ -0,0 +1,46 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: discord-db-init + namespace: synapse +spec: + template: + spec: + containers: + - name: discord-db-init + image: postgres:15.10 + command: ["/bin/bash", "/data/create_db.sh"] + env: + - name: PGHOST + value: synapse-db-rw.synapse.svc.cluster.local + - name: PGUSER + valueFrom: + secretKeyRef: + name: synapse-db-superuser + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: synapse-db-superuser + key: password + - name: DISCORD_USER + valueFrom: + secretKeyRef: + name: mautrix-discord-db + key: username + - name: DISCORD_PASSWORD + valueFrom: + secretKeyRef: + name: mautrix-discord-db + key: password + - name: DISCORD_DB + value: discord + volumeMounts: + - name: create-db + mountPath: /data + volumes: + - name: create-db + configMap: + name: discord-db-creation + restartPolicy: Never + backoffLimit: 4 diff --git a/manifests/bridges/discord/kustomization.yaml b/manifests/bridges/discord/kustomization.yaml new file mode 100644 index 0000000..f011819 --- /dev/null +++ b/manifests/bridges/discord/kustomization.yaml @@ -0,0 +1,18 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: synapse + +resources: + - service.yaml + - statefulset.yaml + - job.yaml + +generatorOptions: + labels: + app: discord + +configMapGenerator: + - name: discord-db-creation + behavior: create + files: + - create_db.sh diff --git a/manifests/bridges/discord/service.yaml b/manifests/bridges/discord/service.yaml new file mode 100644 index 0000000..faa7638 --- /dev/null +++ b/manifests/bridges/discord/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: discord + namespace: synapse + labels: + app.kubernetes.io/name: discord +spec: + ports: + - name: http + port: 29334 + protocol: TCP + targetPort: 29334 + selector: + app: discord + publishNotReadyAddresses: true diff --git a/manifests/bridges/discord/statefulset.yaml b/manifests/bridges/discord/statefulset.yaml new file mode 100644 index 0000000..4b89244 --- /dev/null +++ b/manifests/bridges/discord/statefulset.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: discord + namespace: synapse +spec: + selector: + matchLabels: + app: discord + serviceName: discord + replicas: 1 + minReadySeconds: 10 + template: + metadata: + labels: + app: discord + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: discord + image: dock.mau.dev/mautrix/discord:v0.7.1 + command: [ + "/usr/bin/mautrix-discord", + "--config", "/data/config.yaml", + "--no-update", + ] + ports: + - containerPort: 29328 + volumeMounts: + - mountPath: "/data/config.yaml" + name: discord-config-file + subPath: config.yaml + volumes: + - name: discord-config-file + secret: + secretName: discord-secret-config diff --git a/manifests/bridges/kustomization.yaml b/manifests/bridges/kustomization.yaml index c61e223..79ddce1 100644 --- a/manifests/bridges/kustomization.yaml +++ b/manifests/bridges/kustomization.yaml @@ -4,6 +4,7 @@ kind: Kustomization resources: - ./signal - ./telegram + - ./discord - ./messenger - ./instagram - ./whatsapp diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml index c0867f6..722943a 100644 --- a/manifests/deployment.yaml +++ b/manifests/deployment.yaml @@ -39,6 +39,9 @@ spec: - mountPath: "/data/telegram.yaml" name: telegram-secret-registration subPath: telegram.yaml + - mountPath: "/data/discord.yaml" + name: discord-secret-registration + subPath: discord.yaml - mountPath: "/data/messenger.yaml" name: messenger-secret-registration subPath: messenger.yaml @@ -67,6 +70,9 @@ spec: - name: telegram-secret-registration secret: secretName: telegram-secret-registration + - name: discord-secret-registration + secret: + secretName: discord-secret-registration - name: messenger-secret-registration secret: secretName: messenger-secret-registration