-
Notifications
You must be signed in to change notification settings - Fork 12
/
docker_entrypoint.sh
41 lines (35 loc) · 1.48 KB
/
docker_entrypoint.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
#!/usr/bin/env bash
set -o pipefail -o errexit -o nounset
: "${API_ENDPOINT:?'This environment variable is required'}"
if [ -z "${PORT:-}" ]; then
export PORT=80
fi
if [ -n "${PROXY_TIMEOUT_IN_SECS:-}" ]; then
export PROXY_TIMEOUT_DIRECTIVES="proxy_connect_timeout ${PROXY_TIMEOUT_IN_SECS}s; proxy_send_timeout ${PROXY_TIMEOUT_IN_SECS}s; proxy_read_timeout ${PROXY_TIMEOUT_IN_SECS}s; send_timeout ${PROXY_TIMEOUT_IN_SECS}s;"
fi
# Ensure there is no default nginx configuration listening on port 80,
# as this prevents the dyno to start in Heroku:
rm /etc/nginx/conf.d/default.conf || true
# Inject env variables in hesperides.conf:
envsubst </etc/nginx/conf.d/hesperides.conf.template >/etc/nginx/conf.d/hesperides.conf
# Inject env variables in index.html:
envsubst </usr/share/nginx/html/index.html.template >/usr/share/nginx/html/index.html
# Ensure all the required JS files are present:
grep -F '<script ' /usr/share/nginx/html/index.html | sed 's/.*src="\([^"]*\)".*/\1/' | while read js_file; do
if ! [ -s /usr/share/nginx/html/$js_file ]; then
echo "$js_file is missing or empty"
exit 1
fi
done
# Ensure all the required CSS files are present:
grep -F '<link rel="stylesheet"' /usr/share/nginx/html/index.html | sed 's/.*href="\([^"]*\)".*/\1/' | while read css_file; do
if ! [ -s /usr/share/nginx/html/$css_file ]; then
echo "$css_file is missing or empty"
exit 1
fi
done
if [ $# -gt 0 ]; then
exec "$@"
else
exec nginx -g 'daemon off;'
fi