From 7095eac05232109ce315b8db67a7e98b00f4fac3 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 10:14:19 +0930 Subject: [PATCH 01/10] migrate env for NGINX_* to PROXY_* --- plugins/nginx-vhosts/functions | 19 +++++++++++++++++++ plugins/nginx-vhosts/install | 4 ++++ plugins/nginx-vhosts/subcommands/migrate | 13 +++++++++++++ .../nginx-vhosts/templates/nginx.conf.sigil | 4 ++-- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 plugins/nginx-vhosts/subcommands/migrate diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 9edfd99da..809694085 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -348,3 +348,22 @@ nginx_build_config() { fi fi } + +# @TODO: Remove this after a few versions +migrate_nginx_to_proxy() { + declare desc="migrates DOKKU_NGINX_* to DOKKI_PROXY_*" + for app in $(dokku_apps); do + local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" + local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" + if [[ -n "$nginx_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" + config_unset --no-restart "$app" DOKKU_NGINX_PORT + fi + if [[ -n "$nginx_ssl_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_SSL_PORT to DOKKU_PROXY_SSL_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_SSL_PORT="$nginx_ssl_port" + config_unset --no-restart "$app" DOKKU_NGINX_SSL_PORT + fi + done +} diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 0d7513208..58a92da26 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -1,5 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/config/functions" case "$DOKKU_DISTRO" in debian) @@ -73,6 +75,8 @@ cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/500-error.html" "${DOKK # patch broken nginx 1.8.0 logrotate [[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/invoke-rc.d/service/g' /etc/logrotate.d/nginx +migrate_nginx_to_proxy + case "$DOKKU_DISTRO" in debian) NGINX_INIT="/usr/sbin/invoke-rc.d" diff --git a/plugins/nginx-vhosts/subcommands/migrate b/plugins/nginx-vhosts/subcommands/migrate new file mode 100644 index 000000000..36cc089b4 --- /dev/null +++ b/plugins/nginx-vhosts/subcommands/migrate @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" + +nginx_migrate_cmd() { + declare desc="converts DOKKU_NGINX_* to DOKKI_PROXY_*" + local cmd="nginx:migrate" + migrate_nginx_to_proxy +} + +nginx_migrate_cmd diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index c05ed954d..3f2036fdf 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -12,7 +12,7 @@ server { access_log /var/log/nginx/{{ $.APP }}-access.log; error_log /var/log/nginx/{{ $.APP }}-error.log; {{ if (and (eq $listen_port "80") ($.SSL_INUSE)) }} - return 301 https://$host:{{ $.NGINX_SSL_PORT }}$request_uri; + return 301 https://$host:{{ $.PROXY_SSL_PORT }}$request_uri; {{ else }} location / { @@ -69,7 +69,7 @@ server { ssl_prefer_server_ciphers on; keepalive_timeout 70; - {{ if and (eq $.SPDY_SUPPORTED "true") (ne $.HTTP2_SUPPORTED "true") }}add_header Alternate-Protocol {{ $.NGINX_SSL_PORT }}:npn-spdy/2;{{ end }} + {{ if and (eq $.SPDY_SUPPORTED "true") (ne $.HTTP2_SUPPORTED "true") }}add_header Alternate-Protocol {{ $.PROXY_SSL_PORT }}:npn-spdy/2;{{ end }} location / { From 4c3a0801f72de4544a67e07200f1e720209a56ef Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 10:59:07 +0930 Subject: [PATCH 02/10] fix review and switch DOKKU_NGINX to DOKKU_PROXY in scripts/docs --- docs/configuration/domains.md | 2 +- docs/configuration/nginx.md | 6 +++--- docs/configuration/ssl.md | 4 ++-- plugins/nginx-vhosts/functions | 20 ++++++++++---------- plugins/nginx-vhosts/install | 3 +-- plugins/nginx-vhosts/post-certs-remove | 2 +- plugins/nginx-vhosts/post-certs-update | 12 ++++++------ plugins/nginx-vhosts/pre-disable-vhost | 2 +- plugins/nginx-vhosts/pre-enable-vhost | 2 +- plugins/nginx-vhosts/subcommands/migrate | 13 ------------- 10 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 plugins/nginx-vhosts/subcommands/migrate diff --git a/docs/configuration/domains.md b/docs/configuration/domains.md index e04817f58..c2a8b17dd 100644 --- a/docs/configuration/domains.md +++ b/docs/configuration/domains.md @@ -51,7 +51,7 @@ If desired, it is possible to disable vhosts with the domains plugin. dokku domains:disable myapp ``` -On subsequent deploys, the nginx virtualhost will be discarded. This is useful when deploying internal-facing services that should not be publicly routeable. As of 0.4.0, nginx will still be configured to proxy your app on some random high port. This allows internal services to maintain the same port between deployments. You may change this port by setting `DOKKU_NGINX_PORT` and/or `DOKKU_NGINX_SSL_PORT` (for services configured to use SSL.) +On subsequent deploys, the nginx virtualhost will be discarded. This is useful when deploying internal-facing services that should not be publicly routeable. As of 0.4.0, nginx will still be configured to proxy your app on some random high port. This allows internal services to maintain the same port between deployments. You may change this port by setting `DOKKU_PROXY_PORT` and/or `DOKKU_PROXY_SSL_PORT` (for services configured to use SSL.) The domains plugin allows you to specify custom domains for applications. This plugin is aware of any ssl certificates that are imported via `certs:add`. Be aware that disabling domains (with `domains:disable`) will override any custom domains. diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index 1d673f9cd..cff65f187 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -30,8 +30,8 @@ Dokku uses a templating library by the name of [sigil](https://github.com/glider {{ .APP_SSL_PATH }} Path to SSL certificate and key {{ .DOKKU_ROOT }} Global Dokku root directory (ex: app dir would be `{{ .DOKKU_ROOT }}/{{ .APP }}`) {{ .DOKKU_APP_LISTENERS }} List of IP:PORT pairs of app containers -{{ .NGINX_PORT }} Non-SSL nginx listener port (same as `DOKKU_NGINX_PORT` config var) -{{ .NGINX_SSL_PORT }} SSL nginx listener port (same as `DOKKU_NGINX_SSL_PORT` config var) +{{ .PROXY_PORT }} Non-SSL nginx listener port (same as `DOKKU_PROXY_PORT` config var) +{{ .PROXY_SSL_PORT }} SSL nginx listener port (same as `DOKKU_PROXY_SSL_PORT` config var) {{ .NOSSL_SERVER_NAME }} List of non-SSL VHOSTS {{ .PROXY_PORT_MAP }} List of port mappings (same as `DOKKU_PROXY_PORT_MAP` config var) {{ .PROXY_UPSTREAM_PORTS }} List of configured upstream ports (derived from `DOKKU_PROXY_PORT_MAP` config var) @@ -46,7 +46,7 @@ Dokku uses a templating library by the name of [sigil](https://github.com/glider The default nginx.conf template will include everything from your apps `nginx.conf.d/` subdirectory in the main `server {}` block (see above): -```go +``` include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf; ``` diff --git a/docs/configuration/ssl.md b/docs/configuration/ssl.md index 5d2651218..321d9bc4a 100644 --- a/docs/configuration/ssl.md +++ b/docs/configuration/ssl.md @@ -129,8 +129,8 @@ If your server runs behind an HTTP/S load balancer, then Nginx will see all requ ```go server { - listen [::]:{{ .NGINX_PORT }}; - listen {{ .NGINX_PORT }}; + listen [::]:{{ .PROXY_PORT }}; + listen {{ .PROXY_PORT }}; server_name {{ .NOSSL_SERVER_NAME }}; access_log /var/log/nginx/{{ .APP }}-access.log; error_log /var/log/nginx/{{ .APP }}-error.log; diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 809694085..4391af4e9 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -88,29 +88,29 @@ configure_nginx_ports() { declare desc="configure nginx listening ports" local APP=$1; verify_app_name "$APP" local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")" - local DOKKU_NGINX_PORT=$(config_get "$APP" DOKKU_NGINX_PORT) - local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT) + local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) + local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) local IS_APP_VHOST_ENABLED="$(is_app_vhost_enabled "$APP")" local UPSTREAM_PORT="5000" - if [[ -z "$DOKKU_NGINX_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then + if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then dokku_log_info1 "no nginx port set. setting to random open high port" local NGINX_PORT=$(get_available_port) else local NGINX_PORT=80 fi - config_set --no-restart "$APP" DOKKU_NGINX_PORT="$NGINX_PORT" + config_set --no-restart "$APP" DOKKU_PROXY_PORT="$NGINX_PORT" fi - if [[ -z "$DOKKU_NGINX_SSL_PORT" ]]; then + if [[ -z "$DOKKU_PROXY_SSL_PORT" ]]; then if (is_ssl_enabled "$APP"); then local NGINX_SSL_PORT=443 if [[ -z "$RAW_TCP_PORTS" ]] && [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then dokku_log_info1 "no nginx ssl port set. setting to random open high port" NGINX_SSL_PORT=$(get_available_port) fi - config_set --no-restart "$APP" DOKKU_NGINX_SSL_PORT="$NGINX_SSL_PORT" + config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$NGINX_SSL_PORT" fi fi if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then @@ -120,8 +120,8 @@ configure_nginx_ports() { local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} " done else - local NGINX_PORT=${NGINX_PORT:-$DOKKU_NGINX_PORT} - local NGINX_SSL_PORT=${NGINX_SSL_PORT:-$DOKKU_NGINX_SSL_PORT} + local NGINX_PORT=${NGINX_PORT:-$DOKKU_PROXY_PORT} + local NGINX_SSL_PORT=${NGINX_SSL_PORT:-$DOKKU_PROXY_SSL_PORT} [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(< "$DOKKU_ROOT/$APP/PORT.web.1")" if [[ -n "$NGINX_PORT" ]] && [[ -n "$NGINX_SSL_PORT" ]]; then local PROXY_PORT_MAP+=" http:${NGINX_PORT}:$UPSTREAM_PORT https:${NGINX_SSL_PORT}:$UPSTREAM_PORT " @@ -236,8 +236,8 @@ nginx_build_config() { # setup nginx listen ports configure_nginx_ports "$APP" - local NGINX_PORT=$(config_get "$APP" DOKKU_NGINX_PORT) - local NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT) + local NGINX_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) + local NGINX_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) local PORT_MAP diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 58a92da26..dbda02fbe 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -1,7 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" case "$DOKKU_DISTRO" in debian) diff --git a/plugins/nginx-vhosts/post-certs-remove b/plugins/nginx-vhosts/post-certs-remove index ff6518d33..8fa3cac05 100755 --- a/plugins/nginx-vhosts/post-certs-remove +++ b/plugins/nginx-vhosts/post-certs-remove @@ -9,7 +9,7 @@ nginx_post_certs_remove() { local trigger="nginx_post_certs_remove" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - config_unset --no-restart "$APP" DOKKU_NGINX_SSL_PORT + config_unset --no-restart "$APP" DOKKU_PROXY_SSL_PORT # shellcheck disable=SC2046 remove_proxy_ports "$APP" $(filter_app_proxy_ports "$APP" "https" "443") diff --git a/plugins/nginx-vhosts/post-certs-update b/plugins/nginx-vhosts/post-certs-update index 3a391d7b5..a195aced2 100755 --- a/plugins/nginx-vhosts/post-certs-update +++ b/plugins/nginx-vhosts/post-certs-update @@ -9,15 +9,15 @@ nginx_post_certs_update() { local trigger="nginx_post_certs_update" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - local DOKKU_NGINX_PORT=$(config_get "$APP" DOKKU_NGINX_PORT) - local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_NGINX_SSL_PORT) + local DOKKU_NGINX_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) + local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) - if [[ "$DOKKU_NGINX_PORT" == "80" ]]; then - config_unset --no-restart "$APP" DOKKU_NGINX_PORT + if [[ "$DOKKU_PROXY_PORT" == "80" ]]; then + config_unset --no-restart "$APP" DOKKU_PROXY_PORT fi - if [[ "$DOKKU_NGINX_SSL_PORT" == "443" ]]; then - config_unset --no-restart "$APP" DOKKU_NGINX_SSL_PORT + if [[ "$DOKKU_PROXY_SSL_PORT" == "443" ]]; then + config_unset --no-restart "$APP" DOKKU_PROXY_SSL_PORT fi if [[ "$DOKKU_PROXY_PORT_MAP" == *http:80:* ]]; then # shellcheck disable=SC2046 diff --git a/plugins/nginx-vhosts/pre-disable-vhost b/plugins/nginx-vhosts/pre-disable-vhost index 7a65a58b3..e36f16a43 100755 --- a/plugins/nginx-vhosts/pre-disable-vhost +++ b/plugins/nginx-vhosts/pre-disable-vhost @@ -9,7 +9,7 @@ nginx_pre_disable_vhost_trigger() { local trigger="nginx_pre_disable_vhost_trigger" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - config_unset --no-restart "$APP" DOKKU_NGINX_PORT DOKKU_NGINX_SSL_PORT DOKKU_PROXY_PORT_MAP + config_unset --no-restart "$APP" DOKKU_PROXY_PORT DOKKU_NGINX_SSL_PORT DOKKU_PROXY_PORT_MAP fi } diff --git a/plugins/nginx-vhosts/pre-enable-vhost b/plugins/nginx-vhosts/pre-enable-vhost index 0ef752eb4..8d07324b8 100755 --- a/plugins/nginx-vhosts/pre-enable-vhost +++ b/plugins/nginx-vhosts/pre-enable-vhost @@ -9,7 +9,7 @@ nginx_pre_enable_vhost_trigger() { local trigger="nginx_pre_enable_vhost_trigger" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - config_unset --no-restart "$APP" DOKKU_NGINX_PORT DOKKU_NGINX_SSL_PORT DOKKU_PROXY_PORT_MAP + config_unset --no-restart "$APP" DOKKU_PROXY_PORT DOKKU_PROXY_SSL_PORT DOKKU_PROXY_PORT_MAP fi } diff --git a/plugins/nginx-vhosts/subcommands/migrate b/plugins/nginx-vhosts/subcommands/migrate deleted file mode 100644 index 36cc089b4..000000000 --- a/plugins/nginx-vhosts/subcommands/migrate +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/config/functions" -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" - -nginx_migrate_cmd() { - declare desc="converts DOKKU_NGINX_* to DOKKI_PROXY_*" - local cmd="nginx:migrate" - migrate_nginx_to_proxy -} - -nginx_migrate_cmd From 85a7956876efe06675e11bc0687cbf78f1e55b43 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 11:07:07 +0930 Subject: [PATCH 03/10] add last PROXY conversions --- docs/configuration/environment-variables.md | 4 +-- plugins/nginx-vhosts/functions | 36 ++++++++++----------- plugins/nginx-vhosts/post-certs-update | 4 +-- plugins/nginx-vhosts/pre-disable-vhost | 2 +- tests/unit/test_helper.bash | 6 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 77136e82d..7b119b8d1 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -110,8 +110,8 @@ The following list config variables have special meaning and can be set in a var | `DOKKU_DOCKERFILE_ENTRYPOINT` | dockerfile entrypoint | `dokku config:set` | | | `DOKKU_DOCKERFILE_PORTS` | dockerfile ports | `dokku config:set` | | | `DOKKU_DOCKERFILE_START_CMD` | none | `dokku config:set` | | -| `DOKKU_NGINX_PORT` | automatically assigned | `dokku config:set` | | -| `DOKKU_NGINX_SSL_PORT` | automatically assigned | `dokku config:set` | | +| `DOKKU_PROXY_PORT` | automatically assigned | `dokku config:set` | | +| `DOKKU_PROXY_SSL_PORT` | automatically assigned | `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 4391af4e9..f55f68a9c 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -96,21 +96,21 @@ configure_nginx_ports() { if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then - dokku_log_info1 "no nginx port set. setting to random open high port" - local NGINX_PORT=$(get_available_port) + dokku_log_info1 "no proxy port set. setting to random open high port" + local PROXY_PORT=$(get_available_port) else - local NGINX_PORT=80 + local PROXY_PORT=80 fi - config_set --no-restart "$APP" DOKKU_PROXY_PORT="$NGINX_PORT" + 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 NGINX_SSL_PORT=443 + local PROXY_SSL_PORT=443 if [[ -z "$RAW_TCP_PORTS" ]] && [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then - dokku_log_info1 "no nginx ssl port set. setting to random open high port" - NGINX_SSL_PORT=$(get_available_port) + dokku_log_info1 "no proxy ssl port set. setting to random open high port" + PROXY_SSL_PORT=$(get_available_port) fi - config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$NGINX_SSL_PORT" + config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$PROXY_SSL_PORT" fi fi if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then @@ -120,13 +120,13 @@ configure_nginx_ports() { local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} " done else - local NGINX_PORT=${NGINX_PORT:-$DOKKU_PROXY_PORT} - local NGINX_SSL_PORT=${NGINX_SSL_PORT:-$DOKKU_PROXY_SSL_PORT} + local PROXY_PORT=${PROXY_PORT:-$DOKKU_PROXY_PORT} + local PROXY_SSL_PORT=${PROXY_SSL_PORT:-$DOKKU_PROXY_SSL_PORT} [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(< "$DOKKU_ROOT/$APP/PORT.web.1")" - if [[ -n "$NGINX_PORT" ]] && [[ -n "$NGINX_SSL_PORT" ]]; then - local PROXY_PORT_MAP+=" http:${NGINX_PORT}:$UPSTREAM_PORT https:${NGINX_SSL_PORT}:$UPSTREAM_PORT " - elif [[ -n "$NGINX_PORT" ]]; then - local PROXY_PORT_MAP+=" http:${NGINX_PORT}:$UPSTREAM_PORT " + if [[ -n "$PROXY_PORT" ]] && [[ -n "$PROXY_SSL_PORT" ]]; then + local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT https:${PROXY_SSL_PORT}:$UPSTREAM_PORT " + elif [[ -n "$PROXY_PORT" ]]; then + local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT " fi fi if [[ -n "$PROXY_PORT_MAP" ]]; then @@ -236,8 +236,8 @@ nginx_build_config() { # setup nginx listen ports configure_nginx_ports "$APP" - local NGINX_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) - local NGINX_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) + local PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) + local PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) local PORT_MAP @@ -306,7 +306,7 @@ nginx_build_config() { HTTP2_SUPPORTED="$HTTP2_SUPPORTED" DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" - NGINX_PORT="$NGINX_PORT" NGINX_SSL_PORT="$NGINX_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" + PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS") # execute sigil template processing @@ -354,7 +354,7 @@ migrate_nginx_to_proxy() { declare desc="migrates DOKKU_NGINX_* to DOKKI_PROXY_*" for app in $(dokku_apps); do local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" - local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" + local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" if [[ -n "$nginx_port" ]]; then dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" diff --git a/plugins/nginx-vhosts/post-certs-update b/plugins/nginx-vhosts/post-certs-update index a195aced2..53b23c84f 100755 --- a/plugins/nginx-vhosts/post-certs-update +++ b/plugins/nginx-vhosts/post-certs-update @@ -9,8 +9,8 @@ nginx_post_certs_update() { local trigger="nginx_post_certs_update" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - local DOKKU_NGINX_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) - local DOKKU_NGINX_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) + local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) + local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) local DOKKU_PROXY_PORT_MAP=$(config_get "$APP" DOKKU_PROXY_PORT_MAP) if [[ "$DOKKU_PROXY_PORT" == "80" ]]; then diff --git a/plugins/nginx-vhosts/pre-disable-vhost b/plugins/nginx-vhosts/pre-disable-vhost index e36f16a43..0d5d621be 100755 --- a/plugins/nginx-vhosts/pre-disable-vhost +++ b/plugins/nginx-vhosts/pre-disable-vhost @@ -9,7 +9,7 @@ nginx_pre_disable_vhost_trigger() { local trigger="nginx_pre_disable_vhost_trigger" local APP="$1" if [[ "$(get_app_proxy_type "$APP")" == "nginx" ]]; then - config_unset --no-restart "$APP" DOKKU_PROXY_PORT DOKKU_NGINX_SSL_PORT DOKKU_PROXY_PORT_MAP + config_unset --no-restart "$APP" DOKKU_PROXY_PORT DOKKU_PROXY_SSL_PORT DOKKU_PROXY_PORT_MAP fi } diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index ed62dfd52..ee94c70dc 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -277,12 +277,12 @@ server { listen [::]:{{ \$listen_port }}; listen {{ \$listen_port }}; server_name {{ $.NOSSL_SERVER_NAME }} $CUSTOM_TEMPLATE_SSL_DOMAIN; - return 301 https://\$host:{{ $.NGINX_SSL_PORT }}\$request_uri; + return 301 https://\$host:{{ $.PROXY_SSL_PORT }}\$request_uri; } {{ else if eq \$scheme "https"}} server { - listen [::]:{{ $.NGINX_SSL_PORT }} ssl spdy; - listen {{ $.NGINX_SSL_PORT }} ssl spdy; + listen [::]:{{ $.PROXY_SSL_PORT }} ssl spdy; + listen {{ $.PROXY_SSL_PORT }} ssl spdy; {{ if $.SSL_SERVER_NAME }}server_name {{ $.SSL_SERVER_NAME }} $CUSTOM_TEMPLATE_SSL_DOMAIN; {{ end }} {{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }} $CUSTOM_TEMPLATE_SSL_DOMAIN; {{ end }} ssl_certificate {{ $.APP_SSL_PATH }}/server.crt; From d3c9e80fcb942d972e1f77d1bf46127a634cc0ff Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 11:14:18 +0930 Subject: [PATCH 04/10] deprecate usage of NGINX_* in custom config --- plugins/nginx-vhosts/functions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index f55f68a9c..b40863375 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -306,6 +306,8 @@ nginx_build_config() { HTTP2_SUPPORTED="$HTTP2_SUPPORTED" DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" + # @TODO: Remove this after a few versions + NGINX_PORT="$NGINX_PORT" NGINX_SSL_PORT="$NGINX_SSL_PORT" PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS") From dc0404dbf149de086da4e0dfed55b497e65208fc Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 11:54:28 +0930 Subject: [PATCH 05/10] add better logging to nginx migrate and fix indentation --- plugins/nginx-vhosts/functions | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index b40863375..9050ab631 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -354,18 +354,22 @@ nginx_build_config() { # @TODO: Remove this after a few versions migrate_nginx_to_proxy() { declare desc="migrates DOKKU_NGINX_* to DOKKI_PROXY_*" + dokku_log_info1 "Migrating DOKKU_NGINX env variables. The following variables will be migrated" + dokku_log_info2 "DOKKU_NGINX_PORT -> DOKKU_PROXY_PORT" + dokku_log_info2 "DOKKU_NGINX_SSL_PORT -> DOKKU_PROXY_SSL_PORT" for app in $(dokku_apps); do local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" - if [[ -n "$nginx_port" ]]; then - dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" - config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" - config_unset --no-restart "$app" DOKKU_NGINX_PORT - fi - if [[ -n "$nginx_ssl_port" ]]; then - dokku_log_info1 "Migrating DOKKU_NGINX_SSL_PORT to DOKKU_PROXY_SSL_PORT for $app" - config_set --no-restart "$app" DOKKU_PROXY_SSL_PORT="$nginx_ssl_port" - config_unset --no-restart "$app" DOKKU_NGINX_SSL_PORT - fi - done + if [[ -n "$nginx_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" + config_unset --no-restart "$app" DOKKU_NGINX_PORT + fi + if [[ -n "$nginx_ssl_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_SSL_PORT to DOKKU_PROXY_SSL_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_SSL_PORT="$nginx_ssl_port" + config_unset --no-restart "$app" DOKKU_NGINX_SSL_PORT + fi + done + dokku_log_info2 "Migration complete" } From 71bc198cecb4368979171caf789d7b494f5a190f Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 12:02:49 +0930 Subject: [PATCH 06/10] inline nginx migrate function --- plugins/nginx-vhosts/functions | 23 ----------------------- plugins/nginx-vhosts/install | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 9050ab631..3c8b72093 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -350,26 +350,3 @@ nginx_build_config() { fi fi } - -# @TODO: Remove this after a few versions -migrate_nginx_to_proxy() { - declare desc="migrates DOKKU_NGINX_* to DOKKI_PROXY_*" - dokku_log_info1 "Migrating DOKKU_NGINX env variables. The following variables will be migrated" - dokku_log_info2 "DOKKU_NGINX_PORT -> DOKKU_PROXY_PORT" - dokku_log_info2 "DOKKU_NGINX_SSL_PORT -> DOKKU_PROXY_SSL_PORT" - for app in $(dokku_apps); do - local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" - local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" - if [[ -n "$nginx_port" ]]; then - dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" - config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" - config_unset --no-restart "$app" DOKKU_NGINX_PORT - fi - if [[ -n "$nginx_ssl_port" ]]; then - dokku_log_info1 "Migrating DOKKU_NGINX_SSL_PORT to DOKKU_PROXY_SSL_PORT for $app" - config_set --no-restart "$app" DOKKU_PROXY_SSL_PORT="$nginx_ssl_port" - config_unset --no-restart "$app" DOKKU_NGINX_SSL_PORT - fi - done - dokku_log_info2 "Migration complete" -} diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index dbda02fbe..a961cd50a 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" case "$DOKKU_DISTRO" in debian) @@ -74,7 +73,25 @@ cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/500-error.html" "${DOKK # patch broken nginx 1.8.0 logrotate [[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/invoke-rc.d/service/g' /etc/logrotate.d/nginx -migrate_nginx_to_proxy +# @TODO: Remove this after a few versions +dokku_log_info1 "Migrating DOKKU_NGINX env variables. The following variables will be migrated" +dokku_log_info2 "DOKKU_NGINX_PORT -> DOKKU_PROXY_PORT" +dokku_log_info2 "DOKKU_NGINX_SSL_PORT -> DOKKU_PROXY_SSL_PORT" +for app in $(dokku_apps); do + local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" + local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" + if [[ -n "$nginx_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" + config_unset --no-restart "$app" DOKKU_NGINX_PORT + fi + if [[ -n "$nginx_ssl_port" ]]; then + dokku_log_info1 "Migrating DOKKU_NGINX_SSL_PORT to DOKKU_PROXY_SSL_PORT for $app" + config_set --no-restart "$app" DOKKU_PROXY_SSL_PORT="$nginx_ssl_port" + config_unset --no-restart "$app" DOKKU_NGINX_SSL_PORT + fi +done +dokku_log_info2 "Migration complete" case "$DOKKU_DISTRO" in debian) From f054b30086d71b8763c45246d566585c292dd09a Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 3 Jul 2017 12:44:53 +0930 Subject: [PATCH 07/10] fix missing function --- plugins/nginx-vhosts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index a961cd50a..5db3c4c74 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" case "$DOKKU_DISTRO" in debian) From 61f1060c69db21fe73001a4f96ef5c7753f1a2de Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 10 Jul 2017 16:32:53 +0930 Subject: [PATCH 08/10] fix old env being passed --- plugins/nginx-vhosts/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 3c8b72093..fa4718605 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -307,7 +307,7 @@ nginx_build_config() { DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" # @TODO: Remove this after a few versions - NGINX_PORT="$NGINX_PORT" NGINX_SSL_PORT="$NGINX_SSL_PORT" + NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT" PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS") From f48a6e18347d0145fda718416040106d00562b37 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 1 Oct 2017 16:18:33 -0400 Subject: [PATCH 09/10] fix: remove local use in install hook --- plugins/nginx-vhosts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 5db3c4c74..f6b81d296 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -79,8 +79,8 @@ dokku_log_info1 "Migrating DOKKU_NGINX env variables. The following variables wi dokku_log_info2 "DOKKU_NGINX_PORT -> DOKKU_PROXY_PORT" dokku_log_info2 "DOKKU_NGINX_SSL_PORT -> DOKKU_PROXY_SSL_PORT" for app in $(dokku_apps); do - local nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" - local nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" + nginx_port="$(config_get "$app" DOKKU_NGINX_PORT || true)" + nginx_ssl_port="$(config_get "$app" DOKKU_NGINX_SSL_PORT || true)" if [[ -n "$nginx_port" ]]; then dokku_log_info1 "Migrating DOKKU_NGINX_PORT to DOKKU_PROXY_PORT for $app" config_set --no-restart "$app" DOKKU_PROXY_PORT="$nginx_port" From cf45ccb040f134015036fa6ae33c466a5d9237b6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 6 Mar 2018 01:27:46 -0500 Subject: [PATCH 10/10] feat: ignore shellcheck SC2191 --- .stickler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stickler.yml b/.stickler.yml index aa3813b99..1e11ab0ef 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -1,7 +1,7 @@ linters: shellcheck: shell: bash - exclude: SC2034,SC1090 + exclude: SC2034,SC1090,SC2191 golint: files: