refactor: move domain manipulation into triggers
This allows other plugins to avoid understanding the underlying details of how domains might be integrated with.
This commit is contained in:
14
plugins/domains/domains-add
Executable file
14
plugins/domains/domains-add
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-add() {
|
||||
declare desc="adds a domain to an app"
|
||||
declare trigger="domains-add"
|
||||
declare APP="$1" DOMAIN="$2"
|
||||
|
||||
domains_add "$APP" "$DOMAIN"
|
||||
}
|
||||
|
||||
trigger-domains-domains-add "$@"
|
||||
18
plugins/domains/domains-disable
Executable file
18
plugins/domains/domains-disable
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-disable() {
|
||||
declare desc="disables domains for an app"
|
||||
declare trigger="domains-disable"
|
||||
declare APP="$1" RESTART_APP="$2"
|
||||
|
||||
if [[ "$RESTART_APP" == "true" ]]; then
|
||||
disable_app_vhost "$APP"
|
||||
else
|
||||
disable_app_vhost "$APP" --no-restart
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-domains-domains-disable "$@"
|
||||
18
plugins/domains/domains-enable
Executable file
18
plugins/domains/domains-enable
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-enable() {
|
||||
declare desc="enables domains for an app"
|
||||
declare trigger="domains-enable"
|
||||
declare APP="$1" RESTART_APP="$2"
|
||||
|
||||
if [[ "$RESTART_APP" == "true" ]]; then
|
||||
enable_app_vhost "$APP"
|
||||
else
|
||||
enable_app_vhost "$APP" --no-restart
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-domains-domains-enable "$@"
|
||||
14
plugins/domains/domains-list
Executable file
14
plugins/domains/domains-list
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-list() {
|
||||
declare desc="returns all domains for an app"
|
||||
declare trigger="domains-list"
|
||||
declare APP="$1"
|
||||
|
||||
get_app_domains "$APP"
|
||||
}
|
||||
|
||||
trigger-domains-domains-list "$@"
|
||||
19
plugins/domains/domains-setup
Executable file
19
plugins/domains/domains-setup
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-setup() {
|
||||
declare desc="creates vhost files as necessary"
|
||||
declare trigger="domains-setup"
|
||||
declare APP="$1"
|
||||
|
||||
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then
|
||||
dokku_log_info1 "App virtual host support disabled, skipping domains setup"
|
||||
return
|
||||
fi
|
||||
|
||||
domains_setup "$APP"
|
||||
}
|
||||
|
||||
trigger-domains-domains-setup "$@"
|
||||
16
plugins/domains/domains-vhost-enabled
Executable file
16
plugins/domains/domains-vhost-enabled
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-domains-domains-vhost-enabled() {
|
||||
declare desc="returns whether vhosts are enabled or not"
|
||||
declare trigger="domains-vhost-enabled"
|
||||
declare APP="$1"
|
||||
|
||||
if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-domains-domains-vhost-enabled "$@"
|
||||
@@ -1,28 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
disable_app_vhost() {
|
||||
declare desc="disable vhost support for given application"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
local APP=$1
|
||||
declare APP=$1 RESTART_APP="$2"
|
||||
verify_app_name "$APP"
|
||||
local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST"
|
||||
local APP_URLS_FILE="$DOKKU_ROOT/$APP/URLS"
|
||||
|
||||
plugn trigger pre-disable-vhost "$APP"
|
||||
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"
|
||||
if [[ -f "$APP_VHOST_FILE" ]] || [[ -f "$APP_URLS_FILE" ]]; then
|
||||
dokku_log_info1 "App virtual host support disabled"
|
||||
rm -f "$APP_VHOST_FILE" "$APP_URLS_FILE"
|
||||
fi
|
||||
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
[[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP
|
||||
# shellcheck disable=SC2086
|
||||
DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS $APP NO_VHOST=1
|
||||
}
|
||||
@@ -39,10 +34,10 @@ domains_setup() {
|
||||
|
||||
if [[ ! -f $APP_VHOST_PATH ]]; then
|
||||
if [[ -n "$DEFAULT_VHOSTS" ]]; then
|
||||
dokku_log_info1 "Creating new $APP_VHOST_PATH..."
|
||||
dokku_log_info1 "Creating new app virtual host file..."
|
||||
echo "$DEFAULT_VHOSTS" >"$APP_VHOST_PATH"
|
||||
else
|
||||
dokku_log_info2 "no global VHOST set. disabling vhost support"
|
||||
dokku_log_info2 "Global server virtual host not set, disabling app vhost..."
|
||||
disable_app_vhost "$APP" --no-restart
|
||||
fi
|
||||
fi
|
||||
@@ -129,14 +124,14 @@ domains_disable() {
|
||||
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)"
|
||||
dokku_log_info1 "Domains (VHOST) support is already disabled for app ($APP)"
|
||||
fi
|
||||
}
|
||||
|
||||
domains_enable() {
|
||||
declare desc="enable domains/VHOST support"
|
||||
verify_app_name "$1"
|
||||
local APP="$1"
|
||||
local APP="$1" RESTART_APP="$2"
|
||||
local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
||||
local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")"
|
||||
|
||||
@@ -145,10 +140,10 @@ domains_enable() {
|
||||
if [[ -n "$DEFAULT_VHOSTS" ]]; then
|
||||
echo "$DEFAULT_VHOSTS" >"$APP_VHOST_PATH"
|
||||
fi
|
||||
[[ "$2" == "--no-restart" ]] && local ENABLE_APP_VHOST_ARGS=$2
|
||||
[[ "$RESTART_APP" == "--no-restart" ]] && local ENABLE_APP_VHOST_ARGS=$RESTART_APP
|
||||
enable_app_vhost "$APP" "$ENABLE_APP_VHOST_ARGS"
|
||||
else
|
||||
dokku_log_info1 "domains (VHOST) support is already enabled for app ($APP)"
|
||||
dokku_log_info1 "Domains (VHOST) support is already enabled for app ($APP)"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -212,13 +207,11 @@ domains_set_global() {
|
||||
|
||||
enable_app_vhost() {
|
||||
declare desc="enable vhost support for given application"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
local APP=$1
|
||||
declare APP=$1 RESTART_APP="$2"
|
||||
verify_app_name "$APP"
|
||||
|
||||
plugn trigger pre-enable-vhost "$APP"
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
[[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP
|
||||
# shellcheck disable=SC2086
|
||||
DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS "$APP" NO_VHOST=0
|
||||
}
|
||||
@@ -278,7 +271,6 @@ get_global_vhosts() {
|
||||
|
||||
is_app_vhost_enabled() {
|
||||
declare desc="returns true or false if vhost support is enabled for a given application"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
local APP=$1
|
||||
verify_app_name "$APP"
|
||||
|
||||
Reference in New Issue
Block a user