diff --git a/plugins/domains/core-post-deploy b/plugins/domains/core-post-deploy new file mode 100755 index 000000000..60b71ef6f --- /dev/null +++ b/plugins/domains/core-post-deploy @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/domains/functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-domains-core-post-deploy() { + declare desc="domains core-post-deploy plugin trigger" + declare trigger="core-post-deploy" + declare APP="$1" + + if [[ "$(plugn trigger proxy-type "$APP")" != "nginx" ]]; then + return + fi + + if [[ ! -f "/etc/nginx/sites-enabled/default" ]]; then + return + fi + + get_app_domains | while read -r domain; do + if [[ "$domain" =~ $RE_IPV4 ]]; then + dokku_log_warn "Detected IPv4 domain name with nginx proxy enabled." + dokku_log_warn "Ensure the default nginx site is removed before continuing." + break + fi + + if [[ "$domain" =~ $RE_IPV6 ]]; then + dokku_log_warn "Detected IPv6 domain name with nginx proxy enabled." + dokku_log_warn "Ensure the default nginx site is removed before continuing." + break + fi + done +} + +trigger-domains-core-post-deploy "$@" diff --git a/plugins/domains/functions b/plugins/domains/functions index 79341b6a3..e7fe0bd2d 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -26,8 +26,6 @@ domains_setup() { local APP="$1" local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" - local RE_IPV4="$(get_ipv4_regex)" - local RE_IPV6="$(get_ipv6_regex)" local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")" if [[ ! -f $APP_VHOST_PATH ]]; then @@ -264,8 +262,6 @@ is_global_vhost_enabled() { declare desc="returns true if we have a valid global vhost set; otherwise returns false" local GLOBAL_VHOSTS=$(get_global_vhosts) local GLOBAL_VHOSTS_ENABLED=false - local RE_IPV4="$(get_ipv4_regex)" - local RE_IPV6="$(get_ipv6_regex)" while read -r GLOBAL_VHOST; do if (is_valid_hostname "$GLOBAL_VHOST"); then diff --git a/tests/unit/domains.bats b/tests/unit/domains.bats index f37f88ff4..1fb49b522 100644 --- a/tests/unit/domains.bats +++ b/tests/unit/domains.bats @@ -355,3 +355,21 @@ teardown() { echo "status: $status" assert_success } + +@test "(domains) verify warning on ipv4/ipv6 domain name" { + touch /etc/nginx/sites-enabled/default + rm "$DOKKU_ROOT/VHOST" + echo "127.0.0.1" >"$DOKKU_ROOT/VHOST" + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Detected IPv4 domain name with nginx proxy enabled." + + rm -f /etc/nginx/sites-enabled/default + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "Detected IPv4 domain name with nginx proxy enabled." 0 +}