use python for variable substitution

This commit is contained in:
Finn 2024-06-04 19:48:26 -07:00
parent 2cdbfd296d
commit 40366779f5
3 changed files with 43 additions and 18 deletions

View file

@ -45,6 +45,20 @@ spec:
labels: labels:
app: bridge-facebook app: bridge-facebook
spec: 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: containers:
- image: dock.mau.dev/mautrix/meta:latest - image: dock.mau.dev/mautrix/meta:latest
name: bridge-facebook name: bridge-facebook
@ -58,11 +72,6 @@ spec:
mountPath: /data mountPath: /data
- name: config - name: config
mountPath: /config mountPath: /config
- name: init
mountPath: /init
envFrom:
- secretRef:
name: bridge-facebook
volumes: volumes:
- name: config - name: config
configMap: configMap:

View file

@ -63,6 +63,20 @@ spec:
labels: labels:
app: bridge-telegram app: bridge-telegram
spec: 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: containers:
- image: dock.mau.dev/mautrix/telegram:latest - image: dock.mau.dev/mautrix/telegram:latest
name: bridge-telegram name: bridge-telegram
@ -76,11 +90,6 @@ spec:
mountPath: /data mountPath: /data
- name: config - name: config
mountPath: /config mountPath: /config
- name: init
mountPath: /init
envFrom:
- secretRef:
name: bridge-telegram
volumes: volumes:
- name: config - name: config
configMap: configMap:

View file

@ -4,11 +4,18 @@ metadata:
name: bridge-init name: bridge-init
namespace: matrix namespace: matrix
data: data:
initialize-bridge.sh: | initialize-bridge.py: |
#!/bin/bash #!/usr/bin/python
set -euo pipefail import os
cp /config/config.yaml /data/config.yaml
sed -i "s#AS_TOKEN#${AS_TOKEN}#g" /data/config.yaml with open("/config/config.yaml") as r:
sed -i "s#HS_TOKEN#${HS_TOKEN}#g" /data/config.yaml c = r.read()
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 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)