You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I am using the upstream image and a replica with hot_standby=on.
I mount a shell script to /docker-entrypoint-initdb.d/ to create multiple users and multiple databases. These script read from an environment variable in the format <user>:<password>:<db1>,<db2>|<second_user>:<password>:<db2>
# Create user harbor with password pass when non existing then create databases registry and clair and grant access to harbor when databases are non existing.# Then create user test with password pass when non existing and create test_db and grant access to test.
POSTGRES_MULTIPLE_DATABASES="harbor:pass:registry,clair,notary_server,notary_signer|test:pass:test_db"
#!/bin/bashset -e
set -u
# Source for the create user logic:# https://stackoverflow.com/a/49858797functioncreate_user() {
local user=$1local password=$2echo" Creating user '$user'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER"<<-EOSQL DO \$\$ BEGIN CREATE USER $user WITH ENCRYPTED PASSWORD '$password'; EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'not creating role $user -- it already exists'; END\$\$;EOSQL
}
functioncreate_database() {
local database=$1local owner=$2echo" Creating database '$database' and granting to '$owner'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER"<<-EOSQL DO \$\$ BEGIN CREATE DATABASE $database; GRANT ALL PRIVILEGES ON DATABASE $database TO $owner; EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'not creating and granting database $database -- it already exists'; END\$\$;EOSQL
}
functionmain() {
if [ -n"$POSTGRES_MULTIPLE_DATABASES" ];thenecho"Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"# Declare variableslocal user
local password
local db_list
forentryin$(echo "$POSTGRES_MULTIPLE_DATABASES"| tr '|''');do# Split user
user=$(echo "$entry"| tr ':'''| awk '{print $1}')# Split password
password=$(echo "$entry"| tr ':'''| awk '{print $2}')# Split access list
db_list=$(echo "$entry"| tr ':'''| awk '{print $3}')
create_user "$user""$password"fordbin$(echo "$db_list"| tr ',''');do
create_database "$db""$user"donedoneecho"Multiple databases created"fi
}
main
Is this something you would like to be built in the Docker containers and made available within the Helm chart?
Suggestions for improvements are welcome to!
The text was updated successfully, but these errors were encountered:
Currently I am using the upstream image and a replica with
hot_standby=on
.I mount a shell script to
/docker-entrypoint-initdb.d/
to create multiple users and multiple databases. These script read from an environment variable in the format<user>:<password>:<db1>,<db2>|<second_user>:<password>:<db2>
Is this something you would like to be built in the Docker containers and made available within the Helm chart?
Suggestions for improvements are welcome to!
The text was updated successfully, but these errors were encountered: