-
Notifications
You must be signed in to change notification settings - Fork 7
/
docker-entrypoint.sh
executable file
·50 lines (41 loc) · 1.46 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
42
43
44
45
46
47
48
49
50
#!/bin/ash -e
mkdir -p /run/nginx/
rm -rf /run/nginx/nginx.pid
if [ "${#}" -eq 0 ] || [ "${1}" == "test" ]; then
echo "Starting docker-nginx"
j2 --undefined /code/templates/nginx.conf.j2 > /etc/nginx/nginx.conf
j2 --undefined /code/templates/site.conf.j2 > /etc/nginx/conf.d/site.conf
if [ "${UWSGI}" == "true" ]; then
cp /code/conf/uwsgi_params /etc/nginx/uwsgi_params
fi
if [ "${MAINTENANCE}" == "true" ]; then
cp -vr /code/html /var/www/
fi
if [ ! -z ${BASIC_AUTH_ALL} ] || [ ! -z ${BASIC_AUTH_LOCATIONS} ]; then
if [ ! -z ${BASIC_AUTH_USER} ] && [ ! -z ${AWS_SM_PATH} ] && [ -z ${BASIC_AUTH_PASS} ]; then
BASIC_AUTH_PASS=$(aws_sm --path "${AWS_SM_PATH}" --key "${AWS_SM_KEY:-BASIC_AUTH_PASS}")
elif [ -z ${BASIC_AUTH_USER} ] || [ -z ${BASIC_AUTH_PASS} ]; then
echo "Missing basic auth credentials."
echo "Set BASIC_AUTH_USER and BASIC_AUTH_PASS or BASIC_AUTH_USER and AWS_SM_PATH, AWS_DEFAULT_REGION (and optionally AWS_SM_KEY)."
exit 2
fi
echo "${BASIC_AUTH_USER}:$(openssl passwd -crypt ${BASIC_AUTH_PASS})" > /etc/nginx/htpasswd
fi
if [[ "${DEV_SSL_CERT}" == "true" ]]; then
cp -rp /code/certs /etc/nginx
fi
if [[ "${DEBUG}" == "true" ]]; then
for i in /etc/nginx/nginx.conf $(ls -d /etc/nginx/conf.d/*); do
printf "\n# ${i}:"
cat ${i}
done
fi
if [ "${1}" == "test" ]; then
nginx -t
else
echo "Starting nginx"
exec nginx -g 'daemon off;'
fi
else
exec "${@}"
fi