forked from JamesSaxon/routing-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-build-and-query.sh
executable file
·67 lines (44 loc) · 1.59 KB
/
docker-build-and-query.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
#!/usr/bin/env bash
set -e
if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
if [ "$1" = 'postgres' ] && [ ! -v $GEOID ]; then
s3cmd get s3://jsaxon-routing/osm/${GEOID}.pbf
osmium cat ${GEOID}.pbf -f osm -o scripts/input/${GEOID}.osm
s3cmd get s3://jsaxon-routing/locations/${GEOID}.csv scripts/input/locations.csv
fi
# allow the container to be started with `--user`
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA"
chmod 700 "$PGDATA"
mkdir -p /var/run/postgresql
chown -R postgres /var/run/postgresql
chmod 775 /var/run/postgresql
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
if [ "$POSTGRES_INITDB_WALDIR" ]; then
mkdir -p "$POSTGRES_INITDB_WALDIR"
chown -R postgres "$POSTGRES_INITDB_WALDIR"
chmod 700 "$POSTGRES_INITDB_WALDIR"
fi
gosu postgres /start-postgres-db.sh
# Now run the user scripts.
psql+=(psql -U "${POSTGRES_USER:-postgres}" -d "$POSTGRES_DB" )
for f in /scripts/build/* /scripts/run/01_cost_matrix.sh ; do
case "$f" in
*.sh) echo "Running user script :: $f"; . "$f" ;;
*.sql) echo "Running user script :: $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "Running user script :: $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "Skipping $f -- sql/sh only!!" ;;
esac
echo
done
gosu postgres /stop-postgres-db.sh
if [ ! -v $GEOID ]; then
s3cmd put scripts/output/cost_matrix.csv s3://jsaxon-routing/output/${GEOID}.csv
fi
exit 0
fi
echo "Running in pass-through mode: $@"
exec "$@"