feat: add ability to disable custom ninx.conf.sigil extraction
Closes #4087
This commit is contained in:
@@ -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
|
||||
|
||||
```
|
||||
|
||||
@@ -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")"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user