diff --git a/manifests/bridges/instagram/create_db.sh b/manifests/bridges/instagram/create_db.sh new file mode 100644 index 0000000..04cff4d --- /dev/null +++ b/manifests/bridges/instagram/create_db.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +echo "Checking if $INSTAGRAM_DB database exists..." + +if psql -lqt | cut -d \| -f 1 | grep -qw $INSTAGRAM_DB; then + echo "Database exists, skipping creation" +else + echo "Database does not exist, creating..." + createdb $INSTAGRAM_DB + createuser $INSTAGRAM_USER + psql -c "ALTER USER $INSTAGRAM_USER WITH ENCRYPTED PASSWORD '$INSTAGRAM_PASSWORD';" + psql -c "GRANT ALL PRIVILEGES ON DATABASE $INSTAGRAM_DB TO $INSTAGRAM_USER;" + psql -c "ALTER DATABASE $INSTAGRAM_DB OWNER TO $INSTAGRAM_USER;" +fi diff --git a/manifests/bridges/instagram/job.yaml b/manifests/bridges/instagram/job.yaml new file mode 100644 index 0000000..d829d54 --- /dev/null +++ b/manifests/bridges/instagram/job.yaml @@ -0,0 +1,46 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: instagram-db-init + namespace: synapse +spec: + template: + spec: + containers: + - name: instagram-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: INSTAGRAM_USER + valueFrom: + secretKeyRef: + name: mautrix-instagram-db + key: username + - name: INSTAGRAM_PASSWORD + valueFrom: + secretKeyRef: + name: mautrix-instagram-db + key: password + - name: INSTAGRAM_DB + value: instagram + volumeMounts: + - name: create-db + mountPath: /data + volumes: + - name: create-db + configMap: + name: instagram-db-creation + restartPolicy: Never + backoffLimit: 4 diff --git a/manifests/bridges/instagram/kustomization.yaml b/manifests/bridges/instagram/kustomization.yaml new file mode 100644 index 0000000..09d685d --- /dev/null +++ b/manifests/bridges/instagram/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: instagram + +configMapGenerator: + - name: instagram-db-creation + behavior: create + files: + - create_db.sh diff --git a/manifests/bridges/instagram/service.yaml b/manifests/bridges/instagram/service.yaml new file mode 100644 index 0000000..543213c --- /dev/null +++ b/manifests/bridges/instagram/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: instagram + namespace: synapse + labels: + app.kubernetes.io/name: instagram +spec: + ports: + - name: http + port: 29319 + protocol: TCP + targetPort: 29319 + selector: + app: instagram + publishNotReadyAddresses: true diff --git a/manifests/bridges/instagram/statefulset.yaml b/manifests/bridges/instagram/statefulset.yaml new file mode 100644 index 0000000..1ea562b --- /dev/null +++ b/manifests/bridges/instagram/statefulset.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: instagram + namespace: synapse +spec: + selector: + matchLabels: + app: instagram + serviceName: instagram + replicas: 1 + minReadySeconds: 10 + template: + metadata: + labels: + app: instagram + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: instagram + image: dock.mau.dev/mautrix/meta:v0.4.2 + command: [ + "/usr/bin/mautrix-meta", + "--config", "/data/config.yaml", + "--no-update", + ] + ports: + - containerPort: 29328 + volumeMounts: + - mountPath: "/data/config.yaml" + name: instagram-config-file + subPath: config.yaml + volumes: + - name: instagram-config-file + secret: + secretName: instagram-secret-config diff --git a/manifests/bridges/kustomization.yaml b/manifests/bridges/kustomization.yaml index c3ecb09..51ea70a 100644 --- a/manifests/bridges/kustomization.yaml +++ b/manifests/bridges/kustomization.yaml @@ -4,3 +4,4 @@ kind: Kustomization resources: - ./signal - ./messenger + - ./instagram