feat(bridge): Add discord

This commit is contained in:
Tanguy Herbron 2024-12-16 16:52:47 +01:00
parent 03a167a13f
commit 62b57c19f9
8 changed files with 139 additions and 2 deletions

View File

@ -3,8 +3,8 @@
## Bridges
- [x] Signal
- [ ] Telegram
- [x] Telegram
- [x] Facebook Messenger
- [x] WhatsApp
- [x] Instagram
- [ ] Discord
- [x] Discord

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -4,6 +4,7 @@ kind: Kustomization
resources:
- ./signal
- ./telegram
- ./discord
- ./messenger
- ./instagram
- ./whatsapp

View File

@ -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