From 1a2849744883ade3740b3765f980e3b581fc4545 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 16 Dec 2024 11:53:36 +0100 Subject: [PATCH] feat(bridges): Add whatsapp --- manifests/bridges/kustomization.yaml | 1 + manifests/bridges/whatsapp/create_db.sh | 14 ++++++ manifests/bridges/whatsapp/job.yaml | 46 +++++++++++++++++++ manifests/bridges/whatsapp/kustomization.yaml | 18 ++++++++ manifests/bridges/whatsapp/service.yaml | 16 +++++++ manifests/bridges/whatsapp/statefulset.yaml | 36 +++++++++++++++ 6 files changed, 131 insertions(+) create mode 100644 manifests/bridges/whatsapp/create_db.sh create mode 100644 manifests/bridges/whatsapp/job.yaml create mode 100644 manifests/bridges/whatsapp/kustomization.yaml create mode 100644 manifests/bridges/whatsapp/service.yaml create mode 100644 manifests/bridges/whatsapp/statefulset.yaml diff --git a/manifests/bridges/kustomization.yaml b/manifests/bridges/kustomization.yaml index 51ea70a..4508c1b 100644 --- a/manifests/bridges/kustomization.yaml +++ b/manifests/bridges/kustomization.yaml @@ -5,3 +5,4 @@ resources: - ./signal - ./messenger - ./instagram + - ./whatsapp diff --git a/manifests/bridges/whatsapp/create_db.sh b/manifests/bridges/whatsapp/create_db.sh new file mode 100644 index 0000000..6bcb6d7 --- /dev/null +++ b/manifests/bridges/whatsapp/create_db.sh @@ -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 diff --git a/manifests/bridges/whatsapp/job.yaml b/manifests/bridges/whatsapp/job.yaml new file mode 100644 index 0000000..0d87f71 --- /dev/null +++ b/manifests/bridges/whatsapp/job.yaml @@ -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 diff --git a/manifests/bridges/whatsapp/kustomization.yaml b/manifests/bridges/whatsapp/kustomization.yaml new file mode 100644 index 0000000..6c893a1 --- /dev/null +++ b/manifests/bridges/whatsapp/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: whatsapp + +configMapGenerator: + - name: whatsapp-db-creation + behavior: create + files: + - create_db.sh diff --git a/manifests/bridges/whatsapp/service.yaml b/manifests/bridges/whatsapp/service.yaml new file mode 100644 index 0000000..209490e --- /dev/null +++ b/manifests/bridges/whatsapp/service.yaml @@ -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 diff --git a/manifests/bridges/whatsapp/statefulset.yaml b/manifests/bridges/whatsapp/statefulset.yaml new file mode 100644 index 0000000..19df087 --- /dev/null +++ b/manifests/bridges/whatsapp/statefulset.yaml @@ -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