mirror of
https://github.com/GothenburgBitFactory/taskchampion-sync-server.git
synced 2026-07-17 17:04:57 +00:00
Init container to run sql file
This commit is contained in:
committed by
Dustin J. Mitchell
parent
a8f7281786
commit
27c3f954c9
@ -25,6 +25,56 @@ spec:
|
||||
{{- end }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.securityContext | nindent 8 }}
|
||||
{{- if and .Values.postgres.enabled .Values.postgres.initContainer.enabled }}
|
||||
initContainers:
|
||||
- name: postgres-init
|
||||
image: "{{ .Values.postgres.initContainer.image }}"
|
||||
imagePullPolicy: {{ .Values.postgres.initContainer.imagePullPolicy }}
|
||||
env:
|
||||
- name: PGHOST
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "taskchampion-sync-server.postgres-secret-name" . }}
|
||||
key: host
|
||||
- name: PGPORT
|
||||
value: "{{ .Values.postgres.port }}"
|
||||
- name: PGUSER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "taskchampion-sync-server.postgres-secret-name" . }}
|
||||
key: username
|
||||
- name: PGPASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "taskchampion-sync-server.postgres-secret-name" . }}
|
||||
key: password
|
||||
- name: PGDATABASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "taskchampion-sync-server.postgres-secret-name" . }}
|
||||
key: database
|
||||
- name: SCHEMA_URL
|
||||
value: {{ include "taskchampion-sync-server.schema-url" . | quote }}
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
set -e
|
||||
until pg_isready -h "$PGHOST" -p "$PGPORT" -U "$PGUSER"; do
|
||||
echo 'Waiting for PostgreSQL...'
|
||||
sleep 2
|
||||
done
|
||||
echo "Downloading schema from ${SCHEMA_URL}..."
|
||||
wget -qO /tmp/schema.sql "$SCHEMA_URL" || {
|
||||
echo 'Failed to download schema - continuing with main container'
|
||||
exit 0
|
||||
}
|
||||
psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" -f /tmp/schema.sql || {
|
||||
echo 'Schema execution failed (SQL error) - continuing with main container'
|
||||
exit 0
|
||||
}
|
||||
echo 'Schema executed successfully'
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: taskchampion-sync-server
|
||||
{{- if eq .Values.postgres.enabled true }}
|
||||
|
||||
Reference in New Issue
Block a user