-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathdocker-entrypoint.sh
executable file
·92 lines (85 loc) · 2.13 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
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
# echo a string, handling different types
safe_echo() {
# $1 = value
if [ -z "$1" ]; then
echo -n "null"
elif printf '%s\n' "$1" | grep -qE '\n.+\n$'; then
echo -n "\`$1\`"
else
echo -n "'$1'"
fi
}
# handle boolean
bool() {
# $1 = value
case "$1" in
true | TRUE | yes | t | True)
echo -n true ;;
false | FALSE | no | n | False)
echo -n false ;;
*)
echo "Err: Unknown boolean value \"$1\"" >&2
exit 1 ;;
esac
}
# handle array values
array() {
# $1 = value
# $2 = arraytype
if [ -z "$1" ]; then
echo -n "[]"
else
case "$2" in
string)
echo -n "['$(echo "$1" | sed "s/,/', '/g")']"
;;
*)
echo -n "[$1]"
;;
esac
fi
}
# handle object values
object() {
# $1 = value
if [ -z "$1" ]; then
echo -n "null"
else
echo -n "$1"
fi
}
config_schema=$(cat /etc/nginx/conf.d/config.schema.json)
# Iterate over environment variables with "SB_" prefix
env -0 | cut -f1 -d= | tr '\0' '\n' | grep "^SB_" | {
echo "window.STAC_BROWSER_CONFIG = {"
while IFS='=' read -r name; do
# Strip the prefix
argname="${name#SB_}"
# Read the variable's value
value="$(eval "echo \"\$$name\"")"
# Get the argument type from the schema
argtype="$(echo "$config_schema" | jq -r ".properties.$argname.type[0]")"
arraytype="$(echo "$config_schema" | jq -r ".properties.$argname.items.type[0]")"
# Encode key/value
echo -n " $argname: "
case "$argtype" in
string)
safe_echo "$value"
;;
boolean)
bool "$value"
;;
integer | number | object)
object "$value"
;;
array)
array "$value" "$arraytype"
;;
*)
safe_echo "$value"
;;
esac
echo ","
done
echo "}"
} > /usr/share/nginx/html/config.js