Merge pull request #4121 from dokku/4087-nginx-extract-disable

Add ability to disable custom ninx.conf.sigil extraction
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2020-09-05 11:48:57 -04:00
commit 70c947289f
5 files changed
+46 -2

No files matched your search

+13
View File
@@ -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. > 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 ### Available template variables
``` ```
+1
View File
@@ -41,6 +41,7 @@ cmd-nginx-report-single() {
"--nginx-access-log-path: $(fn-nginx-access-log-path "$APP")" "--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-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-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-error-log-path: $(fn-nginx-error-log-path "$APP")"
"--nginx-hsts: $(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")" "--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-include-subdomains: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-include-subdomains" "true")"
+5
View File
@@ -198,6 +198,11 @@ get_custom_nginx_template() {
local IMAGE_TAG="$(get_running_image_tag "$APP")" local IMAGE_TAG="$(get_running_image_tag "$APP")"
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
local NGINX_TEMPLATE_NAME="nginx.conf.sigil" 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 copy_from_image "$IMAGE" "$NGINX_TEMPLATE_NAME" "$DESTINATION_FILE" 2>/dev/null || true
} }
+2 -2
View File
@@ -9,13 +9,13 @@ cmd-nginx-set() {
declare cmd="nginx:set" declare cmd="nginx:set"
[[ "$1" == "$cmd" ]] && shift 1 [[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3" 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 "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
[[ -z "$KEY" ]] && dokku_log_fail "No key specified" [[ -z "$KEY" ]] && dokku_log_fail "No key specified"
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then 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 fi
if [[ -n "$VALUE" ]]; then if [[ -n "$VALUE" ]]; then
+25
View File
@@ -49,6 +49,31 @@ teardown() {
assert_output_contains "${TEST_APP}-worker-5000" 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)" { @test "(nginx-vhosts) nginx:build-config (failed validate_nginx)" {
run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template
echo "output: $output" echo "output: $output"