kopia lustrzana https://github.com/kartoza/docker-postgis
update readme
rodzic
3b5b0090d0
commit
b48240ab43
12
README.md
12
README.md
|
@ -61,6 +61,7 @@ differentiates itself by:
|
|||
it runs with e.g. `QGIS`
|
||||
* Streaming replication and logical replication support included (turned off by default)
|
||||
* Ability to create multiple database when starting the container.
|
||||
* Ability to define multiple super users.
|
||||
* Ability to create multiple schemas when starting the container.
|
||||
* Enable multiple extensions in the database when setting it up.
|
||||
* `Gdal` drivers automatically registered for pg raster.
|
||||
|
@ -296,7 +297,16 @@ database name(or multiple databases comma separated).
|
|||
* `-e POSTGRES_USER=<PGUSER>`
|
||||
* `-e POSTGRES_PASS=<PGPASSWORD>`
|
||||
|
||||
**Note:** You should use a strong passwords. If you are using docker-compose make sure docker can
|
||||
You can also pass a comma separated values of the env variable to define multiple super users i.e
|
||||
|
||||
```bash
|
||||
POSTGRES_USER=docker,gis
|
||||
POSTGRES_PASS=gis.data
|
||||
```
|
||||
The number of passwords and users will need to match otherwise the container will hang. Also try to
|
||||
pass username and passwords with commas as we use a comma as a separator for the loop.
|
||||
|
||||
**Note:** You should use a strong passwords. If you are using docker-compose make sure docker can
|
||||
interpolate the password. Example using a password with a `$` you will need to escape it ie `$$`
|
||||
|
||||
* `-e POSTGRES_DBNAME=<PGDBNAME>`
|
||||
|
|
|
@ -533,3 +533,14 @@ function extension_install() {
|
|||
fi
|
||||
|
||||
}
|
||||
|
||||
function role_check() {
|
||||
ROLE_NAME=$1
|
||||
|
||||
RESULT=$(su - postgres -c "psql postgres -t -c \"SELECT 1 FROM pg_roles WHERE rolname = '$ROLE_NAME'\"")
|
||||
COMMAND="ALTER"
|
||||
if [ -z "$RESULT" ]; then
|
||||
COMMAND="CREATE"
|
||||
fi
|
||||
|
||||
}
|
|
@ -2,20 +2,9 @@
|
|||
|
||||
source /scripts/env-data.sh
|
||||
|
||||
# This script will setup new configured user
|
||||
# This script will setup new users using $POSTGRES_USER and $POSTGRES_PASS env variables.
|
||||
|
||||
# Note that $POSTGRES_USER and $POSTGRES_PASS below are optional parameters that can be passed
|
||||
# via docker run e.g.
|
||||
#docker run --name="postgis" -e POSTGRES_USER=qgis -e POSTGRES_PASS=qgis -d -v
|
||||
#/var/docker-data/postgres-dat:/var/lib/postgresql -t qgis/postgis:6
|
||||
|
||||
# If you dont specify a user/password in docker run, we will generate one
|
||||
# here and create a user called 'docker' to go with it.
|
||||
|
||||
# Only create credentials if this is a master database
|
||||
# Slave database will just mirror from master users
|
||||
|
||||
# Check user already exists
|
||||
|
||||
# TODO - Fragile check if a password already contains a comma
|
||||
SUPER_USERS=$(echo "$POSTGRES_USER" | awk -F "," '{print NF-1}')
|
||||
|
@ -25,7 +14,7 @@ SUPER_USERS_PASSWORD=$(echo "$POSTGRES_PASS" | awk -F "," '{print NF-1}')
|
|||
|
||||
# check if the number of super users match the number of passwords defined
|
||||
if [[ ${SUPER_USERS} != ${SUPER_USERS_PASSWORD} ]];then
|
||||
echo -e "\e[1;31m Number of passwords and users should match \033[0m"
|
||||
echo -e "\e[1;31m Error Number of passwords and users should match \033[0m"
|
||||
exit 1
|
||||
else
|
||||
env_array ${POSTGRES_USER}
|
||||
|
@ -33,11 +22,8 @@ else
|
|||
env_array ${POSTGRES_PASS}
|
||||
for db_pass in "${strarr[@]}"; do
|
||||
echo -e "\e[32m [Entrypoint] creating superuser \e[1;31m ${db_user} \033[0m"
|
||||
RESULT=`su - postgres -c "psql postgres -t -c \"SELECT 1 FROM pg_roles WHERE rolname = '$db_user'\""`
|
||||
COMMAND="ALTER"
|
||||
if [ -z "$RESULT" ]; then
|
||||
COMMAND="CREATE"
|
||||
fi
|
||||
# Check user already exists
|
||||
role_check $db_user
|
||||
su - postgres -c "psql postgres -c \"$COMMAND USER $db_user WITH SUPERUSER ENCRYPTED PASSWORD '$db_pass';\""
|
||||
done
|
||||
done
|
||||
|
@ -46,10 +32,6 @@ fi
|
|||
|
||||
|
||||
echo "Creating replication user $REPLICATION_USER"
|
||||
RESULT_REPLICATION=`su - postgres -c "psql postgres -t -c \"SELECT 1 FROM pg_roles WHERE rolname = '$REPLICATION_USER'\""`
|
||||
COMMANDS="ALTER"
|
||||
if [ -z "$RESULT_REPLICATION" ]; then
|
||||
COMMANDS="CREATE"
|
||||
fi
|
||||
su - postgres -c "psql postgres -c \"$COMMANDS USER $REPLICATION_USER WITH REPLICATION ENCRYPTED PASSWORD '$REPLICATION_PASS';\""
|
||||
#su - postgres -c "psql postgres -c \"GRANT pg_read_all_data TO $REPLICATION_USER;\""
|
||||
role_check $REPLICATION_USER
|
||||
su - postgres -c "psql postgres -c \"$COMMAND USER $REPLICATION_USER WITH REPLICATION ENCRYPTED PASSWORD '$REPLICATION_PASS';\""
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue