use docker for postgis

This commit is contained in:
Motiejus Jakštys 2020-12-15 23:49:25 +02:00
parent b9e6e6dd5d
commit a0469cf9bc
2 changed files with 40 additions and 24 deletions

View File

@ -1,5 +1,8 @@
BOUNDS = xmin=582700 ymin=6060750 xmax=584830 ymax=6062750 #uzupis
XYZ = $(patsubst %.zip,%.xyz,$(wildcard DTM_*.zip)) #BOUNDS = xmin=582700 ymin=6060750 xmax=584830 ymax=6062750
#krekenava
BOUNDS = xmin=493674 ymin=6146103 xmax=518869 ymax=6171741
XYZ = $(patsubst %.zip,%.xyz,$(wildcard *.zip))
SORT = sort -n -k2 -k1 -t, SORT = sort -n -k2 -k1 -t,
.PHONY: all .PHONY: all
@ -40,6 +43,5 @@ all.xyz: $(XYZ)
$(SORT) > $@ $(SORT) > $@
db/.ready: managedb db/.ready: managedb
-./managedb stop; rm -fr db ./managedb start
./managedb init
touch $@ touch $@

View File

@ -1,32 +1,46 @@
#!/bin/bash #!/bin/bash
PATH=$PATH:/usr/lib/postgresql/12/bin _psql() {
case ${1:-} in env \
init) PGPASSWORD=osm \
mkdir -p db && initdb db
mkdir -p db/wal
sed -i "s/.*unix_socket_dir.*/unix_socket_directories = '.\/wal'/" \
db/postgresql.conf
pg_ctl -D db -l db/logfile start
export PGHOST=127.0.0.1
psql postgres -c 'CREATE ROLE osm WITH SUPERUSER LOGIN'
psql postgres -c 'CREATE DATABASE osm'
psql osm osm -c 'CREATE EXTENSION postgis'
;;
start)
pg_ctl -D db -l db/logfile start
;;
stop)
pg_ctl -D db -l db/logfile stop
;;
"" | --)
[[ $# -gt 1 ]] && shift
exec env \
PGHOST=127.0.0.1 \ PGHOST=127.0.0.1 \
PGUSER=osm \ PGUSER=osm \
PGDATABASE=osm \ PGDATABASE=osm \
psql "$@" psql "$@"
}
_wait_for_postgres() {
>&2 echo -n "Waiting for postgres"
for _ in $(seq 240); do
if _psql -qc '\q' 2>/dev/null; then
>&2 echo " up"
exit 0
fi
>&2 echo -n .
sleep 1
done
>&2 echo " down"
exit 1
}
name=postgis-contours
case ${1:-} in
start)
docker run -d --rm \
-p 5432:5432 \
-e POSTGRES_DBNAME=osm \
-e POSTGRES_USER=osm \
-e POSTGRES_PASSWORD=osm \
--name "$name" \
postgis/postgis:13-3.0-alpine
_wait_for_postgres
;;
stop)
docker stop "$name"
;;
"" | --)
[[ $# -gt 1 ]] && shift
_psql "$@"
;; ;;
*) *)
>&2 echo "Unknown command: '$*'" >&2 echo "Unknown command: '$*'"