From c8a34f906aff0629001def45069f7adca8ea46ef Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:35:32 -0500 Subject: [PATCH 1/4] chore: remove unused ipv4/ipv6 regex fetch --- plugins/domains/functions | 4 ---- 1 file changed, 4 deletions(-) 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 From f3b04032a8ed8731f7e67b2a3926b4f12c779a87 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:43:28 -0500 Subject: [PATCH 2/4] feat: add warning when a user is attempting to deploy with an ipv4/ipv6 domain name and has the default nginx site file available This might cause an app to not load for users, causing confusion on first use. Closes #5341 --- plugins/domains/core-post-deploy | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 plugins/domains/core-post-deploy diff --git a/plugins/domains/core-post-deploy b/plugins/domains/core-post-deploy new file mode 100755 index 000000000..d564a6ce6 --- /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 IPv4 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 "$@" From 47f5af44c540dadc414defdd870d637b8f08d69c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 23 Nov 2022 17:46:33 -0500 Subject: [PATCH 3/4] tests: add a test for the error message --- plugins/domains/core-post-deploy | 2 +- tests/unit/domains.bats | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/domains/core-post-deploy b/plugins/domains/core-post-deploy index d564a6ce6..60b71ef6f 100755 --- a/plugins/domains/core-post-deploy +++ b/plugins/domains/core-post-deploy @@ -25,7 +25,7 @@ trigger-domains-core-post-deploy() { fi if [[ "$domain" =~ $RE_IPV6 ]]; then - dokku_log_warn "Detected IPv4 domain name with nginx proxy enabled." + 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 diff --git a/tests/unit/domains.bats b/tests/unit/domains.bats index f37f88ff4..af8c35efa 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 +} \ No newline at end of file From 4da1f7091af5c5a14c197efaae438880edd42802 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 23 Nov 2022 17:49:41 -0500 Subject: [PATCH 4/4] fix: run shfmt --- tests/unit/domains.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/domains.bats b/tests/unit/domains.bats index af8c35efa..1fb49b522 100644 --- a/tests/unit/domains.bats +++ b/tests/unit/domains.bats @@ -372,4 +372,4 @@ teardown() { echo "status: $status" assert_success assert_output_contains "Detected IPv4 domain name with nginx proxy enabled." 0 -} \ No newline at end of file +}