-
Notifications
You must be signed in to change notification settings - Fork 20
/
docker-startup.sh
executable file
·92 lines (82 loc) · 2.62 KB
/
docker-startup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
# This script is used to start the import of kosmtik containers for the Docker development environment.
# You can read details about that in SETUP.md
# Testing if database is ready
i=1
MAXCOUNT=60
echo "Waiting for PostgreSQL to be running"
while [ $i -le $MAXCOUNT ]
do
pg_isready -q && echo "PostgreSQL running" && break
sleep 2
i=$((i+1))
done
test $i -gt $MAXCOUNT && echo "Timeout while waiting for PostgreSQL to be running"
case "$1" in
import)
# Creating default database
psql -c "SELECT 1 FROM pg_database WHERE datname = 'gis';" | grep -q 1 || createdb gis && \
psql -d gis -c 'CREATE EXTENSION IF NOT EXISTS postgis;' && \
psql -d gis -c 'CREATE EXTENSION IF NOT EXISTS hstore;'
# Creating default import settings file editable by user and passing values for osm2pgsql
if [ ! -e ".env" ]; then
cat > .env <<EOF
# Environment settings for importing to a Docker container database
PG_WORK_MEM=${PG_WORK_MEM:-16MB}
PG_MAINTENANCE_WORK_MEM=${PG_MAINTENANCE_WORK_MEM:-256MB}
OSM2PGSQL_CACHE=${OSM2PGSQL_CACHE:-512}
OSM2PGSQL_NUMPROC=${OSM2PGSQL_NUMPROC:-1}
OSM2PGSQL_DATAFILE=${OSM2PGSQL_DATAFILE:-data.osm.pbf}
EXTERNAL_DATA_SCRIPT_FLAGS=${EXTERNAL_DATA_SCRIPT_FLAGS:-}
EOF
chmod a+rw .env
export OSM2PGSQL_CACHE=${OSM2PGSQL_CACHE:-512}
export OSM2PGSQL_NUMPROC=${OSM2PGSQL_NUMPROC:-1}
export OSM2PGSQL_DATAFILE=${OSM2PGSQL_DATAFILE:-data.osm.pbf}
fi
osmium tags-filter \
-o filtered.osm.pbf \
"$OSM2PGSQL_DATAFILE" \
nwr/railway \
nwr/disused:railway \
nwr/abandoned:railway \
nwr/razed:railway \
nwr/construction:railway \
nwr/proposed:railway \
n/public_transport=stop_position \
nwr/public_transport=platform \
r/route=train \
r/route=tram \
r/route=light_rail \
r/route=subway
# Importing data to a database
osm2pgsql \
--create \
--database gis \
--hstore \
--slim \
--merc \
--style setup/openstreetmap-carto.style \
--tag-transform setup/openstreetmap-carto.lua \
--multi-geometry \
--cache $OSM2PGSQL_CACHE \
--number-processes $OSM2PGSQL_NUMPROC \
filtered.osm.pbf
# Post processing imported data
psql -d gis -f sql/osm_carto_views.sql && \
psql -d gis -f sql/functions.sql && \
psql -d gis -f sql/get_station_importance.sql
;;
kosmtik)
# Creating default Kosmtik settings file
if [ ! -e ".kosmtik-config.yml" ]; then
cp /tmp/.kosmtik-config.yml .kosmtik-config.yml
fi
export KOSMTIK_CONFIGPATH=".kosmtik-config.yml"
# Second argument is the kosmtik options
shift
# Starting Kosmtik
exec kosmtik serve --host 0.0.0.0 "$@"
# It needs Ctrl+C to be interrupted
;;
esac