From f5ba843cf30cbe9d7ce41b0795451fb584994836 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 4 Sep 2020 11:29:23 -0400 Subject: [PATCH] feat: add ability to disable custom ninx.conf.sigil extraction Closes #4087 --- docs/configuration/nginx.md | 13 +++++++++++++ plugins/nginx-vhosts/command-functions | 1 + plugins/nginx-vhosts/functions | 5 +++++ plugins/nginx-vhosts/subcommands/set | 4 ++-- tests/unit/nginx-vhosts_7.bats | 25 +++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index 9992bc019..3aa24e3b9 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -174,6 +174,19 @@ Dokku uses a templating library by the name of [sigil](https://github.com/glider > The default template is available [here](https://github.com/dokku/dokku/blob/master/plugins/nginx-vhosts/templates/nginx.conf.sigil), and can be used as a guide for your own, custom `nginx.conf.sigil` file. Please refer to the appropriate template file version for your Dokku version. +While enabled by default, using a custom nginx config can be disabled via `nginx:set`. This may be useful in cases where you do not want to allow users to override any higher-level customization of app nginx config. + +```shell +# enable fetching custom config (default) +dokku nginx:set node-js-app disable-custom-config false + +# disable fetching custom config +dokku nginx:set node-js-app disable-custom-config true +``` + +Unsetting this value is the same as enabling custom nginx config usage. + + ### Available template variables ``` diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index ff91b754a..59ae7036a 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -41,6 +41,7 @@ cmd-nginx-report-single() { "--nginx-access-log-path: $(fn-nginx-access-log-path "$APP")" "--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-disable-custom-config: $(fn-plugin-property-get-default "nginx" "$APP" "disable-custom-config" "false")" "--nginx-error-log-path: $(fn-nginx-error-log-path "$APP")" "--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")" diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 635208538..1ee8868a9 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -198,6 +198,11 @@ get_custom_nginx_template() { local IMAGE_TAG="$(get_running_image_tag "$APP")" local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local NGINX_TEMPLATE_NAME="nginx.conf.sigil" + local DISABLE_CUSTOM_CONFIG="$(fn-plugin-property-get-default "nginx" "$APP" "disable-custom-config" "false")" + + if [[ "$DISABLE_CUSTOM_CONFIG" == "true" ]]; then + return + fi copy_from_image "$IMAGE" "$NGINX_TEMPLATE_NAME" "$DESTINATION_FILE" 2>/dev/null || true } diff --git a/plugins/nginx-vhosts/subcommands/set b/plugins/nginx-vhosts/subcommands/set index e99f94c28..d319a720b 100755 --- a/plugins/nginx-vhosts/subcommands/set +++ b/plugins/nginx-vhosts/subcommands/set @@ -9,13 +9,13 @@ cmd-nginx-set() { declare cmd="nginx:set" [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" KEY="$2" VALUE="$3" - local VALID_KEYS=("access-log-path" "bind-address-ipv4" "bind-address-ipv6" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "proxy-read-timeout") + local VALID_KEYS=("access-log-path" "bind-address-ipv4" "bind-address-ipv6" "disable-custom-config" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "proxy-read-timeout") [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" [[ -z "$KEY" ]] && dokku_log_fail "No key specified" if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then - dokku_log_fail "Invalid key specified, valid keys include: access-log-path, bind-address-ipv4, bind-address-ipv6, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, proxy-read-timeout" + dokku_log_fail "Invalid key specified, valid keys include: access-log-path, bind-address-ipv4, bind-address-ipv6, disable-custom-config, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, proxy-read-timeout" fi if [[ -n "$VALUE" ]]; then diff --git a/tests/unit/nginx-vhosts_7.bats b/tests/unit/nginx-vhosts_7.bats index 060676d28..d1eefcda9 100644 --- a/tests/unit/nginx-vhosts_7.bats +++ b/tests/unit/nginx-vhosts_7.bats @@ -49,6 +49,31 @@ teardown() { assert_output_contains "${TEST_APP}-worker-5000" } +@test "(nginx-vhosts) nginx:build-config (disable custom nginx template - no ssl)" { + run /bin/bash -c "dokku nginx:set $TEST_APP disable-custom-config true" + echo "output: $output" + echo "status: $status" + assert_success + + add_domain "www.test.app.dokku.me" + run deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:scale $TEST_APP worker=1" + echo "output: $output" + echo "status: $status" + assert_success + + assert_nonssl_domain "www.test.app.dokku.me" + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "${TEST_APP}-worker-5000" 0 +} + @test "(nginx-vhosts) nginx:build-config (failed validate_nginx)" { run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template echo "output: $output"