mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
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:
@@ -327,6 +327,21 @@ fn-nginx-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() {
|
||||
declare desc="get the configured proxy buffer size"
|
||||
declare APP="$1"
|
||||
@@ -730,8 +745,9 @@ fn-nginx-vhosts-nginx-init-cmd() {
|
||||
declare desc="start nginx for given distros"
|
||||
declare CMD="$1"
|
||||
|
||||
if [[ -n "$DOKKU_NGINX_CUSTOM_CMD" ]]; then
|
||||
$DOKKU_NGINX_CUSTOM_CMD $CMD
|
||||
local NGINX_SERVICE_COMMAND="$(fn-nginx-computed-nginx-service-command "$APP")"
|
||||
if [[ -n "$NGINX_SERVICE_COMMAND" ]]; then
|
||||
"$NGINX_SERVICE_COMMAND" $CMD
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
@@ -234,6 +234,36 @@ func AppNginxConfSigilPath(appName string) string {
|
||||
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 {
|
||||
return common.PropertyGet("nginx", appName, "keepalive-timeout")
|
||||
}
|
||||
@@ -268,19 +298,6 @@ func GlobalLingeringTimeout() string {
|
||||
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 {
|
||||
return common.PropertyGet("nginx", appName, "proxy-buffer-size")
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ func appValue(appName string, property string) string {
|
||||
value = nginx_vhosts.AppLingeringTimeout(appName)
|
||||
case "nginx-conf-sigil-path":
|
||||
value = nginx_vhosts.AppNginxConfSigilPath(appName)
|
||||
case "nginx-service-command":
|
||||
value = nginx_vhosts.AppNginxServiceCommand(appName)
|
||||
case "proxy-buffer-size":
|
||||
value = nginx_vhosts.AppProxyBufferSize(appName)
|
||||
case "proxy-buffering":
|
||||
@@ -133,6 +135,8 @@ func computedValue(appName string, property string) string {
|
||||
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
||||
case "nginx-conf-sigil-path":
|
||||
value = nginx_vhosts.ComputedNginxConfSigilPath(appName)
|
||||
case "nginx-service-command":
|
||||
value = nginx_vhosts.ComputedNginxServiceCommand(appName)
|
||||
case "proxy-buffer-size":
|
||||
value = nginx_vhosts.ComputedProxyBufferSize(appName)
|
||||
case "proxy-buffering":
|
||||
@@ -199,6 +203,8 @@ func globalValue(appName string, property string) string {
|
||||
value = nginx_vhosts.ComputedLingeringTimeout(appName)
|
||||
case "nginx-conf-sigil-path":
|
||||
value = nginx_vhosts.GlobalNginxConfSigilPath()
|
||||
case "nginx-service-command":
|
||||
value = nginx_vhosts.GlobalNginxServiceCommand()
|
||||
case "proxy-buffer-size":
|
||||
value = nginx_vhosts.GlobalProxyBufferSize()
|
||||
case "proxy-buffering":
|
||||
|
||||
@@ -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-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 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 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" "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"
|
||||
|
||||
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
|
||||
|
||||
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
|
||||
|
||||
Reference in New Issue
Block a user