kopia lustrzana https://github.com/kartoza/docker-postgis
Fix various issues with the database (#127)
* Fix typo in helper script
* Port work in develop to 10 branch (#90)
* Port 9.6 to develop (#89)
* Part one of porting work from 9.6 to 10
* Backported more scripts from 9.6 branch
* Added missing apt update in dockerfile
* Updates to entrypoint to reference image and update docker-compose to reference 10 pg
* Added sample and docs from 9.6 branch
* Removed my diagram as Rizky had already added one
* Fix env paths for pg 10
* Fixes for backporting work from 9.6 to 10 - dbb now spins up and accepts connections properly
* Update README.md
* Backport from branch: 9.6-2.4
Fix default datadir
- Change into default datadir
- Add small unittest
* Optimise PostgreSQL performance and align with the changes done in 9.6
version
* Fix version numbers
* Minor change to correct env file
* Merged 10 branch into develop
* Remove reduntant conf file from dockerfile
* Remove reduntant conf file directive from setup script
* Remove reduntant conf file directive from script
* Migrate settings to be compatible with PostgreSQL version 11
* fix ssl setup
* Align changes to postgresql version 11
* Set destroy database to false
* Commented out code for destroy database
* Fix version number for build
* Merge develop to master to align with PostgreSQL 11 (#117)
* Added note about version number
* README update
* Revert to using pg 9.3 in latest build - prevent breaking downstream apps for now
* Revert to pg 9.3
* Fix references to 9.4 to make them 9.3 rather
* Fix incorrect version in 9.4 branch
* Fix TOPOLOGY conditional typo
* Update run-postgis-docker.sh
* Update run-postgis-docker.sh
added IPADDRESS
* Updates from Marco
* Allow connections from 192.168 private network too
* start temporary server in local-only mode, poll instead of blind wait, preserve pid 1
* Enable PostGIS Out DB raster support
http://postgis.net/2015/05/02/tip_enable_raster_drivers/
http://postgis.net/docs/postgis_installation.html#install_short_version
* Remove hardcoded reference to container name "docker"
* upgrade postgres to 9.5 and postgis to 2.2
* Added flexible IP range as arg on docker run
* Added better description to docker env vars
* Updated references to pg and postgis versions in readme
* Followup 0745c488
, fix references to 9.4
* problem version
postgresql version is 9.4, instead of 9.5
* Added note about allowing external ports.
* Update README.md
* Cleanups to 9.5 branch - remove old supervisor files
* Fix for README
* 9.5 2.2 (#49)
* Allow connections from 192.168 private network too
* Updated references to pg and postgis versions in readme
* Cleanups to 9.5 branch - remove old supervisor files
* Fix for README
* Dont add supervisor stuff which is deprecated
* Fix 9.4 reference
* Allow changing the default database name (#50)
* Allow changing the default database name (#50)
* Allow changing the default database name (#50) (#52)
* Commented out legacy scripts since it seems they are removed in 2.2
* 9.5 2.2 (#58)
* Allow changing the default database name (#50)
* Commented out legacy scripts since it seems they are removed in 2.2
* 9.5 2.2 (#59)
* Allow changing the default database name (#50)
* Commented out legacy scripts since it seems they are removed in 2.2
* Improve start (#57)
* Make initial dir optional
* Improve termination of background initial process #56
* Merge improvements from 9.5 branch (#60)
* Allow changing the default database name (#50)
* Commented out legacy scripts since it seems they are removed in 2.2
* 9.5 2.2 (#59)
* Allow changing the default database name (#50)
* Commented out legacy scripts since it seems they are removed in 2.2
* Improve start (#57)
* Make initial dir optional
* Improve termination of background initial process #56
* Added more options to convenience run script
* Added missing l from getopts
* Added missing l from getopts
* 9.5 2.2 (#61)
* Allow changing the default database name (#50)
* Allow changing the default database name (#50)
* Allow changing the default database name (#50) (#52)
* Commented out legacy scripts since it seems they are removed in 2.2
* Added more options to convenience run script
* Added missing l from getopts
* Added missing l from getopts
* Tweak convenience scripts (#62)
* Added missing l from getopts
* allow connection when using docker compose (#65)
see https://github.com/docker/compose/issues/4336
and https://github.com/kartoza/docker-postgis/issues/40
* Install gnupg for fetching keys first
* Fix key fetching
* Updated to 9.6 and postgis 2.4
* Ditch apt-cacher stuff
* Upgraded to PG 10
* change version from postgresql-10.0 to 10 and fix typo in run-postgis… (#76)
* change version from postgresql-10.0 to 10 and fix typo in run-postgis file
* edit setup.sh to version 10
* Change from version 10.0 to 10 in Dockerfile (#75)
I checked that postgresql-10.0 is an invalid name. It should be just postgresql-10
* Fixes for pg 10 to start nicely
* Port 9.6 to develop (#89)
* Part one of porting work from 9.6 to 10
* Backported more scripts from 9.6 branch
* Added missing apt update in dockerfile
* Updates to entrypoint to reference image and update docker-compose to reference 10 pg
* Added sample and docs from 9.6 branch
* Removed my diagram as Rizky had already added one
* Fix env paths for pg 10
* Fixes for backporting work from 9.6 to 10 - dbb now spins up and accepts connections properly
* Update README.md
* Fix #90 and replace references to slave with replicant
(Slave is a pejorative term)
* Backport from branch: 9.6-2.4
Fix default datadir
- Change into default datadir
- Add small unittest
* Merge branch 10 into develop (#113)
* Fix typo in helper script
* Port work in develop to 10 branch (#90)
* Port 9.6 to develop (#89)
* Part one of porting work from 9.6 to 10
* Backported more scripts from 9.6 branch
* Added missing apt update in dockerfile
* Updates to entrypoint to reference image and update docker-compose to reference 10 pg
* Added sample and docs from 9.6 branch
* Removed my diagram as Rizky had already added one
* Fix env paths for pg 10
* Fixes for backporting work from 9.6 to 10 - dbb now spins up and accepts connections properly
* Update README.md
* Backport from branch: 9.6-2.4
Fix default datadir
- Change into default datadir
- Add small unittest
* Optimise PostgreSQL performance and align with the changes done in 9.6
version
* Fix version numbers
* Minor change to correct env file
* Merged 10 branch into develop
* Remove reduntant conf file from dockerfile
* Remove reduntant conf file directive from setup script
* Remove reduntant conf file directive from script
* Port changes for Postgres version 11 (#114)
* Fix typo in helper script
* Port work in develop to 10 branch (#90)
* Port 9.6 to develop (#89)
* Part one of porting work from 9.6 to 10
* Backported more scripts from 9.6 branch
* Added missing apt update in dockerfile
* Updates to entrypoint to reference image and update docker-compose to reference 10 pg
* Added sample and docs from 9.6 branch
* Removed my diagram as Rizky had already added one
* Fix env paths for pg 10
* Fixes for backporting work from 9.6 to 10 - dbb now spins up and accepts connections properly
* Update README.md
* Backport from branch: 9.6-2.4
Fix default datadir
- Change into default datadir
- Add small unittest
* Optimise PostgreSQL performance and align with the changes done in 9.6
version
* Fix version numbers
* Minor change to correct env file
* Merged 10 branch into develop
* Remove reduntant conf file from dockerfile
* Remove reduntant conf file directive from setup script
* Remove reduntant conf file directive from script
* Migrate settings to be compatible with PostgreSQL version 11
* fix ssl setup
* Port changes to 11 branch (#115)
* Fix typo in helper script
* Port work in develop to 10 branch (#90)
* Port 9.6 to develop (#89)
* Part one of porting work from 9.6 to 10
* Backported more scripts from 9.6 branch
* Added missing apt update in dockerfile
* Updates to entrypoint to reference image and update docker-compose to reference 10 pg
* Added sample and docs from 9.6 branch
* Removed my diagram as Rizky had already added one
* Fix env paths for pg 10
* Fixes for backporting work from 9.6 to 10 - dbb now spins up and accepts connections properly
* Update README.md
* Backport from branch: 9.6-2.4
Fix default datadir
- Change into default datadir
- Add small unittest
* Optimise PostgreSQL performance and align with the changes done in 9.6
version
* Fix version numbers
* Minor change to correct env file
* Merged 10 branch into develop
* Remove reduntant conf file from dockerfile
* Remove reduntant conf file directive from setup script
* Remove reduntant conf file directive from script
* Migrate settings to be compatible with PostgreSQL version 11
* fix ssl setup
* Align changes to postgresql version 11
* Set destroy database to false
* Commented out code for destroy database
* Fix version number for build
* Implement conf lock file check (#116)
It will make sure that the conf file will only be generated once
for a given container.
* Added new configuration in recovery.conf and postgres optimisations for master-slave replication (#118)
* Remove template logic and use plain create extension (#119)
* Remove template logic and added option to create multiple databases and extensions
* Fix travis error
* More optimisations for replication
* Fix logic for checking if database exists since we now can create
multiple databases.
* Added Licence file
* add logic for running sql scripts and fix other various issues
* add logic to check if entrypoint directory is empty or not and then run sql
* fix pid error on startup of replication
* add better ways of checking if database exists whilst creating them
pull/130/head
rodzic
21b45fcabd
commit
a5fad69fc1
17
README.md
17
README.md
|
@ -150,6 +150,23 @@ Under ubuntu 16.04 the postgresql client can be installed like this:
|
|||
sudo apt-get install postgresql-client-9.6
|
||||
```
|
||||
|
||||
## Running SQL scripts on container startup.
|
||||
|
||||
|
||||
In some instances users want to run some SQL scripts to populate the
|
||||
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.
|
||||
|
||||
Currently you can pass `.sql` and `.sql.gz` files as mounted volumes.
|
||||
|
||||
```
|
||||
|
||||
docker run -d -v ./setup-db.sql:/docker-entrypoint-initdb.d/setup-db.sql kartoza/postgis`
|
||||
```
|
||||
|
||||
|
||||
## Storing data on the host rather than the container.
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# This script will run as the postgres user due to the Dockerfile USER directive
|
||||
set -e
|
||||
|
||||
#TODO Prepare lock files that prevent running the setup-conf,setup-pg_hba,setup-ssl.sh on each restart
|
||||
# Setup postgres CONF file
|
||||
|
||||
source /setup-conf.sh
|
||||
|
@ -15,29 +14,63 @@ source /setup-ssl.sh
|
|||
|
||||
source /setup-pg_hba.sh
|
||||
|
||||
# Running extended script or sql if provided.
|
||||
# Useful for people who extends the image.
|
||||
function entry_point_script {
|
||||
SETUP_LOCKFILE="/docker-entrypoint-initdb.d/.entry_point.lock"
|
||||
if [[ -f "${SETUP_LOCKFILE}" ]]; then
|
||||
return 0
|
||||
else
|
||||
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}
|
||||
list=(`echo ${POSTGRES_DBNAME} | tr ',' ' '`)
|
||||
arr=(${list})
|
||||
SINGLE_DB=${arr[0]}
|
||||
case "$f" in
|
||||
*.sql) echo "$0: running $f"; psql ${SINGLE_DB} -U ${POSTGRES_USER} -p 5432 -h localhost -f ${f} || true ;;
|
||||
*.sql.gz) echo "$0: running $f"; gunzip < "$f" | psql ${SINGLE_DB} -U ${POSTGRES_USER} -p 5432 -h localhost || true ;;
|
||||
*) echo "$0: ignoring $f" ;;
|
||||
esac
|
||||
echo
|
||||
done
|
||||
# Put lock file to make sure entry point scripts were run
|
||||
touch ${SETUP_LOCKFILE}
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function kill_postgres {
|
||||
PID=`cat ${PG_PID}`
|
||||
kill -TERM ${PID}
|
||||
|
||||
# Wait for background postgres main process to exit
|
||||
while [[ "$(ls -A ${PG_PID} 2>/dev/null)" ]]; do
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -z "$REPLICATE_FROM" ]]; then
|
||||
# This means this is a master instance. We check that database exists
|
||||
echo "Setup master database"
|
||||
source /setup-database.sh
|
||||
entry_point_script
|
||||
kill_postgres
|
||||
else
|
||||
# This means this is a slave/replication instance.
|
||||
echo "Setup slave database"
|
||||
source /setup-replication.sh
|
||||
fi
|
||||
|
||||
# Running extended script or sql if provided.
|
||||
# Useful for people who extends the image.
|
||||
|
||||
echo
|
||||
for f in /docker-entrypoint-initdb.d/*; do
|
||||
case "$f" in
|
||||
*.sh) echo "$0: running $f"; . "$f" ;;
|
||||
*.sql) echo "$0: running $f"; "${psql[@]}" < "$f"; echo ;;
|
||||
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
|
||||
*) echo "$0: ignoring $f" ;;
|
||||
esac
|
||||
echo
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# If no arguments passed to entrypoint, then run postgres by default
|
||||
if [[ $# -eq 0 ]];
|
||||
|
|
|
@ -48,8 +48,8 @@ source /setup-user.sh
|
|||
# Since we now pass a comma separated list in database creation we need to search for all databases as a test
|
||||
|
||||
for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||
RESULT=`su - postgres -c "psql -l | grep -w ${db} | wc -l"`
|
||||
if [[ ! ${RESULT} == '1' ]]; then
|
||||
RESULT=`su - postgres -c "psql -t -c \"SELECT count(1) from pg_database where datname='${db}';\""`
|
||||
if [[ ${RESULT} -eq 0 ]]; then
|
||||
echo "Create db ${db}"
|
||||
su - postgres -c "createdb -O ${POSTGRES_USER} ${db}"
|
||||
for ext in $(echo ${POSTGRES_MULTIPLE_EXTENSIONS} | tr ',' ' '); do
|
||||
|
@ -67,11 +67,4 @@ done
|
|||
# This should show up in docker logs afterwards
|
||||
su - postgres -c "psql -l"
|
||||
|
||||
# Kill postgres
|
||||
PID=`cat ${PG_PID}`
|
||||
kill -TERM ${PID}
|
||||
|
||||
# Wait for background postgres main process to exit
|
||||
while [[ "$(ls -A ${PG_PID} 2>/dev/null)" ]]; do
|
||||
sleep 1
|
||||
done
|
||||
|
|
Ładowanie…
Reference in New Issue