Skip to content

Commit a454895

Browse files
authored
Merge pull request #209 from rcthomas/add-file-env-to-entrypoint
Add file_env function to set the token env var
2 parents aaed713 + 16ad271 commit a454895

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

chp-docker-entrypoint

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
# Wrapper around CHP entrypoint that changes defaults slightly
33
# to be more appropriate when run in a container.
44

5+
# usage: file_env VAR [DEFAULT]
6+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
7+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
8+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
9+
file_env() {
10+
var=$1
11+
file_var="${var}_FILE"
12+
var_value=$(printenv $var || true)
13+
file_var_value=$(printenv $file_var || true)
14+
default_value=$2
15+
16+
if [ -n "$var_value" -a -n "$file_var_value" ]; then
17+
echo >&2 "error: both $var and $file_var are set (but are exclusive)"
18+
exit 1
19+
fi
20+
21+
if [ -z "${var_value}" ]; then
22+
if [ -z "${file_var_value}" ]; then
23+
export "${var}"="${default_value}"
24+
else
25+
export "${var}"="$(cat $file_var_value)"
26+
fi
27+
fi
28+
29+
unset "$file_var"
30+
}
31+
32+
file_env 'CONFIGPROXY_AUTH_TOKEN'
33+
534
case "$@" in
635
*"--api-ip"*)
736
break;;

0 commit comments

Comments
 (0)