forked from satishweb/docker-doh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint
executable file
·54 lines (45 loc) · 1.71 KB
/
docker-entrypoint
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
#!/bin/bash
# Author: Satish Gaikwad <[email protected]>
set -e
if [ -f /run/secrets/DEBUG ]; then
export DEBUG=$(cat $i)
fi
if [ "$DEBUG" = "1" ]; then
set -x
BASH_CMD_FLAGS='-x'
fi
DOH_CONFIG_SAMPLE_FILE=/server/doh-server.sample.conf
DOH_CONFIG_FILE=/server/doh-server.conf
DOH_CONFIG_CUSTOM_FILE=/server-custom/doh-server.conf
printf "|---------------------------------------------------------------------------------------------\n";
printf "| Starting DNS Over HTTP Service \n"
if [ -f "${DOH_CONFIG_CUSTOM_FILE}" ]; then
printf "| ENTRYPOINT: \033[0;31mUse custom server config...\033[0m\n"
cat "${DOH_CONFIG_CUSTOM_FILE}" > "${DOH_CONFIG_FILE}"
else
# Load env vars
printf "| ENTRYPOINT: \033[0;31mLoading docker secrets if found...\033[0m\n"
for i in $(env|grep '/run/secrets'); do
varName=$(echo $i|awk -F '[=]' '{print $1}'|sed 's/_FILE//')
varFile=$(echo $i|awk -F '[=]' '{print $2}')
exportCmd="export $varName=$(cat $varFile)"
echo "${exportCmd}" >> /etc/profile
eval "${exportCmd}"
printf "| ENTRYPOINT: Exporting var: $varName\n"
done
# lets generate config file by replacing all variables inside of it.
TMP_FILE=/tmp/doh-server.conf
cp ${DOH_CONFIG_SAMPLE_FILE} ${TMP_FILE}
DOLLAR='$' envsubst < /tmp/doh-server.conf > ${DOH_CONFIG_FILE}
rm ${TMP_FILE}
fi
# Check if app-config is present
if [ -f /app-config ]; then
# We expect that app-config handles the launch of app command
echo "| ENTRYPOINT: Executing app-config..."
. /app-config "$@"
else
# Let default CMD run if app-config is missing
echo "| ENTRYPOINT: app-config was not available, running given parameters or default CMD..."
exec $@
fi