From 371949f4ecb248cb2434427c716cbcdd6e374790 Mon Sep 17 00:00:00 2001 From: Mirko Geissler Date: Wed, 29 Jun 2016 15:30:20 +0200 Subject: [PATCH] Create default app domain for every global domain --- plugins/common/functions | 18 ++++++------- plugins/domains/functions | 41 ++++++++++++++++------------- plugins/domains/subcommands/default | 2 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 764fd9c15..d248ff155 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -814,24 +814,24 @@ get_ipv6_regex() { echo "${RE_IPV6}\$" } -get_global_vhost() { - declare desc="return global vhost" +get_global_vhosts() { + declare desc="return global vhosts" local GLOBAL_VHOST_FILE="$DOKKU_ROOT/VHOST" - [[ -f "$GLOBAL_VHOST_FILE" ]] && local GLOBAL_VHOST=$(< "$GLOBAL_VHOST_FILE") - echo "$GLOBAL_VHOST" + [[ -f "$GLOBAL_VHOST_FILE" ]] && local GLOBAL_VHOSTS=$(< "$GLOBAL_VHOST_FILE") + echo "$GLOBAL_VHOSTS" } is_global_vhost_enabled() { declare 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 GLOBAL_VHOSTS=$(get_global_vhosts) + local GLOBAL_VHOSTS_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 + if [[ -z "$GLOBAL_VHOSTS" ]] || [[ "$GLOBAL_VHOSTS" =~ $RE_IPV4 ]] || [[ "$GLOBAL_VHOSTS" =~ $RE_IPV6 ]]; then + local GLOBAL_VHOSTS_ENABLED=false fi - echo $GLOBAL_VHOST_ENABLED + echo $GLOBAL_VHOSTS_ENABLED } is_app_vhost_enabled() { diff --git a/plugins/domains/functions b/plugins/domains/functions index ee6f77601..4b399bcfe 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -20,27 +20,30 @@ get_app_domains() { fi } -get_default_vhost() { +get_default_vhosts() { declare desc="return default vhost" verify_app_name "$1" local APP="$1"; local RE_IPV4="$(get_ipv4_regex)"; local RE_IPV6="$(get_ipv6_regex)" + if [[ "$(is_global_vhost_enabled)" == "true" ]]; then - local VHOST=$(get_global_vhost) - if ! ([[ "$VHOST" =~ $RE_IPV4 ]] || [[ "$VHOST" =~ $RE_IPV6 ]]); then - local SUBDOMAIN=${APP/%\.${VHOST}/} - local hostname=$(: | plugn trigger nginx-hostname "$APP" "$SUBDOMAIN" "$VHOST") - if [[ ! -n $hostname ]]; then - if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then - local hostname="${APP/\//-}" - else - local hostname="${APP/\//-}.$VHOST" + local VHOSTS=$(get_global_vhosts) + + while read -r VHOST; do + if ! ([[ "$VHOST" =~ $RE_IPV4 ]] || [[ "$VHOST" =~ $RE_IPV6 ]]); then + local SUBDOMAIN=${APP/%\.${VHOST}/} + local hostname=$(: | plugn trigger nginx-hostname "$APP" "$SUBDOMAIN" "$VHOST") + if [[ ! -n $hostname ]]; then + if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then + local hostname="${APP/\//-}" + else + local hostname="${APP/\//-}.$VHOST" + fi fi + echo "$hostname" fi - local DEFAULT_VHOST="$hostname" - fi + done <<< "$VHOSTS" fi - echo "$DEFAULT_VHOST" } domains_setup() { @@ -48,12 +51,12 @@ domains_setup() { verify_app_name "$1" local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"; local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" local RE_IPV4="$(get_ipv4_regex)"; local RE_IPV6="$(get_ipv6_regex)" - local DEFAULT_VHOST="$(get_default_vhost "$APP")" + local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")" if [[ ! -f $APP_VHOST_PATH ]]; then - if [[ -n "$DEFAULT_VHOST" ]]; then + if [[ -n "$DEFAULT_VHOSTS" ]]; then dokku_log_info1 "Creating new $APP_VHOST_PATH..." - echo "$DEFAULT_VHOST" > "$APP_VHOST_PATH" + echo "$DEFAULT_VHOSTS" > "$APP_VHOST_PATH" else dokku_log_info2 "no global VHOST set. disabling vhost support" disable_app_vhost "$APP" --no-restart @@ -118,11 +121,11 @@ domains_enable() { declare desc="enable domains/VHOST support" verify_app_name "$1" local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" - local DEFAULT_VHOST="$(get_default_vhost "$APP")" + local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")" if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]];then - if [[ -n "$DEFAULT_VHOST" ]]; then - echo "$DEFAULT_VHOST" > "$APP_VHOST_PATH" + if [[ -n "$DEFAULT_VHOSTS" ]]; then + echo "$DEFAULT_VHOSTS" > "$APP_VHOST_PATH" fi [[ "$2" == "--no-restart" ]] && local ENABLE_APP_VHOST_ARGS=$2 enable_app_vhost "$APP" "$ENABLE_APP_VHOST_ARGS" diff --git a/plugins/domains/subcommands/default b/plugins/domains/subcommands/default index 7bf731c04..011a1c292 100755 --- a/plugins/domains/subcommands/default +++ b/plugins/domains/subcommands/default @@ -10,7 +10,7 @@ domains_main_cmd() { if [[ "$(is_global_vhost_enabled)" == "true" ]]; then dokku_log_info2_quiet "Global Domain Name" - get_global_vhost + get_global_vhosts fi if [[ -n "$APP" ]]; then verify_app_name "$APP"