From 579d4303032c3ba7940c7d7d07630ea60fcdbf7a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 18 Feb 2020 17:02:49 -0500 Subject: [PATCH 1/3] refactor: rename nginx:show-conf to nginx:show-config --- ISSUE_TEMPLATE.md | 2 +- docs/appendices/0.20.0-migration-guide.md | 8 ++++++-- docs/configuration/nginx.md | 6 +++--- plugins/nginx-vhosts/help-functions | 2 +- plugins/nginx-vhosts/internal-functions | 18 ++++++++++++++++++ plugins/nginx-vhosts/subcommands/show-conf | 17 ++--------------- plugins/nginx-vhosts/subcommands/show-config | 7 +++++++ tests/unit/40_nginx-vhosts_2.bats | 12 ++++++------ 8 files changed, 44 insertions(+), 28 deletions(-) create mode 100755 plugins/nginx-vhosts/subcommands/show-config diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index b78209d87..47fd451f7 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -32,7 +32,7 @@ ### Additional information - Container Inspect Output (if applicable) via `dokku ps:inspect APP_NAME` -- The nginx configuration (if applicable) via `dokku nginx:show-conf APP_NAME` +- The nginx configuration (if applicable) via `dokku nginx:show-config APP_NAME` - Link to the exact repository being deployed (if possible/applicable): - If a deploy is failing or behaving unexpectedly: - Application name diff --git a/docs/appendices/0.20.0-migration-guide.md b/docs/appendices/0.20.0-migration-guide.md index 79abc6bfc..16ff323b6 100644 --- a/docs/appendices/0.20.0-migration-guide.md +++ b/docs/appendices/0.20.0-migration-guide.md @@ -1,8 +1,8 @@ # 0.20.0 Migration Guide -## Deprecated command removal +## Removals -The following commands have been deprecated and were removed in this release. +The following commands were previously deprecated and were removed in this release. - `apps`: Use `apps:list` instead. - `certs`: Use `certs:report` instead. @@ -13,3 +13,7 @@ The following commands have been deprecated and were removed in this release. - `plugin`: Use `plugin:list` instead. - `proxy`: Use `proxy:report` instead. - `trace`: Use `trace:on` or `trace:off` instead. + +## Deprecations + +- `nginx:show-conf` has been deprecated in favor of `nginx:show-config`. diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index b8e99825c..8a620f185 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -8,7 +8,7 @@ nginx:build-config # (Re)builds nginx config for given app nginx:error-logs [-t] # Show the nginx error logs for an application (-t follows) nginx:report [] [] # Displays a nginx report for one or more apps nginx:set () # Set or clear an nginx property for an app -nginx:show-conf # Display app nginx config +nginx:show-config # Display app nginx config nginx:validate [] [--clean] # Validates and optionally cleans up invalid nginx configurations ``` @@ -92,10 +92,10 @@ dokku nginx:build-config node-js-app ## Showing the nginx config -For debugging purposes, it may be useful to show the nginx config. This can be achieved via the `nginx:show-conf` command. +For debugging purposes, it may be useful to show the nginx config. This can be achieved via the `nginx:show-config` command. ```shell -dokku nginx:show-conf node-js-app +dokku nginx:show-config node-js-app ``` ## Validating nginx configs diff --git a/plugins/nginx-vhosts/help-functions b/plugins/nginx-vhosts/help-functions index d8e660210..5f62064f1 100755 --- a/plugins/nginx-vhosts/help-functions +++ b/plugins/nginx-vhosts/help-functions @@ -32,7 +32,7 @@ fn-help-content() { nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) nginx:report [] [], Displays an nginx report for one or more apps nginx:set (), Set or clear an nginx property for an app - nginx:show-conf , Display app nginx config + nginx:show-config , Display app nginx config nginx:validate [] [--clean], Validates and optionally cleans up invalid nginx configurations help_content } diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index 7fe7401a1..2c1e344de 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -70,6 +70,24 @@ cmd-nginx-report-single() { fi } +cmd-nginx-show-config() { + declare desc="display app nginx config" + declare cmd="nginx:show-config" + [[ "$1" == "$cmd" ]] && shift 1 + if [[ "$1" == "nginx:show-conf" ]]; then + dokku_log_warn "Deprecated: Please use nginx:show-config" + shift 1 + fi + declare APP="$1" + + verify_app_name "$APP" + if [[ ! -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then + dokku_log_fail "No nginx.conf exists for $APP" + fi + + cat "$DOKKU_ROOT/$APP/nginx.conf" +} + fn-nginx-vhosts-manage-hsts() { declare APP="$1" SSL_ENABLED="$2" local HSTS="$(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")" diff --git a/plugins/nginx-vhosts/subcommands/show-conf b/plugins/nginx-vhosts/subcommands/show-conf index 355463078..408a012e0 100755 --- a/plugins/nginx-vhosts/subcommands/show-conf +++ b/plugins/nginx-vhosts/subcommands/show-conf @@ -2,19 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" -cmd-nginx-show-conf() { - declare desc="display app nginx config" - declare cmd="nginx:show-conf" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" - - verify_app_name "$APP" - if [[ ! -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then - dokku_log_fail "No nginx.conf exists for $APP" - fi - - cat "$DOKKU_ROOT/$APP/nginx.conf" -} - -cmd-nginx-show-conf "$@" +cmd-nginx-show-config "$@" diff --git a/plugins/nginx-vhosts/subcommands/show-config b/plugins/nginx-vhosts/subcommands/show-config new file mode 100755 index 000000000..408a012e0 --- /dev/null +++ b/plugins/nginx-vhosts/subcommands/show-config @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" + +cmd-nginx-show-config "$@" diff --git a/tests/unit/40_nginx-vhosts_2.bats b/tests/unit/40_nginx-vhosts_2.bats index 15b4d91a5..32645a3ab 100644 --- a/tests/unit/40_nginx-vhosts_2.bats +++ b/tests/unit/40_nginx-vhosts_2.bats @@ -35,7 +35,7 @@ teardown() { add_domain "node-js-app.dokku.me" add_domain "test.dokku.me" deploy_app - dokku nginx:show-conf $TEST_APP + dokku nginx:show-config $TEST_APP assert_ssl_domain "node-js-app.dokku.me" assert_http_redirect "http://test.dokku.me" "https://test.dokku.me:443/" } @@ -45,7 +45,7 @@ teardown() { add_domain "wildcard1.dokku.me" add_domain "wildcard2.dokku.me" deploy_app - dokku nginx:show-conf $TEST_APP + dokku nginx:show-config $TEST_APP assert_ssl_domain "wildcard1.dokku.me" assert_ssl_domain "wildcard2.dokku.me" } @@ -55,8 +55,8 @@ teardown() { TEST_APP="${TEST_APP}.example.com" setup_test_tls wildcard deploy_app nodejs-express dokku@dokku.me:$TEST_APP - run /bin/bash -c "dokku nginx:show-conf $TEST_APP | grep -e '*.dokku.me' | wc -l" - dokku nginx:show-conf $TEST_APP + run /bin/bash -c "dokku nginx:show-config $TEST_APP | grep -e '*.dokku.me' | wc -l" + dokku nginx:show-config $TEST_APP assert_output "0" } @@ -200,7 +200,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku nginx:show-conf $TEST_APP" + run /bin/bash -c "dokku nginx:show-config $TEST_APP" echo "output: $output" echo "status: $status" assert_output_contains "[::1]:80;" @@ -221,7 +221,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku nginx:show-conf $TEST_APP" + run /bin/bash -c "dokku nginx:show-config $TEST_APP" echo "output: $output" echo "status: $status" assert_output_contains "[::1]:80;" 0 From 94357b961e576ec242f50be64f82d5726307dcc6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 18 Feb 2020 17:12:33 -0500 Subject: [PATCH 2/3] refactor: deprecate nginx:validate The command function move was to fix circular import issues... --- docs/configuration/nginx.md | 14 +-- plugins/nginx-vhosts/command-functions | 104 ++++++++++++++++++ plugins/nginx-vhosts/help-functions | 2 +- plugins/nginx-vhosts/internal-functions | 84 -------------- plugins/nginx-vhosts/report | 2 +- plugins/nginx-vhosts/subcommands/report | 2 +- plugins/nginx-vhosts/subcommands/show-conf | 2 +- plugins/nginx-vhosts/subcommands/show-config | 2 +- plugins/nginx-vhosts/subcommands/validate | 13 +-- .../nginx-vhosts/subcommands/validate-config | 7 ++ tests/unit/40_nginx-vhosts_2.bats | 18 +-- 11 files changed, 134 insertions(+), 116 deletions(-) create mode 100755 plugins/nginx-vhosts/command-functions create mode 100755 plugins/nginx-vhosts/subcommands/validate-config diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index 8a620f185..3b94226f5 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -9,7 +9,7 @@ nginx:error-logs [-t] # Show the nginx error logs for an appl nginx:report [] [] # Displays a nginx report for one or more apps nginx:set () # Set or clear an nginx property for an app nginx:show-config # Display app nginx config -nginx:validate [] [--clean] # Validates and optionally cleans up invalid nginx configurations +nginx:validate-config [] [--clean] # Validates and optionally cleans up invalid nginx configurations ``` ## Binding to specific addresses @@ -100,26 +100,26 @@ dokku nginx:show-config node-js-app ## Validating nginx configs -It may be desired to validate an nginx config outside of the deployment process. To do so, run the `nginx:validate` command. With no arguments, this will validate all app nginx configs, one at a time. A minimal wrapper nginx config is generated for each app's nginx config, upon which `nginx -t` will be run. +It may be desired to validate an nginx config outside of the deployment process. To do so, run the `nginx:validate-config` command. With no arguments, this will validate all app nginx configs, one at a time. A minimal wrapper nginx config is generated for each app's nginx config, upon which `nginx -t` will be run. ```shell -dokku nginx:validate +dokku nginx:validate-config ``` -As app nginx configs are actually executed within a shared context, it is possible for an individual config to be invalid when being validated standalone but _also_ be valid within the global server context. As such, the exit code for the `nginx:validate` command is the exit code of `nginx -t` against the server's real nginx config. +As app nginx configs are actually executed within a shared context, it is possible for an individual config to be invalid when being validated standalone but _also_ be valid within the global server context. As such, the exit code for the `nginx:validate-config` command is the exit code of `nginx -t` against the server's real nginx config. -The `nginx:validate` command also takes an optional `--clean` flag. If specified, invalid nginx configs will be removed. +The `nginx:validate-config` command also takes an optional `--clean` flag. If specified, invalid nginx configs will be removed. > Warning: Invalid app nginx config's will be removed _even if_ the config is valid in the global server context. ```shell -dokku nginx:validate --clean +dokku nginx:validate-config --clean ``` The `--clean` flag may also be specified for a given app: ```shell -dokku nginx:validate node-js-app --clean +dokku nginx:validate-config node-js-app --clean ``` ## Customizing the nginx configuration diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions new file mode 100755 index 000000000..59ffc420c --- /dev/null +++ b/plugins/nginx-vhosts/command-functions @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" + +cmd-nginx-report() { + declare desc="displays a nginx report for one or more apps" + declare cmd="nginx:report" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP="$1" INFO_FLAG="$2" + local INSTALLED_APPS=$(dokku_apps) + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-nginx-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-nginx-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-nginx-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--nginx-bind-address-ipv4: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv4" "")" + "--nginx-bind-address-ipv6: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")" + "--nginx-hsts: $(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")" + "--nginx-hsts-include-subdomains: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-include-subdomains" "true")" + "--nginx-hsts-max-age: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-max-age" "15724800")" + "--nginx-hsts-preload: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-preload" "false")" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "${APP} nginx information" + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" + done + else + local match=false + local value_exists=false + for flag in "${flag_map[@]}"; do + valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" + if [[ "$flag" == "${INFO_FLAG}:"* ]]; then + value=${flag#*: } + size="${#value}" + if [[ "$size" -ne 0 ]]; then + echo "$value" && match=true && value_exists=true + else + match=true + fi + fi + done + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + +cmd-nginx-show-config() { + declare desc="display app nginx config" + declare cmd="nginx:show-config" + [[ "$1" == "$cmd" ]] && shift 1 + if [[ "$1" == "nginx:show-conf" ]]; then + dokku_log_warn "Deprecated: Please use nginx:show-config" + shift 1 + fi + declare APP="$1" + + verify_app_name "$APP" + if [[ ! -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then + dokku_log_fail "No nginx.conf exists for $APP" + fi + + cat "$DOKKU_ROOT/$APP/nginx.conf" +} + + +cmd-nginx-validate-config() { + declare desc="validates and optionally cleans up invalid nginx configurations" + declare cmd="nginx:validate" + [[ "$1" == "$cmd" ]] && shift 1 + if [[ "$1" == "nginx:validate-conf" ]]; then + dokku_log_warn "Deprecated: Please use nginx:validate-config" + shift 1 + fi + declare APP="$1" FLAG="$2" + + validate_nginx "$APP" "$FLAG" +} diff --git a/plugins/nginx-vhosts/help-functions b/plugins/nginx-vhosts/help-functions index 5f62064f1..e7efed5d5 100755 --- a/plugins/nginx-vhosts/help-functions +++ b/plugins/nginx-vhosts/help-functions @@ -33,6 +33,6 @@ fn-help-content() { nginx:report [] [], Displays an nginx report for one or more apps nginx:set (), Set or clear an nginx property for an app nginx:show-config , Display app nginx config - nginx:validate [] [--clean], Validates and optionally cleans up invalid nginx configurations + nginx:validate-config [] [--clean], Validates and optionally cleans up invalid nginx configurations help_content } diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index 2c1e344de..c286b2074 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -4,90 +4,6 @@ set -eo pipefail source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" -cmd-nginx-report() { - declare desc="displays a nginx report for one or more apps" - declare cmd="nginx:report" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" INFO_FLAG="$2" - local INSTALLED_APPS=$(dokku_apps) - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - cmd-nginx-report-single "$app" "$INFO_FLAG" | tee || true - done - else - cmd-nginx-report-single "$APP" "$INFO_FLAG" - fi -} - -cmd-nginx-report-single() { - declare APP="$1" INFO_FLAG="$2" - if [[ "$INFO_FLAG" == "true" ]]; then - INFO_FLAG="" - fi - verify_app_name "$APP" - local flag_map=( - "--nginx-bind-address-ipv4: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv4" "")" - "--nginx-bind-address-ipv6: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")" - "--nginx-hsts: $(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")" - "--nginx-hsts-include-subdomains: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-include-subdomains" "true")" - "--nginx-hsts-max-age: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-max-age" "15724800")" - "--nginx-hsts-preload: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-preload" "false")" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "${APP} nginx information" - for flag in "${flag_map[@]}"; do - key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" - dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" - done - else - local match=false - local value_exists=false - for flag in "${flag_map[@]}"; do - valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" - if [[ "$flag" == "${INFO_FLAG}:"* ]]; then - value=${flag#*: } - size="${#value}" - if [[ "$size" -ne 0 ]]; then - echo "$value" && match=true && value_exists=true - else - match=true - fi - fi - done - [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" - [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" - fi -} - -cmd-nginx-show-config() { - declare desc="display app nginx config" - declare cmd="nginx:show-config" - [[ "$1" == "$cmd" ]] && shift 1 - if [[ "$1" == "nginx:show-conf" ]]; then - dokku_log_warn "Deprecated: Please use nginx:show-config" - shift 1 - fi - declare APP="$1" - - verify_app_name "$APP" - if [[ ! -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then - dokku_log_fail "No nginx.conf exists for $APP" - fi - - cat "$DOKKU_ROOT/$APP/nginx.conf" -} - fn-nginx-vhosts-manage-hsts() { declare APP="$1" SSL_ENABLED="$2" local HSTS="$(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")" diff --git a/plugins/nginx-vhosts/report b/plugins/nginx-vhosts/report index 19d04fd8a..dcadd716e 100755 --- a/plugins/nginx-vhosts/report +++ b/plugins/nginx-vhosts/report @@ -1,5 +1,5 @@ #!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/plugins/nginx-vhosts/subcommands/report b/plugins/nginx-vhosts/subcommands/report index 4270d7a15..9fcc13b49 100755 --- a/plugins/nginx-vhosts/subcommands/report +++ b/plugins/nginx-vhosts/subcommands/report @@ -1,5 +1,5 @@ #!/usr/bin/env bash -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/plugins/nginx-vhosts/subcommands/show-conf b/plugins/nginx-vhosts/subcommands/show-conf index 408a012e0..75c6248f1 100755 --- a/plugins/nginx-vhosts/subcommands/show-conf +++ b/plugins/nginx-vhosts/subcommands/show-conf @@ -2,6 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" cmd-nginx-show-config "$@" diff --git a/plugins/nginx-vhosts/subcommands/show-config b/plugins/nginx-vhosts/subcommands/show-config index 408a012e0..75c6248f1 100755 --- a/plugins/nginx-vhosts/subcommands/show-config +++ b/plugins/nginx-vhosts/subcommands/show-config @@ -2,6 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" cmd-nginx-show-config "$@" diff --git a/plugins/nginx-vhosts/subcommands/validate b/plugins/nginx-vhosts/subcommands/validate index 68fbe0be1..ac7b22f87 100755 --- a/plugins/nginx-vhosts/subcommands/validate +++ b/plugins/nginx-vhosts/subcommands/validate @@ -2,15 +2,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" -cmd-nginx-validate() { - declare desc="validates and optionally cleans up invalid nginx configurations" - declare cmd="nginx:validate" - [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" FLAG="$2" - - validate_nginx "$APP" "$FLAG" -} - -cmd-nginx-validate "$@" +cmd-nginx-validate-config "$@" diff --git a/plugins/nginx-vhosts/subcommands/validate-config b/plugins/nginx-vhosts/subcommands/validate-config new file mode 100755 index 000000000..ac7b22f87 --- /dev/null +++ b/plugins/nginx-vhosts/subcommands/validate-config @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" + +cmd-nginx-validate-config "$@" diff --git a/tests/unit/40_nginx-vhosts_2.bats b/tests/unit/40_nginx-vhosts_2.bats index 32645a3ab..30c96be01 100644 --- a/tests/unit/40_nginx-vhosts_2.bats +++ b/tests/unit/40_nginx-vhosts_2.bats @@ -228,48 +228,48 @@ teardown() { assert_output_contains "127.0.0.1:80;" 0 } -@test "(nginx-vhosts) nginx:validate" { +@test "(nginx-vhosts) nginx:validate-config" { deploy_app - run /bin/bash -c "dokku nginx:validate" + run /bin/bash -c "dokku nginx:validate-config" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku nginx:validate $TEST_APP" + run /bin/bash -c "dokku nginx:validate-config $TEST_APP" echo "output: $output" echo "status: $status" assert_success echo "invalid config" > "/home/dokku/${TEST_APP}/nginx.conf" - run /bin/bash -c "dokku nginx:validate" + run /bin/bash -c "dokku nginx:validate-config" echo "output: $output" echo "status: $status" assert_failure - run /bin/bash -c "dokku nginx:validate $TEST_APP" + run /bin/bash -c "dokku nginx:validate-config $TEST_APP" echo "output: $output" echo "status: $status" assert_failure - run /bin/bash -c "dokku nginx:validate --clean" + run /bin/bash -c "dokku nginx:validate-config --clean" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku nginx:validate" + run /bin/bash -c "dokku nginx:validate-config" echo "output: $output" echo "status: $status" assert_success echo "invalid config" > "/home/dokku/${TEST_APP}/nginx.conf" - run /bin/bash -c "dokku nginx:validate $TEST_APP --clean" + run /bin/bash -c "dokku nginx:validate-config $TEST_APP --clean" echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku nginx:validate" + run /bin/bash -c "dokku nginx:validate-config" echo "output: $output" echo "status: $status" assert_success From 1ba5269779afd9b596c73ee10500b4c7850ad606 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 19 Feb 2020 01:02:12 -0500 Subject: [PATCH 3/3] fix: use correct command name --- plugins/nginx-vhosts/command-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index 59ffc420c..bd68eca62 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -92,9 +92,9 @@ cmd-nginx-show-config() { cmd-nginx-validate-config() { declare desc="validates and optionally cleans up invalid nginx configurations" - declare cmd="nginx:validate" + declare cmd="nginx:validate-config" [[ "$1" == "$cmd" ]] && shift 1 - if [[ "$1" == "nginx:validate-conf" ]]; then + if [[ "$1" == "nginx:validate" ]]; then dokku_log_warn "Deprecated: Please use nginx:validate-config" shift 1 fi