forked from cyclosm/cyclosm-cartocss-style
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-startup.sh
74 lines (63 loc) · 2.03 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
#!/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 DOCKER.md
# Testing if database is ready
i=1
MAXCOUNT=60
DB_NAME=osm
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 = '$DB_NAME';" | grep -q 1 || createdb $DB_NAME && \
psql -d $DB_NAME -c 'CREATE EXTENSION IF NOT EXISTS postgis;' && \
psql -d $DB_NAME -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}
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
# Importing data to a database
osm2pgsql \
--cache $OSM2PGSQL_CACHE \
--number-processes $OSM2PGSQL_NUMPROC \
--hstore \
--database $DB_NAME \
--slim \
-c \
-G \
--drop \
$OSM2PGSQL_DATAFILE
# Run cyclosm-specific sql script
psql --dbname=$DB_NAME --file=views.sql
;;
kosmtik)
# Downloading needed shapefiles
# python scripts/get-shapefiles.py -n
# 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"
# Starting Kosmtik
kosmtik serve project.mml --host 0.0.0.0
# It needs Ctrl+C to be interrupted
;;
esac