-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·136 lines (123 loc) · 4.49 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·136 lines (123 loc) · 4.49 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
set -eo pipefail
shopt -s nullglob
OVERPASS_META=${OVERPASS_META:-no}
OVERPASS_MODE=${OVERPASS_MODE:-clone}
OVERPASS_COMPRESSION=${OVERPASS_COMPRESSION:-gz}
OVERPASS_FLUSH_SIZE=${OVERPASS_FLUSH_SIZE:-16}
OVERPASS_CLONE_SOURCE=${OVERPASS_CLONE_SOURCE:-https://dev.overpass-api.de/api_drolbr/}
# this is used by other processes, so needs to be exported
export OVERPASS_MAX_TIMEOUT=${OVERPASS_MAX_TIMEOUT:-1000s}
if [[ "$OVERPASS_META" == "attic" ]]; then
META="--keep-attic"
elif [[ "${OVERPASS_META}" == "yes" ]]; then
META="--meta"
else
META=""
fi
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh)
if [[ -x "$f" ]]; then
echo "$0: running $f"
"$f"
else
echo "$0: sourcing $f"
# shellcheck disable=SC1090 # ignore SC1090 (unable to follow file) because they are dynamically provided
. "$f"
fi
;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
initialize_db_dir() {
echo "No database directory. Initializing"
touch /db/changes.log
mkdir -p /db/diffs
}
setup_cookie_jar() {
if [[ "${USE_OAUTH_COOKIE_CLIENT}" = "yes" ]]; then
/app/venv/bin/python /app/bin/oauth_cookie_client.py -o /db/cookie.jar -s /secrets/oauth-settings.json --format netscape
# necessary to add newline at the end as oauth_cookie_client doesn't do that
echo >>/db/cookie.jar
else
echo "# Netscape HTTP Cookie File" >/db/cookie.jar
echo "${OVERPASS_COOKIE_JAR_CONTENTS}" >>/db/cookie.jar
fi
chown -R overpass:overpass /db/cookie.jar /db/changes.log /db/diffs
}
if [[ "$OVERPASS_MODE" = "clone" ]]; then
if [[ ! -f /db/init_done ]]; then
initialize_db_dir
setup_cookie_jar
(
mkdir -p /db/db &&
/app/bin/download_clone.sh --db-dir=/db/db --source="${OVERPASS_CLONE_SOURCE}" --meta="${OVERPASS_META}" &&
cp /db/db/replicate_id /db/replicate_id &&
cp -r /app/etc/rules /db/db &&
chown -R overpass:overpass /db/* &&
touch /db/init_done
) || (
echo "Failed to clone overpass repository"
exit 1
)
fi
fi
if [[ "$OVERPASS_MODE" = "init" ]]; then
if [[ ! -f /db/init_done ]]; then
initialize_db_dir
setup_cookie_jar
CURL_STATUS_CODE=$(curl -L -b /db/cookie.jar -o /db/planet.osm.bz2 -w "%{http_code}" "${OVERPASS_PLANET_URL}")
# try again until it's allowed
while [ "$CURL_STATUS_CODE" = "429" ]; do
echo "Server responded with 429 Too many requests. Trying again in 5 minutes..."
sleep 300
CURL_STATUS_CODE=$(curl -L -b /db/cookie.jar -o /db/planet.osm.bz2 -w "%{http_code}" "${OVERPASS_PLANET_URL}")
done
# for `file:///` scheme curl returns `000` HTTP status code
if [[ $CURL_STATUS_CODE = "200" || $CURL_STATUS_CODE = "000" ]]; then
(
if [[ -n "${OVERPASS_PLANET_PREPROCESS:+x}" ]]; then
echo "Running preprocessing command: ${OVERPASS_PLANET_PREPROCESS}"
eval "${OVERPASS_PLANET_PREPROCESS}"
fi &&
/app/bin/init_osm3s.sh /db/planet.osm.bz2 /db/db /app "${META}" "--version=$(osmium fileinfo -e -g data.timestamp.last /db/planet.osm.bz2) --compression-method=${OVERPASS_COMPRESSION} --map-compression-method=${OVERPASS_COMPRESSION} --flush-size=${OVERPASS_FLUSH_SIZE}" &&
echo "Database created. Now updating it." &&
cp -r /app/etc/rules /db/db &&
chown -R overpass:overpass /db/* &&
echo "Updating" &&
/app/bin/update_overpass.sh -O /db/planet.osm.bz2 &&
if [[ "${OVERPASS_USE_AREAS}" = "true" ]]; then
echo "Generating areas..." && /app/bin/osm3s_query --progress --rules --db-dir=/db/db </db/db/rules/areas.osm3s
fi &&
touch /db/init_done &&
rm /db/planet.osm.bz2 &&
chown -R overpass:overpass /db/*
) || (
echo "Failed to process planet file"
exit 1
)
elif [[ $CURL_STATUS_CODE = "403" ]]; then
echo "Access denied when downloading planet file. Check your OVERPASS_PLANET_URL and OVERPASS_COOKIE_JAR_CONTENTS or USE_OAUTH_COOKIE_CLIENT"
cat /db/cookie.jar
exit 1
else
echo "Failed to download planet file. HTTP status code: ${CURL_STATUS_CODE}"
cat /db/planet.osm.bz2
exit 1
fi
fi
fi
if [[ "$OVERPASS_MODE" = "init" || "$OVERPASS_MODE" = "clone" ]]; then
if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then
echo "Overpass container ready to receive requests"
else
echo "Overpass container initialization complete. Exiting."
exit 0
fi
fi
# shellcheck disable=SC2016 # ignore SC2016 (variables within single quotes) as this is exactly what we want to do here
envsubst '${OVERPASS_MAX_TIMEOUT}' </etc/nginx/nginx.conf.template >/etc/nginx/nginx.conf
echo "Starting supervisord process"
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf