From bb176e4130973c7f7c00e7666cf6c917ec4aa7ed Mon Sep 17 00:00:00 2001 From: lalyos Date: Tue, 26 Nov 2019 12:30:51 +0100 Subject: [PATCH] feat: add global fallback for DOKKU_PROXY_PORT and DOKKU_PROXY_SSL_PORT --- docs/configuration/environment-variables.md | 4 ++-- plugins/nginx-vhosts/functions | 6 ++++-- tests/unit/20_nginx-vhosts_1.bats | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 976259b19..c350bbda8 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -116,8 +116,8 @@ The following list config variables have special meaning and can be set in a var | `DOKKU_DOCKERFILE_PORTS` | dockerfile ports | `dokku config:set` | | | `DOKKU_DOCKERFILE_START_CMD` | none | `dokku config:set` | | | `DOKKU_PARALLEL_ARGUMENTS`. | none | `dokku config:set` | Allows passing custom arguments to parallel for `ps:*all` commands | -| `DOKKU_PROXY_PORT` | automatically assigned | `dokku config:set` | | -| `DOKKU_PROXY_SSL_PORT` | automatically assigned | `dokku config:set` | | +| `DOKKU_PROXY_PORT` | automatically assigned | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*`
`dokku config:set` | | +| `DOKKU_PROXY_SSL_PORT` | automatically assigned | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*`
`dokku config:set` | | | `DOKKU_PROXY_PORT_MAP` | automatically assigned | `dokku proxy:ports-add`
`dokku proxy:ports-remove`, `dokku proxy:ports-clear` | | | `DOKKU_SKIP_ALL_CHECKS` | none | `dokku config:set` | | | `DOKKU_SKIP_CLEANUP` | | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | When a deploy is triggered, if this is set to a non-empty value, then old docker containers and images will not be removed. | diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index a76f0ca82..9dc232772 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -96,13 +96,15 @@ configure_nginx_ports() { dokku_log_info1 "no proxy port set. setting to random open high port" local PROXY_PORT=$(get_available_port) else - local PROXY_PORT=80 + local PROXY_PORT=$(config_get --global DOKKU_PROXY_PORT) + PROXY_PORT=${PROXY_PORT:=80} fi DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT="$PROXY_PORT" fi if [[ -z "$DOKKU_PROXY_SSL_PORT" ]]; then if (is_ssl_enabled "$APP"); then - local PROXY_SSL_PORT=443 + local PROXY_SSL_PORT=$(config_get --global DOKKU_PROXY_SSL_PORT) + PROXY_SSL_PORT=${PROXY_SSL_PORT:=443} if [[ -z "$RAW_TCP_PORTS" ]] && [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then dokku_log_info1 "no proxy ssl port set. setting to random open high port" PROXY_SSL_PORT=$(get_available_port) diff --git a/tests/unit/20_nginx-vhosts_1.bats b/tests/unit/20_nginx-vhosts_1.bats index c71d9bc55..c63ab2764 100644 --- a/tests/unit/20_nginx-vhosts_1.bats +++ b/tests/unit/20_nginx-vhosts_1.bats @@ -141,3 +141,14 @@ teardown() { echo "status: "$status assert_success } + +@test "(nginx-vhosts) nginx:build-config (global DOKKU_PROXY_PORT)" { + local GLOBAL_PORT=30999 + run /bin/bash -c "dokku config:set --global DOKKU_PROXY_PORT=${GLOBAL_PORT}" + + deploy_app + check_urls http://${TEST_APP}.dokku.me:${GLOBAL_PORT} + assert_http_success http://${TEST_APP}.dokku.me:${GLOBAL_PORT} + + run /bin/bash -c "dokku config:unset --global DOKKU_PROXY_PORT" +}