From 8edc0d6c1db4238bb165477675bbbf1a3228330f Mon Sep 17 00:00:00 2001 From: nilsnolde Date: Mon, 1 Mar 2021 13:20:12 +0100 Subject: [PATCH] add IGNORE_INIT_HOOK_LOCKFILE env var to be able to execute scripts on every container startup --- README.md | 14 +++++++------- scripts/env-data.sh | 9 ++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9e58c04..e0d9cc5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ To build the image yourself do: docker build -t kartoza/postgis git://github.com/kartoza/docker-postgis ``` -Alternatively clone the repository and build against any preferred branch +Alternatively clone the repository and build against any preferred branch ``` git clone git://github.com/kartoza/docker-postgis @@ -101,7 +101,7 @@ docker build --build-arg DISTRO=ubuntu --build-arg IMAGE_VERSION=focal --build-a #### Locales -By default, the image build will include **all** `locales` to cover any value for `locale` settings such as `DEFAULT_COLLATION`, `DEFAULT_CTYPE` or `DEFAULT_ENCODING`. +By default, the image build will include **all** `locales` to cover any value for `locale` settings such as `DEFAULT_COLLATION`, `DEFAULT_CTYPE` or `DEFAULT_ENCODING`. You can safely delete all `locales` except for the ones you need in `scripts/locale.gen`. This will speed up the build considerably. @@ -190,7 +190,7 @@ username, password and/or default database name(or multiple databases comma sepa * `-e POSTGRES_USER=` * `-e POSTGRES_PASS=` **NB** 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 +docker can interpolate the password. Example using a password with a `$` you will need to escape it ie `$$` * `-e POSTGRES_DBNAME=` * `-e POSTGRES_MULTIPLE_EXTENSIONS=postgis,hstore,postgis_topology,postgis_raster,pgrouting` @@ -326,7 +326,7 @@ database. Since the environment variable POSTGRES_DB allows us to specify multiple database that can be created on startup. When running scripts they will only be executed against the first database ie POSTGRES_DB=gis,data,sample -The SQL script will be executed against the gis database. +The SQL script will be executed against the gis database. Additionally, a lock file is generated in `/docker-entrypoint-initdb.d`, which will prevent the scripts from getting executed after the first container startup. Provide `IGNORE_INIT_HOOK_LOCKFILE=true` to execute the scripts on _every_ container start. Currently you can pass `.sql` , `.sql.gz` and `.sh` files as mounted volumes. @@ -427,7 +427,7 @@ with the following SQL assuming the ${REPLICATION_USER} is called replicator ALTER DEFAULT PRIVILEGES IN SCHEMA data GRANT SELECT ON TABLES TO replicator; -**NB** You need to setup a strong password for replication otherwise the +**NB** You need to setup a strong password for replication otherwise the default password for ${REPLICATION_USER} will default to `replicator` To experiment with the replication abilities, you can see a [docker-compose.yml](sample/replication/docker-compose.yml) @@ -549,7 +549,7 @@ For a detailed example see the docker-compose in the folder `sample/logical_repl ### Support If you require more substantial assistance from [kartoza](https://kartoza.com) (because our work and interaction on docker-postgis is pro bono), -please consider taking out a [Support Level Agreeement](https://kartoza.com/en/shop/product/support) +please consider taking out a [Support Level Agreeement](https://kartoza.com/en/shop/product/support) ## Credits @@ -557,4 +557,4 @@ Tim Sutton (tim@kartoza.com) Gavin Fleming (gavin@kartoza.com) Rizky Maulana (rizky@kartoza.com) Admire Nyakudya (admire@kartoza.com) -October 2020 \ No newline at end of file +October 2020 diff --git a/scripts/env-data.sh b/scripts/env-data.sh index c308ed8..f820650 100644 --- a/scripts/env-data.sh +++ b/scripts/env-data.sh @@ -245,7 +245,6 @@ if [ -z "${REPLICATION_PASS}" ]; then REPLICATION_PASS=replicator fi - if [ -z "$EXTRA_CONF" ]; then EXTRA_CONF="" fi @@ -258,11 +257,16 @@ if [ -z "$PASSWORD_AUTHENTICATION" ]; then PASSWORD_AUTHENTICATION="scram-sha-256" fi +if [ -z "$IGNORE_INIT_HOOK_LOCKFILE" ]; then + IGNORE_INIT_HOOK_LOCKFILE=false +fi + # Compatibility with official postgres variable # Official postgres variable gets priority if [ -n "${POSTGRES_PASSWORD}" ]; then POSTGRES_PASS=${POSTGRES_PASSWORD} fi + if [ -n "${PGDATA}" ]; then DATADIR=${PGDATA} fi @@ -320,7 +324,7 @@ function restart_postgres { function entry_point_script { SETUP_LOCKFILE="/docker-entrypoint-initdb.d/.entry_point.lock" # If lockfile doesn't exists, proceed. - if [[ ! -f "${SETUP_LOCKFILE}" ]]; then + if [[ ! -f "${SETUP_LOCKFILE}" ]] || [ "${IGNORE_INIT_HOOK_LOCKFILE}" == true ]; then if find "/docker-entrypoint-initdb.d" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then for f in /docker-entrypoint-initdb.d/*; do export PGPASSWORD=${POSTGRES_PASS} @@ -361,4 +365,3 @@ until su - postgres -c "${PG_BASEBACKUP} -X stream -h ${REPLICATE_FROM} -p ${REP done } -