nginx-vhosts rewrite
This commit is contained in:
@@ -258,11 +258,6 @@ get_app_container_ids() {
|
||||
echo $DOKKU_CIDS
|
||||
}
|
||||
|
||||
get_dockerfile_exposed_port() {
|
||||
local DOCKERFILE_PORT=$(grep "^EXPOSE \+[[:digit:]]\+\(\/tcp\)\? *$" $1 | head -1 | sed 's/EXPOSE \+\([[:digit:]]\+\)\(\/tcp\)\?.*/\1/' || true)
|
||||
echo "$DOCKERFILE_PORT"
|
||||
}
|
||||
|
||||
get_app_running_container_ids() {
|
||||
local APP=$1
|
||||
verify_app_name $APP
|
||||
@@ -441,3 +436,166 @@ get_ipv6_regex() {
|
||||
# Fixes using a wildcard dns service such as xip.io which allows for *.<ip address>.xip.io
|
||||
echo "${RE_IPV6}\$"
|
||||
}
|
||||
|
||||
get_global_vhost() {
|
||||
local GLOBAL_VHOST_FILE="$DOKKU_ROOT/VHOST"
|
||||
[[ -f "$GLOBAL_VHOST_FILE" ]] && local GLOBAL_VHOST=$(< "$GLOBAL_VHOST_FILE")
|
||||
echo $GLOBAL_VHOST
|
||||
}
|
||||
|
||||
is_global_vhost_enabled() {
|
||||
local desc="returns true if we have a valid global vhost set; otherwise returns false"
|
||||
local GLOBAL_VHOST=$(get_global_vhost)
|
||||
local GLOBAL_VHOST_ENABLED=true
|
||||
local RE_IPV4="$(get_ipv4_regex)"
|
||||
local RE_IPV6="$(get_ipv6_regex)"
|
||||
|
||||
if [[ -z "$GLOBAL_VHOST" ]] || [[ "$GLOBAL_VHOST" =~ $RE_IPV4 ]] || [[ "$GLOBAL_VHOST" =~ $RE_IPV6 ]]; then
|
||||
local GLOBAL_VHOST_ENABLED=false
|
||||
fi
|
||||
echo $GLOBAL_VHOST_ENABLED
|
||||
}
|
||||
|
||||
is_app_vhost_enabled() {
|
||||
local desc="returns true or false if vhost support is enabled for a given application"
|
||||
local APP=$1; verify_app_name $APP
|
||||
|
||||
local NO_VHOST=$(config_get $APP NO_VHOST)
|
||||
local APP_VHOST_ENABLED=true
|
||||
|
||||
if [[ "$NO_VHOST" == "1" ]]; then
|
||||
local APP_VHOST_ENABLED=false
|
||||
fi
|
||||
|
||||
echo $APP_VHOST_ENABLED
|
||||
}
|
||||
|
||||
disable_app_vhost() {
|
||||
local desc="disable vhost support for given application"
|
||||
local APP=$1; verify_app_name $APP
|
||||
local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST"
|
||||
local APP_URLS_FILE="$DOKKU_ROOT/$APP/URLS"
|
||||
local DOKKU_NGINX_PORT=$(config_get $APP DOKKU_NGINX_PORT)
|
||||
local DOKKU_NGINX_SSL_PORT=$(config_get $APP DOKKU_NGINX_SSL_PORT)
|
||||
|
||||
if [[ -f "$APP_VHOST_FILE" ]]; then
|
||||
dokku_log_info1 "VHOST support disabled, deleting $APP/VHOST"
|
||||
rm "$APP_VHOST_FILE"
|
||||
fi
|
||||
if [[ -f "$APP_URLS_FILE" ]]; then
|
||||
dokku_log_info1 "VHOST support disabled, deleting $APP/URLS"
|
||||
rm "$APP_URLS_FILE"
|
||||
fi
|
||||
if [[ "$DOKKU_NGINX_PORT" == "80" ]]; then
|
||||
config_unset --no-restart $APP DOKKU_NGINX_PORT
|
||||
fi
|
||||
if [[ "$DOKKU_NGINX_SSL_PORT" == "443" ]]; then
|
||||
config_unset --no-restart $APP DOKKU_NGINX_SSL_PORT
|
||||
fi
|
||||
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
config_set $CONFIG_SET_ARGS $APP NO_VHOST=1
|
||||
}
|
||||
|
||||
enable_app_vhost() {
|
||||
local desc="enable vhost support for given application"
|
||||
local APP=$1; verify_app_name $APP
|
||||
|
||||
config_unset --no-restart $APP DOKKU_NGINX_PORT DOKKU_NGINX_SSL_PORT
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
config_set $CONFIG_SET_ARGS $APP NO_VHOST=0
|
||||
}
|
||||
|
||||
get_dockerfile_exposed_ports() {
|
||||
local DOCKERFILE_PORTS=$(egrep "^EXPOSE " $1 | awk '{ print $2 }' | xargs) || true
|
||||
echo "$DOCKERFILE_PORTS"
|
||||
}
|
||||
|
||||
get_app_raw_tcp_ports() {
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local DOCKERFILE_PORTS="$(config_get $APP DOKKU_DOCKERFILE_PORTS)"
|
||||
for p in $DOCKERFILE_PORTS; do
|
||||
if [[ ! "$p" =~ .*udp.* ]]; then
|
||||
p=${p//\/tcp}
|
||||
raw_tcp_ports+="$p "
|
||||
fi
|
||||
done
|
||||
raw_tcp_ports="$(echo $raw_tcp_ports| xargs)"
|
||||
echo "$raw_tcp_ports"
|
||||
}
|
||||
|
||||
get_container_ports() {
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local APP_CIDS="$(get_app_container_ids $APP)"
|
||||
local cid
|
||||
|
||||
for cid in $APP_CIDS; do
|
||||
local container_ports="$(docker port $cid | awk '{ print $3 "->" $1}' | awk -F ":" '{ print $2 }')"
|
||||
done
|
||||
|
||||
echo $container_ports
|
||||
}
|
||||
|
||||
get_app_urls() {
|
||||
local APP="$2"; verify_app_name "$APP"
|
||||
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports $APP)"
|
||||
local URLS_FILE="$DOKKU_ROOT/$APP/URLS"
|
||||
|
||||
if [[ -s "$URLS_FILE" ]]; then
|
||||
local app_urls="$(egrep -v "^#" $URLS_FILE)"
|
||||
if [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
for url in ${app_urls[*]}; do
|
||||
for p in $RAW_TCP_PORTS; do
|
||||
local port_urls+="$url:$p "
|
||||
done
|
||||
done
|
||||
local port_urls="$(echo $port_urls| xargs)"
|
||||
fi
|
||||
local URLS=${port_urls:=$app_urls}
|
||||
case "$1" in
|
||||
url)
|
||||
echo "$URLS" | tr ' ' '\n' | head -n1
|
||||
;;
|
||||
urls)
|
||||
echo "$URLS" | tr ' ' '\n'
|
||||
;;
|
||||
esac
|
||||
else
|
||||
local SCHEME="http"; local SSL="$DOKKU_ROOT/$APP/tls"
|
||||
local DOKKU_NGINX_PORT=$(config_get $APP DOKKU_NGINX_PORT || true)
|
||||
local DOKKU_NGINX_SSL_PORT=$(config_get $APP DOKKU_NGINX_SSL_PORT || true)
|
||||
|
||||
if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]]; then
|
||||
local SCHEME="https"
|
||||
fi
|
||||
|
||||
if [[ "$(is_app_proxy_enabled $APP)" == "false" ]]; then
|
||||
if [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
local APP_CONTAINER_PORTS="$(get_container_ports $APP)"
|
||||
local app_port
|
||||
for app_port in $APP_CONTAINER_PORTS; do
|
||||
echo "$(< "$DOKKU_ROOT/HOSTNAME"):$app_port (container)"
|
||||
done
|
||||
else
|
||||
shopt -s nullglob
|
||||
for PORT_FILE in $DOKKU_ROOT/$APP/PORT.*; do
|
||||
echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$PORT_FILE") (container)"
|
||||
done
|
||||
shopt -u nullglob
|
||||
fi
|
||||
elif [[ -n "$DOKKU_NGINX_PORT" ]] || [[ -n "$DOKKU_NGINX_SSL_PORT" ]]; then
|
||||
if [[ -n "$DOKKU_NGINX_PORT" ]];then
|
||||
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$DOKKU_NGINX_PORT ($(get_app_proxy_type $APP))"
|
||||
fi
|
||||
if [[ -n "$DOKKU_NGINX_SSL_PORT" ]]; then
|
||||
echo "https://$(< "$DOKKU_ROOT/HOSTNAME"):$DOKKU_NGINX_SSL_PORT ($(get_app_proxy_type $APP)-ssl)"
|
||||
fi
|
||||
elif [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
for p in $RAW_TCP_PORTS; do
|
||||
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$p"
|
||||
done
|
||||
else
|
||||
echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku core common plugin"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
[plugin.config]
|
||||
|
||||
Reference in New Issue
Block a user