Skip to content

Commit 1c19757

Browse files
committed
Enhance Helm chart configuration for backend and frontend services
- Update Chart.lock to reflect new versions for backend and frontend dependencies. - Introduce new helper functions for generating database connection strings and API URLs in backend and frontend templates. - Modify configmap.yaml files to utilize the new helper functions for DATABASE_URL and NEXT_PUBLIC_API_URL, improving configuration flexibility.
1 parent 62725fb commit 1c19757

File tree

7 files changed

+216
-14
lines changed

7 files changed

+216
-14
lines changed

helm/Chart.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ dependencies:
44
version: 16.7.12
55
- name: backend
66
repository: ""
7-
version: 0.0.3
7+
version: 0.0.6
88
- name: frontend
99
repository: ""
10-
version: 0.0.3
11-
digest: sha256:fd893af7b0f210f42d2243c6f296f9b0d34fdff5b6511d28ed89733e4c97f4e7
12-
generated: "2025-06-30T12:50:59.839800134+02:00"
10+
version: 0.0.6
11+
digest: sha256:f663f9c9e69d8f67366f298ff66437a5819a5102f81f5bdc1b9122913b2a37a0
12+
generated: "2025-07-01T09:04:55.541133494+02:00"

helm/charts/backend/templates/_helpers.tpl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,92 @@ Selector labels
4848
{{- define "backend.selectorLabels" -}}
4949
app.kubernetes.io/name: {{ include "backend.name" . }}
5050
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Backend-specific database URL generation.
55+
This provides a backend-specific override if needed.
56+
*/}}
57+
{{- define "backend.databaseUrl" -}}
58+
{{- include "amazee-ai.backendDatabaseUrl" . }}
59+
{{- end }}
60+
61+
{{/*
62+
Generate database host for backend service.
63+
*/}}
64+
{{- define "backend.databaseHost" -}}
65+
{{- $postgresql := .Values.postgresql | default dict -}}
66+
{{- $external := $postgresql.external | default dict -}}
67+
{{- if $external.enabled }}
68+
{{- /* Extract host from external URL - simplified approach */ -}}
69+
{{- $url := $external.url }}
70+
{{- $host := regexReplaceAll "postgresql://[^:]+:[^@]+@([^:]+):[^/]+/[^?]*" $url "${1}" }}
71+
{{- $host }}
72+
{{- else }}
73+
{{- include "amazee-ai.postgresqlServiceName" . }}
74+
{{- end }}
75+
{{- end }}
76+
77+
{{/*
78+
Generate database port for backend service.
79+
*/}}
80+
{{- define "backend.databasePort" -}}
81+
{{- $postgresql := .Values.postgresql | default dict -}}
82+
{{- $external := $postgresql.external | default dict -}}
83+
{{- if $external.enabled }}
84+
{{- /* Extract port from external URL - simplified approach */ -}}
85+
{{- $url := $external.url }}
86+
{{- $port := regexReplaceAll "postgresql://[^:]+:[^@]+@[^:]+:([^/]+)/[^?]*" $url "${1}" }}
87+
{{- $port }}
88+
{{- else }}
89+
{{- include "amazee-ai.postgresqlPort" . }}
90+
{{- end }}
91+
{{- end }}
92+
93+
{{/*
94+
Generate database name for backend service.
95+
*/}}
96+
{{- define "backend.databaseName" -}}
97+
{{- $postgresql := .Values.postgresql | default dict -}}
98+
{{- $external := $postgresql.external | default dict -}}
99+
{{- if $external.enabled }}
100+
{{- /* Extract database name from external URL - simplified approach */ -}}
101+
{{- $url := $external.url }}
102+
{{- $db := regexReplaceAll "postgresql://[^:]+:[^@]+@[^:]+:[^/]+/([^?]*)" $url "${1}" }}
103+
{{- $db }}
104+
{{- else }}
105+
{{- include "amazee-ai.postgresqlDatabase" . }}
106+
{{- end }}
107+
{{- end }}
108+
109+
{{/*
110+
Generate database username for backend service.
111+
*/}}
112+
{{- define "backend.databaseUsername" -}}
113+
{{- $postgresql := .Values.postgresql | default dict -}}
114+
{{- $external := $postgresql.external | default dict -}}
115+
{{- if $external.enabled }}
116+
{{- /* Extract username from external URL - simplified approach */ -}}
117+
{{- $url := $external.url }}
118+
{{- $user := regexReplaceAll "postgresql://([^:]+):[^@]+@[^:]+:[^/]+/[^?]*" $url "${1}" }}
119+
{{- $user }}
120+
{{- else }}
121+
{{- include "amazee-ai.postgresqlUsername" . }}
122+
{{- end }}
123+
{{- end }}
124+
125+
{{/*
126+
Generate database password for backend service.
127+
*/}}
128+
{{- define "backend.databasePassword" -}}
129+
{{- $postgresql := .Values.postgresql | default dict -}}
130+
{{- $external := $postgresql.external | default dict -}}
131+
{{- if $external.enabled }}
132+
{{- /* Extract password from external URL - simplified approach */ -}}
133+
{{- $url := $external.url }}
134+
{{- $pass := regexReplaceAll "postgresql://[^:]+:([^@]+)@[^:]+:[^/]+/[^?]*" $url "${1}" }}
135+
{{- $pass }}
136+
{{- else }}
137+
{{- include "amazee-ai.postgresqlPassword" . }}
138+
{{- end }}
51139
{{- end }}

helm/charts/backend/templates/configmap.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ metadata:
66
labels:
77
{{- include "backend.labels" . | nindent 4 }}
88
data:
9-
{{- if .Values.database.url }}
10-
DATABASE_URL: {{ .Values.database.url | quote }}
11-
{{- else }}
12-
DATABASE_URL: "postgresql://{{ .Values.database.user }}:{{ .Values.database.password }}@{{ .Values.database.host }}:5432/{{ .Values.database.name }}"
13-
{{- end }}
9+
DATABASE_URL: {{ include "amazee-ai.backendDatabaseUrl" . }}
1410
ENABLE_METRICS: "{{ .Values.enableMetrics }}"
1511
DYNAMODB_REGION: "{{ .Values.dynamodbRegion }}"
1612
SES_REGION: "{{ .Values.sesRegion }}"

helm/charts/frontend/templates/_helpers.tpl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,35 @@ Selector labels
4848
{{- define "frontend.selectorLabels" -}}
4949
app.kubernetes.io/name: {{ include "frontend.name" . }}
5050
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Frontend-specific API URL generation.
55+
This provides a frontend-specific override if needed.
56+
*/}}
57+
{{- define "frontend.apiUrl" -}}
58+
{{- include "amazee-ai.apiUrl" . }}
59+
{{- end }}
60+
61+
{{/*
62+
Generate backend service name for frontend.
63+
*/}}
64+
{{- define "frontend.backendServiceName" -}}
65+
{{- printf "%s-backend" .Release.Name }}
66+
{{- end }}
67+
68+
{{/*
69+
Generate backend service port for frontend.
70+
*/}}
71+
{{- define "frontend.backendServicePort" -}}
72+
{{- "8800" }}
73+
{{- end }}
74+
75+
{{/*
76+
Generate backend service URL for frontend.
77+
*/}}
78+
{{- define "frontend.backendServiceUrl" -}}
79+
{{- $service := include "frontend.backendServiceName" . }}
80+
{{- $port := include "frontend.backendServicePort" . }}
81+
{{- printf "http://%s:%s" $service $port | quote }}
5182
{{- end }}

helm/charts/frontend/templates/configmap.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ metadata:
66
labels:
77
{{- include "frontend.labels" . | nindent 4 }}
88
data:
9-
{{- if .Values.apiUrl }}
10-
NEXT_PUBLIC_API_URL: "{{ .Values.apiUrl }}"
11-
{{- else }}
12-
NEXT_PUBLIC_API_URL: "http://{{ .Release.Name }}-backend:8800"
13-
{{- end }}
9+
NEXT_PUBLIC_API_URL: {{ include "amazee-ai.apiUrl" . }}
1410
STRIPE_PUBLISHABLE_KEY: "{{ .Values.stripePublishableKey }}"
1511
PASSWORDLESS_SIGN_IN: "{{ .Values.passwordlessSignIn }}"

helm/charts/postgresql-16.7.12.tgz

83.1 KB
Binary file not shown.

helm/templates/_helpers.tpl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,95 @@ Selector labels
4848
{{- define "amazee-ai.selectorLabels" -}}
4949
app.kubernetes.io/name: {{ include "amazee-ai.name" . }}
5050
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Generate database connection string for PostgreSQL.
55+
If external database is enabled, use the provided URL.
56+
Otherwise, generate a connection string using the internal PostgreSQL service.
57+
*/}}
58+
{{- define "amazee-ai.databaseUrl" -}}
59+
{{- $postgresql := .Values.postgresql | default dict -}}
60+
{{- $external := $postgresql.external | default dict -}}
61+
{{- if $external.enabled }}
62+
{{- $external.url | quote }}
63+
{{- else }}
64+
{{- $host := printf "%s-postgresql" .Release.Name }}
65+
{{- $user := "postgres" }}
66+
{{- $auth := $postgresql.auth | default dict -}}
67+
{{- $password := $auth.postgresPassword | default "postgres" }}
68+
{{- $database := $auth.database | default "postgres_service" }}
69+
{{- $port := "5432" }}
70+
{{- printf "postgresql://%s:%s@%s:%s/%s" $user $password $host $port $database | quote }}
71+
{{- end }}
72+
{{- end }}
73+
74+
{{/*
75+
Generate database connection string for backend service.
76+
This function checks if a specific database URL is provided in backend.database.url,
77+
and if not, falls back to the main database URL generation.
78+
*/}}
79+
{{- define "amazee-ai.backendDatabaseUrl" -}}
80+
{{- $backend := .Values.backend | default dict -}}
81+
{{- $database := $backend.database | default dict -}}
82+
{{- if $database.url }}
83+
{{- $database.url | quote }}
84+
{{- else }}
85+
{{- include "amazee-ai.databaseUrl" . }}
86+
{{- end }}
87+
{{- end }}
88+
89+
{{/*
90+
Generate API URL for frontend service.
91+
If a specific API URL is provided, use it.
92+
Otherwise, generate a URL using the backend service name.
93+
*/}}
94+
{{- define "amazee-ai.apiUrl" -}}
95+
{{- $frontend := .Values.frontend | default dict -}}
96+
{{- if $frontend.apiUrl }}
97+
{{- $frontend.apiUrl | quote }}
98+
{{- else }}
99+
{{- $backendService := printf "%s-backend" .Release.Name }}
100+
{{- $port := "8800" }}
101+
{{- printf "http://%s:%s" $backendService $port | quote }}
102+
{{- end }}
103+
{{- end }}
104+
105+
{{/*
106+
Generate PostgreSQL service name for internal database.
107+
*/}}
108+
{{- define "amazee-ai.postgresqlServiceName" -}}
109+
{{- printf "%s-postgresql" .Release.Name }}
110+
{{- end }}
111+
112+
{{/*
113+
Generate PostgreSQL service port.
114+
*/}}
115+
{{- define "amazee-ai.postgresqlPort" -}}
116+
{{- "5432" }}
117+
{{- end }}
118+
119+
{{/*
120+
Generate PostgreSQL database name.
121+
*/}}
122+
{{- define "amazee-ai.postgresqlDatabase" -}}
123+
{{- $postgresql := .Values.postgresql | default dict -}}
124+
{{- $auth := $postgresql.auth | default dict -}}
125+
{{- $auth.database | default "postgres_service" }}
126+
{{- end }}
127+
128+
{{/*
129+
Generate PostgreSQL username.
130+
*/}}
131+
{{- define "amazee-ai.postgresqlUsername" -}}
132+
{{- "postgres" }}
133+
{{- end }}
134+
135+
{{/*
136+
Generate PostgreSQL password.
137+
*/}}
138+
{{- define "amazee-ai.postgresqlPassword" -}}
139+
{{- $postgresql := .Values.postgresql | default dict -}}
140+
{{- $auth := $postgresql.auth | default dict -}}
141+
{{- $auth.postgresPassword | default "postgres" }}
51142
{{- end }}

0 commit comments

Comments
 (0)