Merge pull request #8493 from dokku/6760-build-empty-nginx-config-when-there-are-no-web-processes
Generate 502 config for apps without web listeners
This commit is contained in:
@@ -306,38 +306,50 @@ nginx_build_config() {
|
||||
local PROXY_BUSY_BUFFERS_SIZE="$(fn-nginx-computed-proxy-busy-buffers-size "$APP")"
|
||||
local PROXY_KEEPALIVE="$(fn-nginx-computed-proxy-keepalive "$APP")"
|
||||
|
||||
if [[ -z "$DOKKU_APP_LISTENERS" ]]; then
|
||||
local NGINX_BIND_ADDRESS_IP4="$(fn-nginx-computed-bind-address-ipv4 "$APP")"
|
||||
local NGINX_BIND_ADDRESS_IP6="$(fn-nginx-computed-bind-address-ipv6 "$APP")"
|
||||
local NGINX_UNDERSCORE_IN_HEADERS="$(fn-nginx-computed-underscore-in-headers "$APP")"
|
||||
local PROXY_X_FORWARDED_FOR="$(fn-nginx-computed-x-forwarded-for-value "$APP")"
|
||||
local PROXY_X_FORWARDED_PORT="$(fn-nginx-computed-x-forwarded-port-value "$APP")"
|
||||
local PROXY_X_FORWARDED_PROTO="$(fn-nginx-computed-x-forwarded-proto-value "$APP")"
|
||||
local PROXY_X_FORWARDED_SSL="$(fn-nginx-computed-x-forwarded-ssl "$APP")"
|
||||
|
||||
if [[ -z "$DOKKU_APP_LISTENERS" ]] && [[ -z "$PASSED_LISTEN_IP_PORT" ]]; then
|
||||
dokku_log_warn_quiet "No web listeners specified for $APP"
|
||||
elif (is_deployed "$APP"); then
|
||||
if [[ "$(plugn trigger network-get-static-listeners "$APP" "web")" == "" ]]; then
|
||||
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
||||
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG" 2>/dev/null)
|
||||
if ! verify_image "$IMAGE" 2>/dev/null; then
|
||||
dokku_log_fail "Missing image for app"
|
||||
fi
|
||||
|
||||
local IS_DEPLOYED_WITH_LISTENERS=false
|
||||
if [[ -n "$DOKKU_APP_LISTENERS" ]] && (is_deployed "$APP"); then
|
||||
IS_DEPLOYED_WITH_LISTENERS=true
|
||||
fi
|
||||
|
||||
if [[ "$IS_DEPLOYED_WITH_LISTENERS" == "true" ]] || { [[ -z "$DOKKU_APP_LISTENERS" ]] && [[ -z "$PASSED_LISTEN_IP_PORT" ]] && [[ -n "$PROXY_PORT_MAP" ]]; }; then
|
||||
if [[ "$IS_DEPLOYED_WITH_LISTENERS" == "true" ]]; then
|
||||
if [[ "$(plugn trigger network-get-static-listeners "$APP" "web")" == "" ]]; then
|
||||
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
||||
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG" 2>/dev/null)
|
||||
if ! verify_image "$IMAGE" 2>/dev/null; then
|
||||
dokku_log_fail "Missing image for app"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
local NGINX_BUILD_CONFIG_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
||||
local NGINX_CONF=$(mktemp --tmpdir="${NGINX_BUILD_CONFIG_TMP_WORK_DIR}" "nginx.conf.XXXXXX")
|
||||
local CUSTOM_NGINX_TEMPLATE="$NGINX_BUILD_CONFIG_TMP_WORK_DIR/$NGINX_TEMPLATE_NAME"
|
||||
trap "rm -rf '$NGINX_CONF' '$NGINX_BUILD_CONFIG_TMP_WORK_DIR' >/dev/null" RETURN INT TERM EXIT
|
||||
|
||||
get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE" 2>/dev/null
|
||||
if [[ -f "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
||||
dokku_log_info1 'Overriding default nginx.conf with detected nginx.conf.sigil'
|
||||
local NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE"
|
||||
local NGINX_TEMPLATE_SOURCE="app-supplied"
|
||||
if [[ "$IS_DEPLOYED_WITH_LISTENERS" == "true" ]]; then
|
||||
local CUSTOM_NGINX_TEMPLATE="$NGINX_BUILD_CONFIG_TMP_WORK_DIR/$NGINX_TEMPLATE_NAME"
|
||||
get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE" 2>/dev/null
|
||||
if [[ -f "$CUSTOM_NGINX_TEMPLATE" ]]; then
|
||||
dokku_log_info1 'Overriding default nginx.conf with detected nginx.conf.sigil'
|
||||
local NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE"
|
||||
local NGINX_TEMPLATE_SOURCE="app-supplied"
|
||||
fi
|
||||
|
||||
eval "$(config_export app "$APP")"
|
||||
fi
|
||||
|
||||
local NGINX_BIND_ADDRESS_IP4="$(fn-nginx-computed-bind-address-ipv4 "$APP")"
|
||||
local NGINX_BIND_ADDRESS_IP6="$(fn-nginx-computed-bind-address-ipv6 "$APP")"
|
||||
local NGINX_UNDERSCORE_IN_HEADERS="$(fn-nginx-computed-underscore-in-headers "$APP")"
|
||||
local PROXY_X_FORWARDED_FOR="$(fn-nginx-computed-x-forwarded-for-value "$APP")"
|
||||
local PROXY_X_FORWARDED_PORT="$(fn-nginx-computed-x-forwarded-port-value "$APP")"
|
||||
local PROXY_X_FORWARDED_PROTO="$(fn-nginx-computed-x-forwarded-proto-value "$APP")"
|
||||
local PROXY_X_FORWARDED_SSL="$(fn-nginx-computed-x-forwarded-ssl "$APP")"
|
||||
|
||||
eval "$(config_export app "$APP")"
|
||||
local SIGIL_PARAMS=(-f "$NGINX_TEMPLATE" APP="$APP" DOKKU_ROOT="$DOKKU_ROOT"
|
||||
NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME"
|
||||
# Deprecated: Remove this after a few versions
|
||||
@@ -382,34 +394,40 @@ nginx_build_config() {
|
||||
PROXY_X_FORWARDED_PROTO="$PROXY_X_FORWARDED_PROTO"
|
||||
PROXY_X_FORWARDED_SSL="$PROXY_X_FORWARDED_SSL")
|
||||
|
||||
while read -r line || [[ -n "$line" ]]; do
|
||||
PROC_TYPE=${line%%=*}
|
||||
LISTENERS="$(plugn trigger network-get-listeners "$APP" "$PROC_TYPE" | xargs)"
|
||||
UPP_PROC_TYPE="${PROC_TYPE^^}"
|
||||
UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}"
|
||||
SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS")
|
||||
done < <(plugn trigger ps-current-scale "$APP")
|
||||
if [[ "$IS_DEPLOYED_WITH_LISTENERS" == "true" ]]; then
|
||||
while read -r line || [[ -n "$line" ]]; do
|
||||
PROC_TYPE=${line%%=*}
|
||||
LISTENERS="$(plugn trigger network-get-listeners "$APP" "$PROC_TYPE" | xargs)"
|
||||
UPP_PROC_TYPE="${PROC_TYPE^^}"
|
||||
UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}"
|
||||
SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS")
|
||||
done < <(plugn trigger ps-current-scale "$APP")
|
||||
|
||||
if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS"
|
||||
if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS"
|
||||
fi
|
||||
|
||||
if grep NGINX_SSL_PORT "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of NGINX_SSL_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_SSL_PORT"
|
||||
fi
|
||||
|
||||
if grep NGINX_PORT "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of NGINX_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_PORT"
|
||||
fi
|
||||
else
|
||||
SIGIL_PARAMS+=(DOKKU_APP_WEB_LISTENERS="")
|
||||
fi
|
||||
|
||||
if grep NGINX_SSL_PORT "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of NGINX_SSL_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_SSL_PORT"
|
||||
fi
|
||||
|
||||
if grep NGINX_PORT "$NGINX_TEMPLATE"; then
|
||||
dokku_log_warn "Deprecated: Usage of NGINX_PORT within nginx.conf.sigil templates is deprecated in favor of PROXY_PORT"
|
||||
fi
|
||||
|
||||
# execute sigil template processing
|
||||
xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<<"$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)"
|
||||
sigil "${SIGIL_PARAMS[@]}" | cat -s >"$NGINX_CONF"
|
||||
|
||||
dokku_log_info1 "Creating $SCHEME nginx.conf"
|
||||
mkdir -p "$DOKKU_ROOT/$APP/nginx.conf.d"
|
||||
mv "$NGINX_CONF" "$DOKKU_ROOT/$APP/nginx.conf"
|
||||
|
||||
fn-nginx-vhosts-manage-hsts "$APP" "$SSL_INUSE"
|
||||
if [[ "$IS_DEPLOYED_WITH_LISTENERS" == "true" ]]; then
|
||||
fn-nginx-vhosts-manage-hsts "$APP" "$SSL_INUSE"
|
||||
fi
|
||||
|
||||
plugn trigger nginx-pre-reload "$APP" "$DOKKU_APP_LISTEN_PORT" "$DOKKU_APP_LISTEN_IP"
|
||||
|
||||
|
||||
25
plugins/nginx-vhosts/post-create
Executable file
25
plugins/nginx-vhosts/post-create
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-nginx-vhosts-post-create() {
|
||||
declare desc="nginx-vhosts post-create trigger"
|
||||
declare trigger="post-create"
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-setup-app "nginx" "$APP"
|
||||
|
||||
if [[ "$(plugn trigger proxy-type "$APP")" != "nginx" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$(fn-plugin-property-get "nginx" "--global" "proxy-status")" == "stopped" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
nginx_build_config "$APP"
|
||||
}
|
||||
|
||||
trigger-nginx-vhosts-post-create "$@"
|
||||
@@ -26,7 +26,7 @@ trigger-nginx-vhosts-proxy-build-config() {
|
||||
rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil"
|
||||
fi
|
||||
else
|
||||
nginx_clear_config "$APP"
|
||||
nginx_build_config "$APP"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ server {
|
||||
}
|
||||
{{ else }}
|
||||
location / {
|
||||
{{ if $.DOKKU_APP_WEB_LISTENERS }}
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1100;
|
||||
@@ -51,6 +52,9 @@ server {
|
||||
proxy_set_header X-Forwarded-Proto {{ $.PROXY_X_FORWARDED_PROTO }};
|
||||
proxy_set_header X-Request-Start $msec;
|
||||
{{ if $.PROXY_X_FORWARDED_SSL }}proxy_set_header X-Forwarded-Ssl {{ $.PROXY_X_FORWARDED_SSL }};{{ end }}
|
||||
{{ else }}
|
||||
return 502;
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};
|
||||
@@ -103,6 +107,7 @@ server {
|
||||
send_timeout {{ $.SEND_TIMEOUT }};
|
||||
|
||||
location / {
|
||||
{{ if $.DOKKU_APP_WEB_LISTENERS }}
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1100;
|
||||
@@ -129,6 +134,9 @@ server {
|
||||
proxy_set_header X-Forwarded-Proto {{ $.PROXY_X_FORWARDED_PROTO }};
|
||||
proxy_set_header X-Request-Start $msec;
|
||||
{{ if $.PROXY_X_FORWARDED_SSL }}proxy_set_header X-Forwarded-Ssl {{ $.PROXY_X_FORWARDED_SSL }};{{ end }}
|
||||
{{ else }}
|
||||
return 502;
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};
|
||||
@@ -159,6 +167,7 @@ server {
|
||||
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
{{ else if eq $scheme "grpc"}}
|
||||
{{ if $.DOKKU_APP_WEB_LISTENERS }}
|
||||
server {
|
||||
{{ if eq $.HTTP2_DIRECTIVE_SUPPORTED "true" }}
|
||||
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }};
|
||||
@@ -179,7 +188,9 @@ server {
|
||||
client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};
|
||||
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
{{ end }}
|
||||
{{ else if eq $scheme "grpcs"}}
|
||||
{{ if $.DOKKU_APP_WEB_LISTENERS }}
|
||||
server {
|
||||
{{ if eq $.HTTP2_DIRECTIVE_SUPPORTED "true" }}
|
||||
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl;
|
||||
@@ -208,6 +219,7 @@ server {
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $.DOKKU_APP_WEB_LISTENERS }}
|
||||
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
|
||||
|
||||
Reference in New Issue
Block a user