refactor: allow custom nginx command to be set as an nginx property
This avoids adding a new environment variable in favor of a script that can be called both globally as well as on a per-app basis.
This commit is contained in:
@@ -332,6 +332,7 @@ Changing these value globally or on a per-app basis will require rebuilding the
|
|||||||
| keepalive-timeout | `75s` | string | Timeout (with units) during which a keep-alive client connection will stay open on the server side |
|
| keepalive-timeout | `75s` | string | Timeout (with units) during which a keep-alive client connection will stay open on the server side |
|
||||||
| lingering-timeout | `5s` | string | Timeout (with units) is the maximum waiting time for more client data to arrive |
|
| lingering-timeout | `5s` | string | Timeout (with units) is the maximum waiting time for more client data to arrive |
|
||||||
| nginx-conf-sigil-path | `nginx.conf.sigil` | string | Path in the repository to the `nginx.conf.sigil` file |
|
| nginx-conf-sigil-path | `nginx.conf.sigil` | string | Path in the repository to the `nginx.conf.sigil` file |
|
||||||
|
| nginx-service-command | | string | Full path to an executable script or binary to invoke instead of the system's init process when interacting with nginx |
|
||||||
| proxy-buffer-size | `8k` (# is os pagesize) | string | Size of the buffer used for reading the first part of proxied server response |
|
| proxy-buffer-size | `8k` (# is os pagesize) | string | Size of the buffer used for reading the first part of proxied server response |
|
||||||
| proxy-buffering | `on` | string | Enables or disables buffering of responses from the proxied server |
|
| proxy-buffering | `on` | string | Enables or disables buffering of responses from the proxied server |
|
||||||
| proxy-buffers | `8 8k` | string | Number and size of the buffers used for reading the proxied server response, for a single connection |
|
| proxy-buffers | `8 8k` | string | Number and size of the buffers used for reading the proxied server response, for a single connection |
|
||||||
|
|||||||
@@ -327,6 +327,21 @@ fn-nginx-global-nginx-conf-sigil-path() {
|
|||||||
fn-get-property --global "nginx-conf-sigil-path"
|
fn-get-property --global "nginx-conf-sigil-path"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn-nginx-nginx-service-command() {
|
||||||
|
declare APP="$1"
|
||||||
|
fn-get-property --app "$APP" "nginx-service-command"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn-nginx-computed-nginx-service-command() {
|
||||||
|
declare APP="$1"
|
||||||
|
fn-get-property --computed --app "$APP" "nginx-service-command"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn-nginx-global-nginx-service-command() {
|
||||||
|
declare APP="$1"
|
||||||
|
fn-get-property --global "nginx-service-command"
|
||||||
|
}
|
||||||
|
|
||||||
fn-nginx-proxy-buffer-size() {
|
fn-nginx-proxy-buffer-size() {
|
||||||
declare desc="get the configured proxy buffer size"
|
declare desc="get the configured proxy buffer size"
|
||||||
declare APP="$1"
|
declare APP="$1"
|
||||||
@@ -730,8 +745,9 @@ fn-nginx-vhosts-nginx-init-cmd() {
|
|||||||
declare desc="start nginx for given distros"
|
declare desc="start nginx for given distros"
|
||||||
declare CMD="$1"
|
declare CMD="$1"
|
||||||
|
|
||||||
if [[ -n "$DOKKU_NGINX_CUSTOM_CMD" ]]; then
|
local NGINX_SERVICE_COMMAND="$(fn-nginx-computed-nginx-service-command "$APP")"
|
||||||
$DOKKU_NGINX_CUSTOM_CMD $CMD
|
if [[ -n "$NGINX_SERVICE_COMMAND" ]]; then
|
||||||
|
"$NGINX_SERVICE_COMMAND" $CMD
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,36 @@ func AppNginxConfSigilPath(appName string) string {
|
|||||||
return common.PropertyGet("nginx", appName, "nginx-conf-sigil-path")
|
return common.PropertyGet("nginx", appName, "nginx-conf-sigil-path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComputedNginxConfSigilPath(appName string) string {
|
||||||
|
appValue := AppNginxConfSigilPath(appName)
|
||||||
|
if appValue != "" {
|
||||||
|
return appValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return GlobalNginxConfSigilPath()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GlobalNginxConfSigilPath() string {
|
||||||
|
return common.PropertyGetDefault("nginx", "--global", "nginx-conf-sigil-path", "nginx.conf.sigil")
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppNginxServiceCommand(appName string) string {
|
||||||
|
return common.PropertyGet("nginx", appName, "nginx-service-command")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ComputedNginxServiceCommand(appName string) string {
|
||||||
|
appValue := AppNginxServiceCommand(appName)
|
||||||
|
if appValue != "" {
|
||||||
|
return appValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return GlobalNginxServiceCommand()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GlobalNginxServiceCommand() string {
|
||||||
|
return common.PropertyGetDefault("nginx", "--global", "nginx-service-command", "")
|
||||||
|
}
|
||||||
|
|
||||||
func AppKeepaliveTimeout(appName string) string {
|
func AppKeepaliveTimeout(appName string) string {
|
||||||
return common.PropertyGet("nginx", appName, "keepalive-timeout")
|
return common.PropertyGet("nginx", appName, "keepalive-timeout")
|
||||||
}
|
}
|
||||||
@@ -268,19 +298,6 @@ func GlobalLingeringTimeout() string {
|
|||||||
return common.PropertyGetDefault("nginx", "--global", "lingering-timeout", "5s")
|
return common.PropertyGetDefault("nginx", "--global", "lingering-timeout", "5s")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComputedNginxConfSigilPath(appName string) string {
|
|
||||||
appValue := AppNginxConfSigilPath(appName)
|
|
||||||
if appValue != "" {
|
|
||||||
return appValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return GlobalNginxConfSigilPath()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GlobalNginxConfSigilPath() string {
|
|
||||||
return common.PropertyGetDefault("nginx", "--global", "nginx-conf-sigil-path", "nginx.conf.sigil")
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppProxyBufferSize(appName string) string {
|
func AppProxyBufferSize(appName string) string {
|
||||||
return common.PropertyGet("nginx", appName, "proxy-buffer-size")
|
return common.PropertyGet("nginx", appName, "proxy-buffer-size")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ func appValue(appName string, property string) string {
|
|||||||
value = nginx_vhosts.AppLingeringTimeout(appName)
|
value = nginx_vhosts.AppLingeringTimeout(appName)
|
||||||
case "nginx-conf-sigil-path":
|
case "nginx-conf-sigil-path":
|
||||||
value = nginx_vhosts.AppNginxConfSigilPath(appName)
|
value = nginx_vhosts.AppNginxConfSigilPath(appName)
|
||||||
|
case "nginx-service-command":
|
||||||
|
value = nginx_vhosts.AppNginxServiceCommand(appName)
|
||||||
case "proxy-buffer-size":
|
case "proxy-buffer-size":
|
||||||
value = nginx_vhosts.AppProxyBufferSize(appName)
|
value = nginx_vhosts.AppProxyBufferSize(appName)
|
||||||
case "proxy-buffering":
|
case "proxy-buffering":
|
||||||
@@ -133,6 +135,8 @@ func computedValue(appName string, property string) string {
|
|||||||
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
||||||
case "nginx-conf-sigil-path":
|
case "nginx-conf-sigil-path":
|
||||||
value = nginx_vhosts.ComputedNginxConfSigilPath(appName)
|
value = nginx_vhosts.ComputedNginxConfSigilPath(appName)
|
||||||
|
case "nginx-service-command":
|
||||||
|
value = nginx_vhosts.ComputedNginxServiceCommand(appName)
|
||||||
case "proxy-buffer-size":
|
case "proxy-buffer-size":
|
||||||
value = nginx_vhosts.ComputedProxyBufferSize(appName)
|
value = nginx_vhosts.ComputedProxyBufferSize(appName)
|
||||||
case "proxy-buffering":
|
case "proxy-buffering":
|
||||||
@@ -199,6 +203,8 @@ func globalValue(appName string, property string) string {
|
|||||||
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
||||||
case "nginx-conf-sigil-path":
|
case "nginx-conf-sigil-path":
|
||||||
value = nginx_vhosts.GlobalNginxConfSigilPath()
|
value = nginx_vhosts.GlobalNginxConfSigilPath()
|
||||||
|
case "nginx-service-command":
|
||||||
|
value = nginx_vhosts.GlobalNginxServiceCommand()
|
||||||
case "proxy-buffer-size":
|
case "proxy-buffer-size":
|
||||||
value = nginx_vhosts.GlobalProxyBufferSize()
|
value = nginx_vhosts.GlobalProxyBufferSize()
|
||||||
case "proxy-buffering":
|
case "proxy-buffering":
|
||||||
|
|||||||
@@ -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-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
|
local VALID_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
|
||||||
local GLOBAL_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts-include-subdomains" "hsts-max-age" "hsts-preload" "hsts" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
|
local GLOBAL_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts-include-subdomains" "hsts-max-age" "hsts-preload" "hsts" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
|
||||||
|
|
||||||
[[ -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-format, access-log-path, bind-address-ipv4, bind-address-ipv6, client-body-timeout, client-header-timeout, client-max-body-size, disable-custom-config, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, keepalive-timeout, lingering-timeout, nginx-conf-sigil-path, proxy-buffer-size, proxy-buffering, proxy-buffers, proxy-busy-buffers-size, proxy-connect-timeout, proxy-read-timeout, proxy-send-timeout, send-timeout, underscore-in-headers, x-forwarded-for-value, x-forwarded-port-value, x-forwarded-proto-value, x-forwarded-ssl"
|
dokku_log_fail "Invalid key specified, valid keys include: access-log-format, access-log-path, bind-address-ipv4, bind-address-ipv6, client-body-timeout, client-header-timeout, client-max-body-size, disable-custom-config, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, keepalive-timeout, lingering-timeout, nginx-conf-sigil-path, nginx-service-command, proxy-buffer-size, proxy-buffering, proxy-buffers, proxy-busy-buffers-size, proxy-connect-timeout, proxy-read-timeout, proxy-send-timeout, send-timeout, underscore-in-headers, x-forwarded-for-value, x-forwarded-port-value, x-forwarded-proto-value, x-forwarded-ssl"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
|
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
|
||||||
|
|||||||
Reference in New Issue
Block a user