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 PGHOST=127.0.0.1 \
mkdir -p db/wal PGUSER=osm \
sed -i "s/.*unix_socket_dir.*/unix_socket_directories = '.\/wal'/" \ PGDATABASE=osm \
db/postgresql.conf psql "$@"
pg_ctl -D db -l db/logfile start }
export PGHOST=127.0.0.1 _wait_for_postgres() {
psql postgres -c 'CREATE ROLE osm WITH SUPERUSER LOGIN' >&2 echo -n "Waiting for postgres"
psql postgres -c 'CREATE DATABASE osm' for _ in $(seq 240); do
psql osm osm -c 'CREATE EXTENSION postgis' 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) start)
pg_ctl -D db -l db/logfile 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) stop)
pg_ctl -D db -l db/logfile stop docker stop "$name"
;; ;;
"" | --) "" | --)
[[ $# -gt 1 ]] && shift [[ $# -gt 1 ]] && shift
exec env \ _psql "$@"
PGHOST=127.0.0.1 \
PGUSER=osm \
PGDATABASE=osm \
psql "$@"
;; ;;
*) *)
>&2 echo "Unknown command: '$*'" >&2 echo "Unknown command: '$*'"