forked from firecow/cloudflared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.entrypoint
executable file
·57 lines (46 loc) · 1.91 KB
/
Dockerfile.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
#!/bin/bash
set -eo pipefail
if [ "$1" = "cloudflared" ] && [ "$2" = "tunnel" ]; then
# Prevent message about missing config file.
echo "---" > /etc/cloudflared/config.yml
if [ -n "${TUNNEL_NAME}" ]; then
>&2 echo "You cannot use TUNNEL_NAME or --name with firecow/cloudflared image, its auto generated" && exit 1
fi
if [ -n "${TUNNEL_FORCE_PROVISIONING_DNS}" ]; then
>&2 echo "You cannot use TUNNEL_FORCE_PROVISIONING_DNS with firecow/cloudflared image, its determined via route dns command" && exit 1
fi
if [ -z "${TUNNEL_HOSTNAME}" ]; then
>&2 echo "You need to specify TUNNEL_HOSTNAME" && exit 1
fi
if [ -z "${TUNNEL_URL}" ]; then
>&2 echo "You need to specify TUNNEL_URL" && exit 1
fi
if [ -z "${TUNNEL_TRANSPORT_LOGLEVEL}" ]; then
export TUNNEL_TRANSPORT_LOGLEVEL=fatal
fi
if [ -z "${TUNNEL_LOGLEVEL}" ]; then
export TUNNEL_LOGLEVEL=fatal
fi
# function that prints info message, if TUNNEL_LOG_LEVEL is DEBUG or INFO
function printInfo {
if [ ${TUNNEL_LOGLEVEL,,} != 'info' ] && [ ${TUNNEL_LOGLEVEL,,} != 'debug' ]; then return 0; fi
echo "${1}"
}
export TUNNEL_FORCE_PROVISIONING_DNS='false'
export TUNNEL_HOSTNAME=${TUNNEL_HOSTNAME/https:\/\//}
export TUNNEL_NAME=${TUNNEL_NAME:-$TUNNEL_HOSTNAME}
EXISTING_TUNNELS_JSON=$(cloudflared tunnel list --name "${TUNNEL_NAME}" --output json)
if [ "${EXISTING_TUNNELS_JSON}" != "[]" ]; then
printInfo "Deleting existing tunnel '${TUNNEL_NAME}'"
cloudflared tunnel delete "${TUNNEL_NAME}"
else
printInfo "No existing tunnel found"
fi
printInfo "Creating new tunnel '${TUNNEL_NAME}'"
cloudflared tunnel create "${TUNNEL_NAME}" 1> /dev/null
cloudflared tunnel route dns --overwrite-dns "${TUNNEL_NAME}" "${TUNNEL_HOSTNAME}"
unset TUNNEL_HOSTNAME
exec "cloudflared" "tunnel"
else
exec "$@"
fi