refactor: split out proxy port configuration into it's own trigger
This will allow it to be called by plugins other than the nginx-vhosts one.
This commit is contained in:
@@ -1842,6 +1842,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `proxy-configure-ports`
|
||||
|
||||
- Description: Configures the proxy port mapping
|
||||
- Invoked by: `internally triggered by proxy plugins`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `proxy-disable`
|
||||
|
||||
- Description: Disables the configured proxy implementation for an app
|
||||
|
||||
@@ -155,62 +155,6 @@ nginx_logs() {
|
||||
tail "$NGINX_LOGS_ARGS" "$NGINX_LOGS_PATH"
|
||||
}
|
||||
|
||||
configure_nginx_ports() {
|
||||
declare desc="configure nginx listening ports"
|
||||
local APP=$1
|
||||
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
||||
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=true
|
||||
local UPSTREAM_PORT="5000"
|
||||
plugn trigger domains-vhost-enabled "$APP" 2>/dev/null || IS_APP_VHOST_ENABLED=false
|
||||
|
||||
if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
|
||||
if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
|
||||
dokku_log_info1 "No proxy port set, setting to random open high port"
|
||||
local PROXY_PORT=$(get_available_port)
|
||||
else
|
||||
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=$(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)
|
||||
fi
|
||||
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$PROXY_SSL_PORT"
|
||||
fi
|
||||
fi
|
||||
if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then
|
||||
if [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
local RAW_TCP_PORT
|
||||
for RAW_TCP_PORT in $RAW_TCP_PORTS; do
|
||||
local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} "
|
||||
done
|
||||
else
|
||||
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 "$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
|
||||
local PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)"
|
||||
local PROXY_PORT_MAP+=" $(merge_dedupe_list "$(remove_val_from_list "$PORT_MAP" "$DOKKU_PROXY_PORT_MAP" " ")" " ") "
|
||||
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT_MAP="$PROXY_PORT_MAP"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
validate_ssl_domains() {
|
||||
declare desc="check configured domains against SSL cert contents and show warning if mismatched"
|
||||
local APP=$1
|
||||
@@ -384,7 +328,7 @@ nginx_build_config() {
|
||||
fi
|
||||
|
||||
# setup nginx listen ports
|
||||
configure_nginx_ports "$APP"
|
||||
plugn trigger proxy-configure-ports "$APP"
|
||||
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)
|
||||
|
||||
1
plugins/proxy/.gitignore
vendored
1
plugins/proxy/.gitignore
vendored
@@ -6,3 +6,4 @@
|
||||
/install
|
||||
/post-*
|
||||
/report
|
||||
!/proxy-configure-ports
|
||||
|
||||
65
plugins/proxy/proxy-configure-ports
Executable file
65
plugins/proxy/proxy-configure-ports
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/certs/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-proxy-proxy-configure-ports() {
|
||||
declare desc="proxy proxy-configure-ports plugin trigger"
|
||||
declare trigger="proxy-configure-ports"
|
||||
declare APP="$1"
|
||||
local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")"
|
||||
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=true
|
||||
local UPSTREAM_PORT="5000"
|
||||
|
||||
plugn trigger domains-vhost-enabled "$APP" 2>/dev/null || IS_APP_VHOST_ENABLED=false
|
||||
|
||||
if [[ -z "$DOKKU_PROXY_PORT" ]] && [[ -z "$RAW_TCP_PORTS" ]]; then
|
||||
if [[ "$IS_APP_VHOST_ENABLED" == "false" ]]; then
|
||||
dokku_log_info1 "No proxy port set, setting to random open high port"
|
||||
local PROXY_PORT=$(get_available_port)
|
||||
else
|
||||
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=$(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)
|
||||
fi
|
||||
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_SSL_PORT="$PROXY_SSL_PORT"
|
||||
fi
|
||||
fi
|
||||
if [[ -z "$DOKKU_PROXY_PORT_MAP" ]]; then
|
||||
if [[ -n "$RAW_TCP_PORTS" ]]; then
|
||||
local RAW_TCP_PORT
|
||||
for RAW_TCP_PORT in $RAW_TCP_PORTS; do
|
||||
local PROXY_PORT_MAP+=" http:${RAW_TCP_PORT}:${RAW_TCP_PORT} "
|
||||
done
|
||||
else
|
||||
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 "$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
|
||||
local PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)"
|
||||
local PROXY_PORT_MAP+=" $(merge_dedupe_list "$(remove_val_from_list "$PORT_MAP" "$DOKKU_PROXY_PORT_MAP" " ")" " ") "
|
||||
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_PROXY_PORT_MAP="$PROXY_PORT_MAP"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
trigger-proxy-proxy-configure-ports "$@"
|
||||
Reference in New Issue
Block a user