-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·38 lines (30 loc) · 973 Bytes
/
docker-entrypoint.sh
File metadata and controls
executable file
·38 lines (30 loc) · 973 Bytes
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
#!/bin/sh
CONFIG_FILE_PATH="/build/static/env-config.js"
# Recreate config file
rm -rf $CONFIG_FILE_PATH
touch $CONFIG_FILE_PATH
# Add assignment
echo "window.react_env = {" > $CONFIG_FILE_PATH
VARIABLES=$(printenv | grep REACT_APP)
# Read each line in .env file
# Each line represents key=value pairs
while read -r line || [ -n "$line" ];
do
# Split env variables by character `=`
if printf '%s\n' "$line" | grep -q -e '='; then
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
fi
# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
if [ -z $value ]; then
value=${varvalue}
fi
# Append configuration property to JS file
echo " $varname: \"$value\"," >> $CONFIG_FILE_PATH
done << EOF
$VARIABLES
EOF
echo "}" >> $CONFIG_FILE_PATH
nginx -g 'daemon off;'