-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocker-entrypoint
executable file
·59 lines (50 loc) · 1.88 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
55
56
57
58
59
#!/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
printf "|---------------------------------------------------------------------------------------------\n";
printf "| Starting DNS Over HTTP Service \n"
# 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
# If UPSTREAM_DNS_SERVER contains a comma (i.e., multiple servers are provided)
if [[ "$UPSTREAM_DNS_SERVER" == *","* ]]; then
# Convert the comma-separated list into a valid array for the config file
upstream_servers=$(echo "$UPSTREAM_DNS_SERVER" | sed 's/,/","/g')
upstream_servers="[\"$upstream_servers\"]"
else
# If only a single DNS server is provided, use it as before
upstream_servers="[\"$UPSTREAM_DNS_SERVER\"]"
fi
export upstream_servers
# 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}
# 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