feat: auto-run migrations via psql init container on scheduler startup
This commit is contained in:
@@ -28,6 +28,38 @@ spec:
|
||||
{{- end }}
|
||||
securityContext:
|
||||
{{- include "stonks.podSecurityContext" $root | nindent 8 }}
|
||||
{{- if eq $svc.image "scheduler" }}
|
||||
initContainers:
|
||||
- name: run-migrations
|
||||
image: {{ $root.Values.image.registry }}/{{ $svc.image }}:{{ $root.Values.image.tag }}
|
||||
imagePullPolicy: {{ $root.Values.image.pullPolicy }}
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
for f in $(ls /app/infra/migrations/*.sql 2>/dev/null | sort); do
|
||||
echo "Applying $(basename $f)..."
|
||||
PGPASSWORD="$POSTGRES_PASSWORD" psql \
|
||||
-h "$POSTGRES_HOST" -p "$POSTGRES_PORT" \
|
||||
-U "$POSTGRES_USER" -d "$POSTGRES_DB" \
|
||||
-f "$f" -v ON_ERROR_STOP=0 2>&1 | tail -1 || true
|
||||
done
|
||||
echo "Migrations complete."
|
||||
securityContext:
|
||||
{{- include "stonks.containerSecurityContext" $root | nindent 12 }}
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: stonks-config
|
||||
{{- range $svc.secrets }}
|
||||
- secretRef:
|
||||
name: {{ . }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests: { cpu: 50m, memory: 64Mi }
|
||||
limits: { cpu: 200m, memory: 128Mi }
|
||||
volumeMounts:
|
||||
- name: tmp
|
||||
mountPath: /tmp
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: {{ $svc.image }}
|
||||
image: {{ $root.Values.image.registry }}/{{ $svc.image }}:{{ $root.Values.image.tag }}
|
||||
|
||||
Reference in New Issue
Block a user