diff --git a/plugins/domains/commands b/plugins/domains/commands index ee28de85e..a06b85b67 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -1,25 +1,43 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -vhost_create () { - VHOST_PATH="$DOKKU_ROOT/$2/VHOST" - [ -f $VHOST_PATH ] || { - echo "-----> Creating new $VHOST_PATH..." - touch $VHOST_PATH - } -} - case "$1" in domains) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - vhost_create + dokku domains:setup $APP echo "=== $APP Domain Names" cat "$DOKKU_ROOT/$APP/VHOST" ;; + domains:setup) + [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 + [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 + APP="$2" + + [ -f $VHOST_PATH ] || { + echo "-----> Creating new $VHOST_PATH..." + if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then + cat "$DOKKU_ROOT/$APP/URL" > $VHOST_PATH + else + VHOST=$(< "$DOKKU_ROOT/VHOST") + SUBDOMAIN=${APP/%\.${VHOST}/} + hostname=$(: | pluginhook nginx-hostname $APP $SUBDOMAIN $VHOST) + if [[ ! -n $hostname ]]; then + if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then + hostname="${APP/\//-}" + else + hostname="${APP/\//-}.$VHOST" + fi + fi + + echo $hostname > $VHOST_PATH + fi + } + ;; + domains:add) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 @@ -31,7 +49,7 @@ case "$1" in exit 1 fi - vhost_create + dokku domains:setup $APP echo "$3" >> "$DOKKU_ROOT/$APP/VHOST" pluginhook post-domains-update $APP echo "-----> Added $3 to $APP" @@ -42,7 +60,7 @@ case "$1" in [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 APP="$2" - vhost_create + dokku domains:setup $APP echo '' > "$DOKKU_ROOT/$APP/VHOST" pluginhook post-domains-update $APP echo "-----> Cleared domains in $APP" @@ -59,7 +77,7 @@ case "$1" in exit 1 fi - vhost_create + dokku domains:setup $APP sed -i "/^$3$/d" "$DOKKU_ROOT/$APP/VHOST" pluginhook post-domains-update $APP echo "-----> Removed $3 from $APP" diff --git a/plugins/domains/install b/plugins/domains/install index c93af0f66..18b7ae028 100755 --- a/plugins/domains/install +++ b/plugins/domains/install @@ -3,5 +3,5 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x for app in $(ls -d $DOKKU_ROOT/*/CONTAINER); do APP=$(basename $(dirname $app)); - touch "$DOKKU_ROOT/$APP/VHOST" + dokku domains:setup $APP done diff --git a/plugins/nginx-vhosts/post-deploy b/plugins/nginx-vhosts/post-deploy index f2905a905..7853d6931 100755 --- a/plugins/nginx-vhosts/post-deploy +++ b/plugins/nginx-vhosts/post-deploy @@ -23,25 +23,7 @@ restart_nginx () { if [[ -n "$NO_VHOST" ]]; then echo "-----> NO_VHOST config detected" elif [[ -f "$DOKKU_ROOT/VHOST" ]]; then - [ -f $VHOST_PATH ] || { - echo "-----> Creating new $VHOST_PATH..." - if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then - cat "$DOKKU_ROOT/$APP/URL" > $VHOST_PATH - else - VHOST=$(< "$DOKKU_ROOT/VHOST") - SUBDOMAIN=${APP/%\.${VHOST}/} - hostname=$(: | pluginhook nginx-hostname $APP $SUBDOMAIN $VHOST) - if [[ ! -n $hostname ]]; then - if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then - hostname="${APP/\//-}" - else - hostname="${APP/\//-}.$VHOST" - fi - fi - - echo $hostname > $VHOST_PATH - fi - } + dokku domains:setup $APP fi NONSSL_VHOSTS=`cat $VHOST_PATH`