kopia lustrzana https://github.com/kartoza/docker-postgis
rodzic
2be8456411
commit
3fc60d46e7
31
README.md
31
README.md
|
@ -370,6 +370,15 @@ You can alternatively mount an extra config file into the setting's folder i.e
|
||||||
```shell
|
```shell
|
||||||
docker run --name "postgis" -v /data/extra.conf:/settings/extra.conf -p 25432:5432 -d -t kartoza/postgis
|
docker run --name "postgis" -v /data/extra.conf:/settings/extra.conf -p 25432:5432 -d -t kartoza/postgis
|
||||||
```
|
```
|
||||||
|
The `/setting` folder stores the extra configuration and is copied to the proper directory
|
||||||
|
on runtime. The environment variable `EXTRA_CONF_DIR` controls the location of the mounted
|
||||||
|
folder.
|
||||||
|
|
||||||
|
Then proceed to run the following:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker run --name "postgis" -e EXTRA_CONF_DIR=/etc/conf_settings -v /data:/etc/conf_settings -p 25432:5432 -d -t kartoza/postgis
|
||||||
|
```
|
||||||
|
|
||||||
If you want to reinitialize the data directory from scratch, you need to do:
|
If you want to reinitialize the data directory from scratch, you need to do:
|
||||||
|
|
||||||
|
@ -377,6 +386,20 @@ If you want to reinitialize the data directory from scratch, you need to do:
|
||||||
2. Set environment variables `RECREATE_DATADIR=TRUE`. Restart the service
|
2. Set environment variables `RECREATE_DATADIR=TRUE`. Restart the service
|
||||||
3. The service will delete your `DATADIR` directory and start reinitializing your data directory from scratch.
|
3. The service will delete your `DATADIR` directory and start reinitializing your data directory from scratch.
|
||||||
|
|
||||||
|
### Lockfile
|
||||||
|
|
||||||
|
During container startup, some lockfile are generated which prevent reinitialisation of some
|
||||||
|
settings. These lockfile are by default stored in the `/settings` folder, but a user can control
|
||||||
|
where to store these files using the environment variable `CONF_LOCKFILE_DIR` Example
|
||||||
|
|
||||||
|
```
|
||||||
|
-e CONF_LOCKFILE_DIR=/opt/conf_lockfiles \
|
||||||
|
-v /data/lock_files:/opt/conf_lockfiles
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note** If you change the environment variable to point to another location when you restart the container
|
||||||
|
the settings are reinitialized again.
|
||||||
|
|
||||||
## Docker secrets
|
## Docker secrets
|
||||||
|
|
||||||
To avoid passing sensitive information in environment variables, `_FILE` can be appended to
|
To avoid passing sensitive information in environment variables, `_FILE` can be appended to
|
||||||
|
@ -458,6 +481,14 @@ The SQL script will be executed against the `gis` database. Additionally, a lock
|
||||||
`/docker-entrypoint-initdb.d`, which will prevent the scripts from getting executed after the first
|
`/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.
|
container startup. Provide `IGNORE_INIT_HOOK_LOCKFILE=true` to execute the scripts on _every_ container start.
|
||||||
|
|
||||||
|
By default, the lockfile is generated in `/docker-entrypoint-initdb.d` but it can be overwritten by
|
||||||
|
passing the environment variable `SCRIPTS_LOCKFILE_DIR` which can point to another location i.e
|
||||||
|
|
||||||
|
```shell
|
||||||
|
-e SCRIPTS_LOCKFILE_DIR=/data/ \
|
||||||
|
-v /data:/data
|
||||||
|
```
|
||||||
|
|
||||||
Currently, you can pass `.sql`, `.sql.gz` and `.sh` files as mounted volumes.
|
Currently, you can pass `.sql`, `.sql.gz` and `.sh` files as mounted volumes.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|
|
@ -6,10 +6,13 @@ DEFAULT_DATADIR="/var/lib/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
||||||
# Commented for documentation. You can specify the location of
|
# Commented for documentation. You can specify the location of
|
||||||
# pg_wal directory/volume using the following environment variable:
|
# pg_wal directory/volume using the following environment variable:
|
||||||
# POSTGRES_INITDB_WALDIR (default value is unset)
|
# POSTGRES_INITDB_WALDIR (default value is unset)
|
||||||
|
DEFAULT_SCRIPTS_LOCKFILE_DIR="/docker-entrypoint.initdb.d"
|
||||||
|
DEFAULT_CONF_LOCKFILE_DIR="/settings"
|
||||||
|
DEFAULT_EXTRA_CONF_DIR="/settings"
|
||||||
ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main"
|
||||||
PG_ENV="$ROOT_CONF/environment"
|
PG_ENV="$ROOT_CONF/environment"
|
||||||
CONF="$ROOT_CONF/postgresql.conf"
|
CONF="$ROOT_CONF/postgresql.conf"
|
||||||
WAL_ARCHIVE="/opt/archivedir"
|
DEFAULT_WAL_ARCHIVE="/opt/archivedir"
|
||||||
RECOVERY_CONF="$ROOT_CONF/recovery.conf"
|
RECOVERY_CONF="$ROOT_CONF/recovery.conf"
|
||||||
POSTGRES="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/postgres"
|
POSTGRES="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/postgres"
|
||||||
INITDB="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/initdb"
|
INITDB="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/initdb"
|
||||||
|
@ -113,6 +116,22 @@ if [ -z "${SSL_DIR}" ]; then
|
||||||
SSL_DIR="/ssl_certificates"
|
SSL_DIR="/ssl_certificates"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "${WAL_ARCHIVE}" ]; then
|
||||||
|
WAL_ARCHIVE=${DEFAULT_WAL_ARCHIVE}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${SCRIPTS_LOCKFILE_DIR}" ]; then
|
||||||
|
SCRIPTS_LOCKFILE_DIR=${DEFAULT_SCRIPTS_LOCKFILE_DIR}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${CONF_LOCKFILE_DIR}" ]; then
|
||||||
|
CONF_LOCKFILE_DIR=${DEFAULT_CONF_LOCKFILE_DIR}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${EXTRA_CONF_DIR}" ]; then
|
||||||
|
EXTRA_CONF_DIR=${DEFAULT_EXTRA_CONF_DIR}
|
||||||
|
fi
|
||||||
|
|
||||||
# SSL mode
|
# SSL mode
|
||||||
if [ -z "${PGSSLMODE}" ]; then
|
if [ -z "${PGSSLMODE}" ]; then
|
||||||
PGSSLMODE=require
|
PGSSLMODE=require
|
||||||
|
@ -371,9 +390,9 @@ function restart_postgres {
|
||||||
# Useful for people who extends the image.
|
# Useful for people who extends the image.
|
||||||
|
|
||||||
function entry_point_script {
|
function entry_point_script {
|
||||||
SETUP_LOCKFILE="/docker-entrypoint-initdb.d/.entry_point.lock"
|
SETUP_LOCKFILE="${SCRIPTS_LOCKFILE_DIR}/.entry_point.lock"
|
||||||
# If lockfile doesn't exists, proceed.
|
# If lockfile doesn't exists, proceed.
|
||||||
if [[ ! -f "${SETUP_LOCKFILE}" ]] || [ "${IGNORE_INIT_HOOK_LOCKFILE}" == true ]; then
|
if [[ ! -f "${SETUP_LOCKFILE}" ]] || [ "${IGNORE_INIT_HOOK_LOCKFILE}" =~ [Tt][Rr][Uu][Ee] ]; then
|
||||||
if find "/docker-entrypoint-initdb.d" -mindepth 1 -print -quit 2>/dev/null | grep -q .; 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
|
for f in /docker-entrypoint-initdb.d/*; do
|
||||||
export PGPASSWORD=${POSTGRES_PASS}
|
export PGPASSWORD=${POSTGRES_PASS}
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
source /scripts/env-data.sh
|
source /scripts/env-data.sh
|
||||||
|
|
||||||
SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock"
|
create_dir ${EXTRA_CONF_DIR}
|
||||||
create_dir /settings
|
create_dir ${CONF_LOCKFILE_DIR}
|
||||||
|
create_dir ${SCRIPTS_LOCKFILE_DIR}
|
||||||
|
|
||||||
|
SETUP_LOCKFILE="${CONF_LOCKFILE_DIR}/.postgresql.conf.lock"
|
||||||
|
|
||||||
if [ -f "${SETUP_LOCKFILE}" ]; then
|
if [ -f "${SETUP_LOCKFILE}" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -77,9 +81,9 @@ echo "include 'streaming_replication.conf'" >> $CONF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then
|
if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then
|
||||||
# If it doesn't exists, copy from /settings directory if exists
|
# If it doesn't exists, copy from ${EXTRA_CONF_DIR} directory if exists
|
||||||
if [[ -f /settings/extra.conf ]]; then
|
if [[ -f ${EXTRA_CONF_DIR}/extra.conf ]]; then
|
||||||
cp -f /settings/extra.conf ${ROOT_CONF}/extra.conf
|
cp -f ${EXTRA_CONF_DIR}/extra.conf ${ROOT_CONF}/extra.conf
|
||||||
echo "include 'extra.conf'" >> $CONF
|
echo "include 'extra.conf'" >> $CONF
|
||||||
else
|
else
|
||||||
# default value
|
# default value
|
||||||
|
|
|
@ -92,7 +92,7 @@ echo "postgres ready"
|
||||||
source /scripts/setup-user.sh
|
source /scripts/setup-user.sh
|
||||||
|
|
||||||
# enable extensions in template1 if env variable set to true
|
# enable extensions in template1 if env variable set to true
|
||||||
if [[ "$(boolean ${POSTGRES_TEMPLATE_EXTENSIONS})" == TRUE ]] ; then
|
if [[ "$(boolean ${POSTGRES_TEMPLATE_EXTENSIONS})" =~ [Tt][Rr][Uu][Ee] ]] ; then
|
||||||
for ext in $(echo ${POSTGRES_MULTIPLE_EXTENSIONS} | tr ',' ' '); do
|
for ext in $(echo ${POSTGRES_MULTIPLE_EXTENSIONS} | tr ',' ' '); do
|
||||||
echo "Enabling \"${ext}\" in the database template1"
|
echo "Enabling \"${ext}\" in the database template1"
|
||||||
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS \"${ext}\" cascade;' template1"
|
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS \"${ext}\" cascade;' template1"
|
||||||
|
@ -110,11 +110,10 @@ for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||||
if [[ ${RESULT} -eq 0 ]]; then
|
if [[ ${RESULT} -eq 0 ]]; then
|
||||||
echo "Create db ${db}"
|
echo "Create db ${db}"
|
||||||
su - postgres -c "createdb -O ${POSTGRES_USER} ${db}"
|
su - postgres -c "createdb -O ${POSTGRES_USER} ${db}"
|
||||||
|
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS pg_cron cascade;' ${SINGLE_DB}"
|
||||||
for ext in $(echo ${POSTGRES_MULTIPLE_EXTENSIONS} | tr ',' ' '); do
|
for ext in $(echo ${POSTGRES_MULTIPLE_EXTENSIONS} | tr ',' ' '); do
|
||||||
echo "Enabling \"${ext}\" in the database ${db}"
|
echo "Enabling \"${ext}\" in the database ${db}"
|
||||||
if [[ ${ext} = 'pg_cron' ]]; then
|
if [[ ${ext} != 'pg_cron' ]]; then
|
||||||
echo " pg_cron doesn't need to be installed"
|
|
||||||
else
|
|
||||||
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS \"${ext}\" cascade;' $db"
|
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS \"${ext}\" cascade;' $db"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -144,12 +143,5 @@ for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
CRON_LOCKFILE="${ROOT_CONF}/.cron_ext.lock"
|
|
||||||
if [ ! -f "${CRON_LOCKFILE}" ]; then
|
|
||||||
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS pg_cron cascade;' ${SINGLE_DB}"
|
|
||||||
touch ${CRON_LOCKFILE}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This should show up in docker logs afterwards
|
# This should show up in docker logs afterwards
|
||||||
su - postgres -c "psql -l 2>&1"
|
su - postgres -c "psql -l 2>&1"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
source /scripts/env-data.sh
|
source /scripts/env-data.sh
|
||||||
|
|
||||||
SETUP_LOCKFILE="${ROOT_CONF}/.pg_hba.conf.lock"
|
SETUP_LOCKFILE="${CONF_LOCKFILE_DIR}/.pg_hba.conf.lock"
|
||||||
if [ -f "${SETUP_LOCKFILE}" ]; then
|
if [ -f "${SETUP_LOCKFILE}" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
source /scripts/env-data.sh
|
source /scripts/env-data.sh
|
||||||
|
|
||||||
SETUP_LOCKFILE="${ROOT_CONF}/.ssl.conf.lock"
|
SETUP_LOCKFILE="${CONF_LOCKFILE_DIR}/.ssl.conf.lock"
|
||||||
if [ -f "${SETUP_LOCKFILE}" ]; then
|
if [ -f "${SETUP_LOCKFILE}" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
Ładowanie…
Reference in New Issue