I am working on adding an init-container in my app's deployment.yaml so I can decouple my postgres db bootstrap or schema evolution.
As V1 I am trying to mount a sql file that will include the bootstraping of the db ( Database, Schema , Users) from the local directory and then by using a Postgres client image to run the commands in the script.
As of now I have the below
initContainers:
- name: init-myservice
image: jbergknoff/postgresql-client
command: ['sh', '-c', 'psql -a -f /bootstrap.sql']
env:
- name: PGUSER
....
.....
volumeMounts:
- mountPath: /bootstrap.sql
name: bootstrap.sql
From my search results I am guessing I have to use an empty dir volume type to mount the file but I can not get it to work as of now.
I need to also pass the db credentials but not sure how to use them from env variables inside the sql script is there any syntax for that ?
Could you help connect the dots together ? Mainly how to mount the file in the init container and how to grab the env variables from the shell script and use them in the sql script to create for example the user with a password ?
Thanks in advance.