From 2e921f2685fce414ea8fd67f697f8ae455e80ff4 Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Wed, 13 Oct 2021 14:55:53 -0400 Subject: [PATCH] Add db command. Update Tiltfile / app to store DB host in secrets --- Tiltfile | 1 + k8s/app.yaml | 7 +++++-- mev | 22 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Tiltfile b/Tiltfile index 7233762..0838b62 100644 --- a/Tiltfile +++ b/Tiltfile @@ -16,6 +16,7 @@ k8s_yaml(configmap_from_dict("mev-inspect-rpc", inputs = { k8s_yaml(secret_from_dict("mev-inspect-db-credentials", inputs = { "username" : "postgres", "password": "password", + "host": "postgresql", })) docker_build_with_restart("mev-inspect-py", ".", diff --git a/k8s/app.yaml b/k8s/app.yaml index 1c51f81..4195d32 100644 --- a/k8s/app.yaml +++ b/k8s/app.yaml @@ -19,6 +19,11 @@ spec: image: mev-inspect-py command: [ "/app/entrypoint.sh" ] env: + - name: POSTGRES_HOST + valueFrom: + secretKeyRef: + name: mev-inspect-db-credentials + key: host - name: POSTGRES_USER valueFrom: secretKeyRef: @@ -29,8 +34,6 @@ spec: secretKeyRef: name: mev-inspect-db-credentials key: password - - name: POSTGRES_HOST - value: postgresql - name: RPC_URL valueFrom: configMapKeyRef: diff --git a/mev b/mev index 499c139..6571097 100755 --- a/mev +++ b/mev @@ -2,9 +2,27 @@ set -e +DB_NAME=mev_inspect + +function get_kube_db_secret(){ + kubectl get secrets mev-inspect-db-credentials -o jsonpath="{.data.$1}" | base64 --decode +} + +function db(){ + host=$(get_kube_db_secret "host") + username=$(get_kube_db_secret "username") + password=$(get_kube_db_secret "password") + + kubectl run -i --rm --tty postgres-client \ + --env="PGPASSWORD=$password" \ + --image=jbergknoff/postgresql-client \ + -- $DB_NAME --host=$host --user=$username +} + case "$1" in - backfill) - echo "Running backfill from block $2 to block $3" + db) + echo "Connecting to $DB_NAME" + db ;; inspect) block_number=$2