mirror of
https://github.com/shadoll/helm-charts.git
synced 2026-08-28 11:33:17 +00:00
feat: Add Pocket ID Helm chart with deployment, service, ingress, and backup configurations
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
{{- if .Values.dbInit.enabled }}
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-db-init
|
||||
annotations:
|
||||
"helm.sh/hook": post-install
|
||||
"helm.sh/hook-weight": "-5"
|
||||
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: OnFailure
|
||||
containers:
|
||||
- name: postgres-init
|
||||
image: {{ .Values.dbInit.image }}
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
set -e
|
||||
until pg_isready -h $PGHOST -p $PGPORT -U $ADMIN_USER; do
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
export PGPASSWORD=$POSTGRES_ADMIN_PASSWORD
|
||||
|
||||
echo "Creating user $DB_USER if missing..."
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d postgres -tc "SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'" | grep -q 1 || \
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d postgres -c "CREATE USER $DB_USER WITH PASSWORD '${DB_USER_PASSWORD}';"
|
||||
|
||||
echo "Creating database $DB_NAME if missing..."
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d postgres -tc "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" | grep -q 1 || \
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;"
|
||||
|
||||
echo "Granting privileges..."
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d $DB_NAME -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d $DB_NAME -c "GRANT ALL PRIVILEGES ON SCHEMA public TO $DB_USER;"
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d $DB_NAME -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $DB_USER;"
|
||||
psql -h $PGHOST -p $PGPORT -U $ADMIN_USER -d $DB_NAME -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $DB_USER;"
|
||||
echo "Database initialization complete."
|
||||
env:
|
||||
- name: PGHOST
|
||||
value: {{ .Values.dbInit.host | quote }}
|
||||
- name: PGPORT
|
||||
value: {{ .Values.dbInit.port | quote }}
|
||||
- name: ADMIN_USER
|
||||
value: {{ .Values.dbInit.adminUser | quote }}
|
||||
- name: DB_NAME
|
||||
value: {{ .Values.dbInit.database | quote }}
|
||||
- name: DB_USER
|
||||
value: {{ .Values.dbInit.user | quote }}
|
||||
- name: POSTGRES_ADMIN_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.existingSecret }}
|
||||
key: {{ .Values.dbInit.adminPasswordSecretKey }}
|
||||
- name: DB_USER_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.existingSecret }}
|
||||
key: {{ .Values.dbInit.userPasswordSecretKey }}
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "100m"
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user