Move VHOST file creation to a single domains:setup command

This helps remove duplication and also ensures that all hosts have a proper setup after running `make copyfiles`

Note that this command is not exposed in help as it is not generally useful to developers
This commit is contained in:
Jose Diaz-Gonzalez
2014-11-24 02:13:41 -05:00
parent 66171551d8
commit e84526490e
3 changed files with 32 additions and 32 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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`