-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart-nginx.sh
executable file
·58 lines (53 loc) · 2.32 KB
/
start-nginx.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
#!/bin/sh
echo "setting nginx conf ..."
echo "DEBUG": $DEBUG
echo "BUILD": $BUILD
echo "ENV_PREFIX": $ENV_PREFIX
echo "WHITE_LIST": $WHITE_LIST
echo "WHITE_LIST_IP": $WHITE_LIST_IP
echo "APP_VERSION": $APP_VERSION
echo "APP_WORKDIR": $APP_WORKDIR
echo "APP_BASENAME": $APP_BASENAME
echo "API_PLACEHOLDER": $API_PLACEHOLDER
echo "API_PLACEHOLDER_1": $API_PLACEHOLDER_1
echo "API_PLACEHOLDER_2": $API_PLACEHOLDER_2
echo "API_PLACEHOLDER_3": $API_PLACEHOLDER_3
echo "API_PLACEHOLDER_4": $API_PLACEHOLDER_4
echo "API_PLACEHOLDER_5": $API_PLACEHOLDER_5
echo "API_GATEWAY": $API_GATEWAY
echo "API_GATEWAY_1": $API_GATEWAY_1
echo "API_GATEWAY_2": $API_GATEWAY_2
echo "API_GATEWAY_3": $API_GATEWAY_3
echo "API_GATEWAY_4": $API_GATEWAY_4
echo "API_GATEWAY_5": $API_GATEWAY_5
echo "CLIENT_BODY_TIMEOUT": $CLIENT_BODY_TIMEOUT
echo "CLIENT_HEADER_TIMEOUT": $CLIENT_HEADER_TIMEOUT
echo "CLIENT_MAX_BODY_SIZE": $CLIENT_MAX_BODY_SIZE
## Replace env for nginx conf
envsubst '$DEBUG $BUILD $WHITE_LIST $WHITE_LIST_IP $APP_VERSION $APP_WORKDIR $APP_BASENAME $API_PLACEHOLDER $API_GATEWAY $API_PLACEHOLDER_1 $API_GATEWAY_1 $API_PLACEHOLDER_2 $API_GATEWAY_2 $API_PLACEHOLDER_3 $API_GATEWAY_3 $API_PLACEHOLDER_4 $API_GATEWAY_4 $API_PLACEHOLDER_5 $API_GATEWAY_5 $CLIENT_BODY_TIMEOUT $CLIENT_HEADER_TIMEOUT $CLIENT_MAX_BODY_SIZE' < /etc/nginx/conf.d/app.conf.template > /etc/nginx/conf.d/default.conf
## Delete white list config if white list feature off
if [ ${WHITE_LIST} = 'off' ]; then
# delete white list config
sed -i '/^[ ]*\#[ ]*BEGIN_CONFIG_WHEN_WHITE_LIST_ON/,/^[ ]*\#[ ]*END_CONFIG_WHEN_WHITE_LIST_ON/{d;};' /etc/nginx/conf.d/default.conf
fi
## inject runtime env into *.html
ENV_SUBS=$(echo $(env | cut -d= -f1 | grep "^${ENV_PREFIX}" | sed -e 's/^/\$/'))
echo "inject runtime environments ..."
### Recreate env-runtime file
rm -rf ./env-runtime.js
touch ./env-runtime.js
### Add assignment
echo "window._runtime_ = {" >> ./env-runtime.js
for e in $ENV_SUBS; do
# Append configuration property to JS file
eName=$(echo $e | sed -e 's/^\$//');
value=$(echo $(eval echo "\$$eName"));
echo " $eName: \"$value\"," >> ./env-runtime.js
done
echo "}" >> ./env-runtime.js
sed -i -e 's/<script src="\/env-runtime.js"><\/script>//g' *.html
sed -i -e 's/<body>/&<script src="\/env-runtime.js"><\/script>/' *.html
## Start nginx
echo "start nginx"
nginx -g 'daemon off;'
exec "$@"