Skip to content

Commit

Permalink
An attempt to define DB secret access for migrations (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaychenko-sergei authored Jul 1, 2024
1 parent 40822ea commit 443f679
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
4 changes: 2 additions & 2 deletions charts/kamu-api-server/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: kamu-api-server
description: API server component of the Kamu Compute Node
type: application
version: 0.26.10
appVersion: "0.26.4"
version: 0.27.0
appVersion: "0.27.1"
home: https://kamu.dev
icon: https://www.kamu.dev/images/kamu_logo_icon_bg_square.png
sources:
Expand Down
20 changes: 20 additions & 0 deletions charts/kamu-api-server/fetch_db_secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

if [ $# -ne 5 ]; then
echo "Usage: $0 <secret-name> <region> <db-host> <db-port> <db-name>"
exit 1
fi

SECRET_NAME="$1"
REGION="$2"
DB_HOST="$3"
DB_PORT="$4"
DB_NAME="$5"

SECRET_STRING=$(aws secretsmanager get-secret-value --secret-id $SECRET_NAME --region $REGION --query SecretString --output text)
USERNAME=$(echo $SECRET_STRING | jq -r .username)
PASSWORD=$(echo $SECRET_STRING | jq -r .password)

export DB_CONNECTION_STRING="postgresql://${USERNAME}:${PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"

exec "$@"
4 changes: 3 additions & 1 deletion charts/kamu-api-server/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ metadata:
labels:
{{- include "kamu-api-server.labels" . | nindent 4 }}
data:
{{- include "kamu-api-server.config.yaml" . | nindent 2 }}
{{- include "kamu-api-server.config.yaml" . | nindent 2 }}
fetch-db-secret.sh: : |-
{{ .Files.Get "fetch_db_secret.sh" | nindent 4}}
21 changes: 14 additions & 7 deletions charts/kamu-api-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ spec:
imagePullPolicy: {{ .Values.imageMigrations.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
args:
- "migrate"
- "run"
- "--source"
- {{ .Values.imageMigrations.migrationsPath | quote }}
- "--database-url"
- {{ .Values.imageMigrations.databaseConnectionString | quote }}
command: [ "/bin/sh", "-c", "/fetch-db-secret.sh {{ .Values.imageMigrations.databaseSecretName }} $AWS_REGION {{ .Values.imageMigrations.databaseHost }} {{ .Values.imageMigrations.databasePort }} {{ .Values.imageMigrations.databaseName }} && sqlx migrate run --source {{ .Values.imageMigrations.migrationsPath }} --database-url $DB_CONNECTION_STRING" ]
env:
- name: RUST_BACKTRACE
value: "1"
- name: AWS_REGION
valueFrom:
secretKeyRef:
name: {{ $secretName }}
key: aws_region
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: fetch-db-secret
mountPath: /fetch-db-secret.sh
subPath: fetch-db-secret.sh
volumes:
- name: fetch-db-secret
configMap:
name: fetch-db-secret-script
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
6 changes: 5 additions & 1 deletion charts/kamu-api-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ imageMigrations:
pullPolicy: IfNotPresent
tag: ""
migrationsPath: ""
databaseConnectionString: ""
databaseSecretName: ""
databaseHost: ""
databasePort: 5432
databaseName: ""


imagePullSecrets: []
nameOverride: ""
Expand Down
4 changes: 2 additions & 2 deletions charts/kamu-oracle-provider/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: kamu-oracle-provider
description: Oracle provider that uses Kamu Node to supply data to blockchain smart contracts
type: application
version: 0.26.3
appVersion: "0.26.2"
version: 0.27.0
appVersion: "0.27.1"
home: https://kamu.dev
icon: https://www.kamu.dev/images/kamu_logo_icon_bg_square.png
sources:
Expand Down

0 comments on commit 443f679

Please sign in to comment.