From 9106fc8c23389d288c8dedc938ac47e0f7799b4e Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Mon, 9 Oct 2023 17:10:27 +0530 Subject: [PATCH] fix: run db migrations in helm chart --- README.md | 2 +- chart/templates/deployment.yaml | 3 +++ chart/templates/postgres.yaml | 4 +++- fixtures/expected/file-git.json | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e61d81b..840711c1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ make build Starting the server will run the migrations and start scraping in background (The `default-schedule` configuration will run scraping every 60 minutes if configuration is not explicitly specified). ```bash -DB_URL=postgres://:@localhost:5432/ ./.bin/config-db serve --run-migrations +DB_URL=postgres://:@localhost:5432/ ./.bin/config-db serve --db-migrations ``` ### Scape config diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index c98af5af..cb656ac6 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -42,6 +42,9 @@ spec: - --disable-postgrest={{ .Values.disablePostgrest }} - --change-retention-days={{ .Values.configChangeRetentionDays }} - --analysis-retention-days={{ .Values.configAnalysisRetentionDays }} + {{- if .Values.db.enabled}} + - --db-migrations + {{- end}} {{- if .Values.upstream.enabled}} envFrom: - secretRef: diff --git a/chart/templates/postgres.yaml b/chart/templates/postgres.yaml index d3e6733a..c274372e 100644 --- a/chart/templates/postgres.yaml +++ b/chart/templates/postgres.yaml @@ -63,13 +63,15 @@ stringData: {{- $secretData := ( get $secretObj "data" | default dict ) }} {{- $user := (( get $secretData "POSTGRES_USER" ) | b64dec ) | default "postgres" }} {{- $password := (( get $secretData "POSTGRES_PASSWORD" ) | b64dec ) | default (randAlphaNum 32) }} + {{- $dbname := (( get $secretData "POSTGRES_DB" ) | b64dec ) | default "config_db" }} {{- $host := print (include "config-db.name" .) "-postgresql." .Release.Namespace ".svc.cluster.local:5432" }} {{- $url := print "postgresql://" $user ":" $password "@" $host }} - {{- $configDbUrl := ( get $secretData .Values.db.secretKeyRef.key ) | default ( print $url "/config-db" ) }} + {{- $configDbUrl := ( get $secretData .Values.db.secretKeyRef.key ) | default ( print $url "/config_db?sslmode=disable" ) }} POSTGRES_USER: {{ $user | quote }} POSTGRES_PASSWORD: {{ $password | quote }} POSTGRES_HOST: {{ $host | quote }} + POSTGRES_DB: {{ $dbname | quote }} {{ .Values.db.secretKeyRef.key }}: {{ $configDbUrl | quote }} {{- end }} diff --git a/fixtures/expected/file-git.json b/fixtures/expected/file-git.json index 15ecd439..99862f31 100644 --- a/fixtures/expected/file-git.json +++ b/fixtures/expected/file-git.json @@ -27,7 +27,7 @@ { "name": "httpbin_2xx_count", "type": "counter", - "value": "result.code == 200 ? 1 : 0", + "value": "code == 200 ? 1 : 0", "labels": [ { "name": "name",