diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index d73ba8438..348196f4b 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -531,6 +531,96 @@ verify_app_name "$APP" # TODO ``` +### `domains-add` + +- Description: Adds a domain to an app +- Invoked by: +- Arguments: `$APP` `$DOMAIN` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `domains-disable` + +- Description: Disables domains for an app +- Invoked by: +- Arguments: `$APP` `$RESTART_APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `domains-enable` + +- Description: Enables domains for an app +- Invoked by: +- Arguments: `$APP` `$RESTART_APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `domains-list` + +- Description: Lists all domains for an app +- Invoked by: +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `domains-setup` + +- Description: Initializes domains for an app if enabled +- Invoked by: +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + +### `domains-vhost-enabled` + +- Description: Checks if a virtual hosts are enabled for an app +- Invoked by: +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `git-deploy-branch` - Description: Outputs the deploy branch for an app, inherited or not diff --git a/plugins/20_events/domains-add b/plugins/20_events/domains-add new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-add @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/domains-disable b/plugins/20_events/domains-disable new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-disable @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/domains-enable b/plugins/20_events/domains-enable new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-enable @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/domains-list b/plugins/20_events/domains-list new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-list @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/domains-setup b/plugins/20_events/domains-setup new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-setup @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/20_events/domains-vhost-enabled b/plugins/20_events/domains-vhost-enabled new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/domains-vhost-enabled @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/certs/subcommands/generate b/plugins/certs/subcommands/generate index 8f82e8a32..8e53b5c00 100755 --- a/plugins/certs/subcommands/generate +++ b/plugins/certs/subcommands/generate @@ -2,7 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/domains/functions" cmd-certs-generate() { declare desc="generates a self-signed SSL certificate/key combo" @@ -29,7 +28,7 @@ cmd-certs-generate() { chmod 750 "$APP_SSL_PATH" chmod 640 "$APP_SSL_PATH/server.crt" "$APP_SSL_PATH/server.csr" "$APP_SSL_PATH/server.key" plugn trigger post-certs-update "$APP" - [[ -n "$DOMAIN" ]] && (domains_add "$APP" "$DOMAIN" || plugn trigger post-domains-update "$APP") + [[ -n "$DOMAIN" ]] && (plugn trigger domains-add "$APP" "$DOMAIN" || plugn trigger post-domains-update "$APP") dokku_log_info1 "The following is a certificate signing request that can be used" dokku_log_info1 "to generate an 'officially' signed SSL certificate for $APP at $DOMAIN" dokku_log_info1 "by a CA of your choosing." diff --git a/plugins/common/functions b/plugins/common/functions index a9982f45c..7cc3cdc3e 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -849,8 +849,7 @@ internal_get_app_urls() { declare desc="print an app's available urls" source "$PLUGIN_AVAILABLE_PATH/certs/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" - source "$PLUGIN_AVAILABLE_PATH/domains/functions" - + local APP="$2" local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")" local URLS_FILE="$DOKKU_ROOT/$APP/URLS" @@ -860,7 +859,7 @@ internal_get_app_urls() { local app_urls="$(grep -v -E "^#" "$URLS_FILE")" if [[ -n "$DOKKU_PROXY_PORT_MAP" ]]; then local port_map app_vhost - local app_vhosts=$(get_app_domains "$APP") + local app_vhosts=$(plugn trigger domains-list "$APP") for port_map in $DOKKU_PROXY_PORT_MAP; do local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")" local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")" diff --git a/plugins/domains/domains-add b/plugins/domains/domains-add new file mode 100755 index 000000000..062bc0990 --- /dev/null +++ b/plugins/domains/domains-add @@ -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 "$@" diff --git a/plugins/domains/domains-disable b/plugins/domains/domains-disable new file mode 100755 index 000000000..6fb25d8a3 --- /dev/null +++ b/plugins/domains/domains-disable @@ -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 "$@" diff --git a/plugins/domains/domains-enable b/plugins/domains/domains-enable new file mode 100755 index 000000000..5e3127ba9 --- /dev/null +++ b/plugins/domains/domains-enable @@ -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 "$@" diff --git a/plugins/domains/domains-list b/plugins/domains/domains-list new file mode 100755 index 000000000..520bbece8 --- /dev/null +++ b/plugins/domains/domains-list @@ -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 "$@" diff --git a/plugins/domains/domains-setup b/plugins/domains/domains-setup new file mode 100755 index 000000000..1ace670ce --- /dev/null +++ b/plugins/domains/domains-setup @@ -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 "$@" diff --git a/plugins/domains/domains-vhost-enabled b/plugins/domains/domains-vhost-enabled new file mode 100755 index 000000000..cb7becb28 --- /dev/null +++ b/plugins/domains/domains-vhost-enabled @@ -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 "$@" diff --git a/plugins/domains/functions b/plugins/domains/functions index 942352c3b..d4fd192a3 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -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" diff --git a/plugins/nginx-vhosts/core-post-deploy b/plugins/nginx-vhosts/core-post-deploy index 57dad0f23..0ac2813c2 100755 --- a/plugins/nginx-vhosts/core-post-deploy +++ b/plugins/nginx-vhosts/core-post-deploy @@ -2,7 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/domains/functions" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" trigger-nginx-vhosts-core-post-deploy() { @@ -17,12 +16,7 @@ trigger-nginx-vhosts-core-post-deploy() { HAS_NETWORK_CONFIG="$(plugn trigger network-config-exists "$APP")" if [[ "$HAS_NETWORK_CONFIG" == "true" ]]; then - if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then - dokku_log_info1 "VHOST support disabled. Skipping domains setup" - elif [[ ! -f "$DOKKU_ROOT/$APP/VHOST" ]]; then - domains_setup "$APP" - fi - + plugn trigger domains-setup "$APP" nginx_build_config "$APP" fi } diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 702830405..4a8e9e672 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -4,7 +4,6 @@ set -eo pipefail source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/certs/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" -source "$PLUGIN_AVAILABLE_PATH/domains/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" @@ -112,8 +111,9 @@ configure_nginx_ports() { local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) - local IS_APP_VHOST_ENABLED="$(is_app_vhost_enabled "$APP")" + local IS_APP_VHOST_ENABLED=true local UPSTREAM_PORT="5000" + plugn trigger domains-vhost-enabled "$APP" || IS_APP_VHOST_ENABLED=false if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then @@ -164,6 +164,7 @@ validate_ssl_domains() { declare desc="check configured domains against SSL cert contents and show warning if mismatched" local APP=$1 verify_app_name "$APP" + local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" local SSL_HOSTNAME=$(get_ssl_hostnames "$APP") local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g') @@ -317,7 +318,8 @@ nginx_build_config() { local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")" local DOKKU_APP_LISTENERS - local IS_APP_VHOST_ENABLED=$(is_app_vhost_enabled "$APP") + local IS_APP_VHOST_ENABLED=true + plugn trigger domains-vhost-enabled "$APP" || IS_APP_VHOST_ENABLED=false if [[ "$(plugn trigger proxy-is-enabled "$APP")" == "true" ]]; then if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -z "$DOKKU_APP_LISTEN_IP" ]]; then @@ -342,7 +344,7 @@ nginx_build_config() { local PROXY_UPSTREAM_PORTS="$(echo "$PROXY_UPSTREAM_PORTS" | xargs)" local SSL_INUSE= - local NONSSL_VHOSTS=$(get_app_domains "$APP") + local NONSSL_VHOSTS=$(plugn trigger domains-list "$APP") local NOSSL_SERVER_NAME=$(echo "$NONSSL_VHOSTS" | xargs) if is_ssl_enabled "$APP"; then local SSL_INUSE=true diff --git a/plugins/nginx-vhosts/post-domains-update b/plugins/nginx-vhosts/post-domains-update index d2cb14732..425794de6 100755 --- a/plugins/nginx-vhosts/post-domains-update +++ b/plugins/nginx-vhosts/post-domains-update @@ -3,6 +3,7 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" + trigger-nginx-vhosts-post-domains-update() { declare desc="calls nginx build_config when domains are updated" declare trigger="post-domains-update" diff --git a/plugins/nginx-vhosts/proxy-disable b/plugins/nginx-vhosts/proxy-disable index 089fc289e..7144841ac 100755 --- a/plugins/nginx-vhosts/proxy-disable +++ b/plugins/nginx-vhosts/proxy-disable @@ -2,8 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/domains/functions" -source "$PLUGIN_AVAILABLE_PATH/ps/functions" trigger-nginx-vhosts-proxy-disable() { declare desc="disable nginx proxy" @@ -12,8 +10,8 @@ trigger-nginx-vhosts-proxy-disable() { verify_app_name "$APP" if [[ "$(plugn trigger proxy-type "$APP")" == "nginx" ]]; then - disable_app_vhost "$APP" --no-restart - ps_restart "$APP" + plugn trigger domains-disable "$APP" false + plugn trigger app-restart "$APP" fi } diff --git a/plugins/nginx-vhosts/proxy-enable b/plugins/nginx-vhosts/proxy-enable index 4812bcae7..9702114cf 100755 --- a/plugins/nginx-vhosts/proxy-enable +++ b/plugins/nginx-vhosts/proxy-enable @@ -2,8 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/domains/functions" -source "$PLUGIN_AVAILABLE_PATH/ps/functions" trigger-nginx-vhosts-proxy-enable() { declare desc="enable nginx proxy" @@ -12,8 +10,8 @@ trigger-nginx-vhosts-proxy-enable() { verify_app_name "$APP" if [[ "$(plugn trigger proxy-type "$APP")" == "nginx" ]]; then - enable_app_vhost "$APP" --no-restart - ps_restart "$APP" + plugn trigger domains-enable "$APP" "false" + plugn trigger app-restart "$APP" fi } diff --git a/plugins/ps/subcommands/restart b/plugins/ps/subcommands/restart index cccb9ab1e..582fe82ca 100755 --- a/plugins/ps/subcommands/restart +++ b/plugins/ps/subcommands/restart @@ -2,7 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/ps/functions" cmd-ps-restart() { declare desc="restarts app via command line" @@ -11,7 +10,7 @@ cmd-ps-restart() { declare APP="$1" [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" - ps_restart "$APP" + plugn trigger app-restart "$APP" } cmd-ps-restart "$@"