feat(bridges): Add whatsapp

This commit is contained in:
Tanguy Herbron 2024-12-16 11:53:36 +01:00
parent b7beefd92e
commit 1a28497448
6 changed files with 131 additions and 0 deletions

View File

@ -5,3 +5,4 @@ resources:
- ./signal - ./signal
- ./messenger - ./messenger
- ./instagram - ./instagram
- ./whatsapp

View File

@ -0,0 +1,14 @@
#!/bin/bash
echo "Checking if $WHATSAPP_DB database exists..."
if psql -lqt | cut -d \| -f 1 | grep -qw $WHATSAPP_DB; then
echo "Database exists, skipping creation"
else
echo "Database does not exist, creating..."
createdb $WHATSAPP_DB
createuser $WHATSAPP_USER
psql -c "ALTER USER $WHATSAPP_USER WITH ENCRYPTED PASSWORD '$WHATSAPP_PASSWORD';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $WHATSAPP_DB TO $WHATSAPP_USER;"
psql -c "ALTER DATABASE $WHATSAPP_DB OWNER TO $WHATSAPP_USER;"
fi

View File

@ -0,0 +1,46 @@
apiVersion: batch/v1
kind: Job
metadata:
name: whatsapp-db-init
namespace: synapse
spec:
template:
spec:
containers:
- name: whatsapp-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: WHATSAPP_USER
valueFrom:
secretKeyRef:
name: mautrix-whatsapp-db
key: username
- name: WHATSAPP_PASSWORD
valueFrom:
secretKeyRef:
name: mautrix-whatsapp-db
key: password
- name: WHATSAPP_DB
value: whatsapp
volumeMounts:
- name: create-db
mountPath: /data
volumes:
- name: create-db
configMap:
name: whatsapp-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: whatsapp
configMapGenerator:
- name: whatsapp-db-creation
behavior: create
files:
- create_db.sh

View File

@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: whatsapp
namespace: synapse
labels:
app.kubernetes.io/name: whatsapp
spec:
ports:
- name: http
port: 29318
protocol: TCP
targetPort: 29318
selector:
app: whatsapp
publishNotReadyAddresses: true

View File

@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: whatsapp
namespace: synapse
spec:
selector:
matchLabels:
app: whatsapp
serviceName: whatsapp
replicas: 1
minReadySeconds: 10
template:
metadata:
labels:
app: whatsapp
spec:
terminationGracePeriodSeconds: 10
containers:
- name: whatsapp
image: dock.mau.dev/mautrix/whatsapp:v0.11.1
command: [
"/usr/bin/mautrix-whatsapp",
"--config", "/data/config.yaml",
"--no-update",
]
ports:
- containerPort: 29328
volumeMounts:
- mountPath: "/data/config.yaml"
name: whatsapp-config-file
subPath: config.yaml
volumes:
- name: whatsapp-config-file
secret:
secretName: whatsapp-secret-config