{{- if .Values.deployment.db.enabled -}} apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ include "supabase.db.fullname" . }} labels: {{- include "supabase.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.db.enabled }} replicas: {{ .Values.deployment.db.replicaCount }} {{- end }} selector: matchLabels: {{- include "supabase.db.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.deployment.db.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: {{- include "supabase.db.selectorLabels" . | nindent 8 }} spec: {{- with .Values.image.db.pullSecrets}} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "supabase.db.serviceAccountName" . }} securityContext: {{- toYaml .Values.deployment.db.podSecurityContext | nindent 8 }} initContainers: - name: init-db image: "{{ .Values.image.db.repository }}:{{ .Values.image.db.tag | default .Chart.AppVersion }}" imagePullPolicy: IfNotPresent command: ["/bin/sh", "-c"] args: - | echo "Copying init scripts into existing image script directory..." cp -r /docker-entrypoint-initdb.d/* /initdb.d/ cp /custom-init-scripts/98-webhooks.sql /initdb.d/init-scripts/ cp /custom-init-scripts/99-roles.sql /initdb.d/init-scripts/ cp /custom-init-scripts/99-jwt.sql /initdb.d/init-scripts/ cp /custom-init-scripts/99-logs.sql /initdb.d/migrations/ cp /custom-init-scripts/99-realtime.sql /initdb.d/migrations/ cp /custom-init-scripts/97-_supabase.sql /initdb.d/migrations/ cp /custom-init-scripts/99-pooler.sql /initdb.d/migrations/ echo "Copying user-defined migration scripts..." cp /custom-migrations/* /initdb.d/migrations/ || echo "Skip migrations" echo "Initialization scripts are ready" volumeMounts: - mountPath: /custom-init-scripts name: custom-init-scripts - mountPath: /custom-migrations name: custom-migrations - mountPath: /initdb.d name: initdb-scripts-data containers: - name: {{ include "supabase.db.name" $ }} securityContext: {{- toYaml .Values.deployment.db.securityContext | nindent 12 }} image: "{{ .Values.image.db.repository }}:{{ .Values.image.db.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.db.pullPolicy }} lifecycle: preStop: exec: command: ["/bin/sh", "-c", "pg_ctl -D /var/lib/postgres/data -w -t 60 -m fast stop"] env: {{- range $key, $value := .Values.environment.db }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} - name: PGPASSWORD valueFrom: secretKeyRef: {{- if .Values.secret.db.secretRef }} name: {{ .Values.secret.db.secretRef }} key: {{ .Values.secret.db.secretRefKey.password | default "password" }} {{- else }} name: {{ include "supabase.secret.db" . }} key: password {{- end }} - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: {{- if .Values.secret.db.secretRef }} name: {{ .Values.secret.db.secretRef }} key: {{ .Values.secret.db.secretRefKey.password | default "password" }} {{- else }} name: {{ include "supabase.secret.db" . }} key: password {{- end }} - name: PGDATABASE valueFrom: secretKeyRef: {{- if .Values.secret.db.secretRef }} name: {{ .Values.secret.db.secretRef }} key: {{ .Values.secret.db.secretRefKey.database | default "database" }} {{- else }} name: {{ include "supabase.secret.db" . }} key: database {{- end }} - name: POSTGRES_DB valueFrom: secretKeyRef: {{- if .Values.secret.db.secretRef }} name: {{ .Values.secret.db.secretRef }} key: {{ .Values.secret.db.secretRefKey.database | default "database" }} {{- else }} name: {{ include "supabase.secret.db" . }} key: database {{- end }} - name: JWT_SECRET valueFrom: secretKeyRef: {{- if .Values.secret.jwt.secretRef }} name: {{ .Values.secret.jwt.secretRef }} key: {{ .Values.secret.jwt.secretRefKey.secret | default "database" }} {{- else }} name: {{ include "supabase.secret.jwt" . }} key: secret {{- end }} {{- with .Values.deployment.db.livenessProbe }} livenessProbe: {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.deployment.db.readinessProbe }} readinessProbe: {{- toYaml . | nindent 12 }} {{- end }} ports: - name: http containerPort: 5432 protocol: TCP volumeMounts: - mountPath: /docker-entrypoint-initdb.d name: initdb-scripts-data {{- with .Values.deployment.db.volumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} {{- if .Values.persistence.db.enabled }} - mountPath: /var/lib/postgresql/data name: postgres-volume subPath: postgres-data {{- end }} {{- with .Values.deployment.db.resources }} resources: {{- toYaml . | nindent 12 }} {{- end }} volumes: - name: initdb-scripts-data emptyDir: medium: "" - name: custom-init-scripts configMap: name: {{ include "supabase.db.fullname" . }}-initdb - name: custom-migrations configMap: name: {{ include "supabase.db.fullname" . }}-migrations {{- with .Values.deployment.db.volumes }} {{- toYaml . | nindent 8 }} {{- end }} {{- if .Values.persistence.db.enabled }} - name: postgres-volume persistentVolumeClaim: claimName: {{ include "supabase.pvc.name" (dict "root" $ "name" "db") }} {{- end }} {{- with .Values.deployment.db.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.deployment.db.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.deployment.db.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} {{- end }}