From 40366779f58ff3b747e01b2505a37cea4e3251d3 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 4 Jun 2024 19:48:26 -0700 Subject: [PATCH] use python for variable substitution --- k8s/matrix/bridge-meta.yaml | 19 ++++++++++++++----- k8s/matrix/bridge-telegram.yaml | 19 ++++++++++++++----- k8s/matrix/bridge.yaml | 23 +++++++++++++++-------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/k8s/matrix/bridge-meta.yaml b/k8s/matrix/bridge-meta.yaml index 42eed23..0e97a87 100644 --- a/k8s/matrix/bridge-meta.yaml +++ b/k8s/matrix/bridge-meta.yaml @@ -45,6 +45,20 @@ spec: labels: app: bridge-facebook spec: + initContainers: + - name: template-config + image: docker.io/library/python + command: ["python", "/init/initialize-bridge.py"] + volumeMounts: + - name: init + mountPath: /init + - name: storage + mountPath: /data + - name: config + mountPath: /config + envFrom: + - secretRef: + name: bridge-facebook containers: - image: dock.mau.dev/mautrix/meta:latest name: bridge-facebook @@ -58,11 +72,6 @@ spec: mountPath: /data - name: config mountPath: /config - - name: init - mountPath: /init - envFrom: - - secretRef: - name: bridge-facebook volumes: - name: config configMap: diff --git a/k8s/matrix/bridge-telegram.yaml b/k8s/matrix/bridge-telegram.yaml index 0cf61af..bcf8ca4 100644 --- a/k8s/matrix/bridge-telegram.yaml +++ b/k8s/matrix/bridge-telegram.yaml @@ -63,6 +63,20 @@ spec: labels: app: bridge-telegram spec: + initContainers: + - name: template-config + image: docker.io/library/python + command: ["python", "/init/initialize-bridge.py"] + volumeMounts: + - name: init + mountPath: /init + - name: storage + mountPath: /data + - name: config + mountPath: /config + envFrom: + - secretRef: + name: bridge-telegram containers: - image: dock.mau.dev/mautrix/telegram:latest name: bridge-telegram @@ -76,11 +90,6 @@ spec: mountPath: /data - name: config mountPath: /config - - name: init - mountPath: /init - envFrom: - - secretRef: - name: bridge-telegram volumes: - name: config configMap: diff --git a/k8s/matrix/bridge.yaml b/k8s/matrix/bridge.yaml index a946b22..ca51855 100644 --- a/k8s/matrix/bridge.yaml +++ b/k8s/matrix/bridge.yaml @@ -4,11 +4,18 @@ metadata: name: bridge-init namespace: matrix data: - initialize-bridge.sh: | - #!/bin/bash - set -euo pipefail - cp /config/config.yaml /data/config.yaml - sed -i "s#AS_TOKEN#${AS_TOKEN}#g" /data/config.yaml - sed -i "s#HS_TOKEN#${HS_TOKEN}#g" /data/config.yaml - sed -i "s#TG_API_ID#${TG_API_ID}#g" /data/config.yaml - sed -i "s#TG_API_HASH#${TG_API_HASH}#g" /data/config.yaml + initialize-bridge.py: | + #!/usr/bin/python + import os + + with open("/config/config.yaml") as r: + c = r.read() + + for i in ["AS_TOKEN", "HS_TOKEN", "TG_API_ID", "TG_API_HASH"]: + value = os.getenv(i) + if value is not None: + c = c.replace(i, value) + print("replaced", i) + + with open("/data/config.yaml", 'w') as w: + w.write(c)