Merge pull request #2510 from IlyaSemenov/domains_set

Add domains:set and domains:set-global commands
This commit is contained in:
Jose Diaz-Gonzalez
2016-11-28 18:18:51 -07:00
committed by GitHub
7 changed files with 123 additions and 7 deletions

View File

@@ -15,6 +15,8 @@ case "$1" in
domains:enable <app>, Enable VHOST support
domains:remove <app> <domain> [<domain> ...], Remove domains from app
domains:remove-global <domain> [<domain> ...], Remove global domain names
domains:set <app> <domain> [<domain> ...], Set domains for app
domains:set-global <domain> [<domain> ...], Set global domain names
help_content
}

View File

@@ -85,7 +85,7 @@ domains_add() {
fi
done
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]];then
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then
domains_enable "$APP" --no-restart
fi
@@ -105,12 +105,34 @@ domains_remove() {
plugn trigger post-domains-update "$APP" "remove" "$@"
}
domains_set() {
declare desc="set list of domains for app"
verify_app_name "$1"
local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
shift 1
for DOMAIN in "$@"; do
if ! (is_valid_hostname "$DOMAIN"); then
dokku_log_fail "$DOMAIN is invalid. exiting..."
fi
done
echo "$*" | tr " " "\n" > "$APP_VHOST_PATH"
dokku_log_info1 "Set $* for $APP"
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then
domains_enable "$APP" --no-restart
fi
plugn trigger post-domains-update "$APP" "set" "$@"
}
domains_disable() {
declare desc="disable domains/VHOST support"
verify_app_name "$1"
local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]];then
if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then
disable_app_vhost "$APP"
else
dokku_log_info1 "domains (VHOST) support is already disabled for app ($APP)"
@@ -123,7 +145,7 @@ domains_enable() {
local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")"
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]];then
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then
if [[ -n "$DEFAULT_VHOSTS" ]]; then
echo "$DEFAULT_VHOSTS" > "$APP_VHOST_PATH"
fi
@@ -163,3 +185,17 @@ domains_remove_global() {
dokku_log_info1 "Removed $DOMAIN"
done
}
domains_set_global() {
declare desc="set list of global domains"
local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST"
for DOMAIN in "$@"; do
if ! (is_valid_hostname "$DOMAIN"); then
dokku_log_fail "$DOMAIN is invalid. exiting..."
fi
done
echo "$*" | tr " " "\n" > "$GLOBAL_VHOST_PATH"
dokku_log_info1 "Set $*"
}

16
plugins/domains/subcommands/set Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
domains_set_cmd() {
declare desc="set domains for app via command line"
local cmd="domains:set"
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
[[ -z $3 ]] && dokku_log_fail "Please specify a domain name. Usage: dokku $1 $2 <domain> [<domain> ...]"
shift 1
domains_set "$@"
}
domains_set_cmd "$@"

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
domains_set_global_cmd() {
declare desc="set global domain names via command line"
local cmd="domains:set-global"
[[ -z $2 ]] && dokku_log_fail "Please specify a domain name. Usage: dokku $1 <domain> [<domain> ...]"
shift 1
domains_set_global "$@"
}
domains_set_global_cmd "$@"