mirror of
https://github.com/dokku/dokku.git
synced 2026-07-11 04:51:57 +02:00
Emitting the restart policy as a `--restart` argument from a `docker-args-process-deploy` trigger exposed a latent gluing bug: proxy and builder triggers concatenated `$STDIN$output` with no separator, and the scheduler and builders appended `docker-args-process-*` output directly onto the older `docker-args-*` output, so adjacent arguments could merge into values like `--restart=on-failure:10--label`. A space is now inserted at both the trigger echo and the concatenation so arguments always stay separated.
221 lines
9.6 KiB
Bash
Executable File
221 lines
9.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/proxy/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/openresty-vhosts/internal-functions"
|
|
|
|
trigger-openresty-vhosts-docker-args-process-deploy() {
|
|
declare desc="openresty-vhosts docker-args-process-deploy plugin trigger"
|
|
declare trigger="docker-args-process-deploy"
|
|
declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE_TAG="$3" PROC_TYPE="$4" CONTAINER_INDEX="$5"
|
|
local include_dir output value DATA
|
|
local STDIN=$(cat)
|
|
|
|
if [[ "$PROC_TYPE" != "web" ]]; then
|
|
return
|
|
fi
|
|
|
|
if [[ "$(plugn trigger proxy-type "$APP")" != "openresty" ]] && [[ "$(plugn trigger proxy-type "$APP")" != "nginx" ]]; then
|
|
return
|
|
fi
|
|
|
|
if [[ "$(plugn trigger proxy-is-enabled "$APP")" != "true" ]]; then
|
|
return
|
|
fi
|
|
|
|
if ! plugn trigger domains-vhost-enabled "$APP" 2>/dev/null; then
|
|
return
|
|
fi
|
|
|
|
# ensure we have a port mapping
|
|
plugn trigger ports-configure "$APP"
|
|
|
|
include_dir="$(fn-openresty-get-http-includes-dir "$APP")"
|
|
if [[ -d "$include_dir" ]]; then
|
|
pushd "$include_dir" >/dev/null
|
|
for filename in *; do
|
|
if [[ ! -f "$include_dir/$filename" ]]; then
|
|
continue
|
|
fi
|
|
|
|
if [[ $filename != *.conf ]]; then
|
|
continue
|
|
fi
|
|
|
|
# check that filename includes only alphanumeric characters, underscores, and dots
|
|
if [[ "$filename" =~ [^a-zA-Z0-9_.-] ]]; then
|
|
dokku_log_warn "Skipping include file with non-alphanumeric characters: $filename"
|
|
continue
|
|
fi
|
|
|
|
# check that filename does not contain any special characters
|
|
if [[ "$filename" =~ [\'\"\ \$\`\(\)\;] ]]; then
|
|
dokku_log_warn "Skipping include file with unsafe filename: $filename"
|
|
continue
|
|
fi
|
|
|
|
DATA="$(base64 -w 0 <"$include_dir/$filename")"
|
|
output="$output '--label=openresty.include-http-$filename=$DATA'"
|
|
done
|
|
popd &>/dev/null || pushd "/tmp" >/dev/null
|
|
fi
|
|
|
|
include_dir="$(fn-openresty-get-location-includes-dir "$APP")"
|
|
if [[ -d "$include_dir" ]]; then
|
|
pushd "$include_dir" >/dev/null
|
|
for filename in *; do
|
|
if [[ ! -f "$include_dir/$filename" ]]; then
|
|
continue
|
|
fi
|
|
|
|
if [[ $filename != *.conf ]]; then
|
|
continue
|
|
fi
|
|
|
|
# check that filename includes only alphanumeric characters, underscores, and dots
|
|
if [[ "$filename" =~ [^a-zA-Z0-9_.-] ]]; then
|
|
dokku_log_warn "Skipping include file with non-alphanumeric characters: $filename"
|
|
continue
|
|
fi
|
|
|
|
# check that filename does not contain any special characters
|
|
if [[ "$filename" =~ [\'\"\ \$\`\(\)\;] ]]; then
|
|
dokku_log_warn "Skipping include file with unsafe filename: $filename"
|
|
continue
|
|
fi
|
|
|
|
DATA="$(base64 -w 0 <"$include_dir/$filename")"
|
|
output="$output '--label=openresty.include-location-http-$filename=$DATA'"
|
|
done
|
|
popd &>/dev/null || pushd "/tmp" >/dev/null
|
|
fi
|
|
|
|
is_app_listening="false"
|
|
local APP_PORT_MAP="$(plugn trigger ports-get "$APP")"
|
|
while IFS= read -r port_map; do
|
|
proxy_scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")"
|
|
proxy_host_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")"
|
|
proxy_container_port="$(awk -F ':' '{ print $3 }' <<<"$port_map")"
|
|
|
|
if [[ "$proxy_scheme" == "http" ]]; then
|
|
is_app_listening="true"
|
|
if [[ -z "$proxy_container_http_port_candidate" ]]; then
|
|
proxy_container_http_port_candidate="$proxy_container_port"
|
|
proxy_host_http_port_candidate="$proxy_host_port"
|
|
fi
|
|
|
|
if [[ "$proxy_host_port" == "80" ]] && [[ -z "$proxy_container_http_port" ]]; then
|
|
proxy_container_http_port="$proxy_container_port"
|
|
fi
|
|
fi
|
|
|
|
if [[ "$proxy_scheme" == "https" ]]; then
|
|
is_app_listening="true"
|
|
if [[ -z "$proxy_container_https_port_candidate" ]]; then
|
|
proxy_container_https_port_candidate="$proxy_container_port"
|
|
proxy_host_https_port_candidate="$proxy_host_port"
|
|
fi
|
|
|
|
if [[ "$proxy_host_port" == "443" ]] && [[ -z "$proxy_container_https_port" ]]; then
|
|
proxy_container_https_port="$proxy_container_port"
|
|
fi
|
|
fi
|
|
done <<<"$APP_PORT_MAP"
|
|
|
|
if [[ -n "$letsencrypt_email" ]] && [[ -z "$proxy_container_https_port" ]]; then
|
|
proxy_container_https_port_candidate="$proxy_container_http_port_candidate"
|
|
proxy_host_https_port_candidate="$proxy_host_http_port_candidate"
|
|
if [[ -n "$proxy_container_http_port" ]]; then
|
|
proxy_container_https_port_candidate="$proxy_container_http_port"
|
|
proxy_host_http_port_candidate=443
|
|
fi
|
|
fi
|
|
|
|
letsencrypt_value="false"
|
|
if [[ -n "$(fn-openresty-computed-letsencrypt-email)" ]]; then
|
|
if [[ -n "$proxy_container_https_port" ]] || [[ -n "$proxy_container_https_port_candidate" ]]; then
|
|
letsencrypt_value="true"
|
|
fi
|
|
fi
|
|
|
|
output="$output '--label=openresty.letsencrypt=$letsencrypt_value'"
|
|
|
|
value="$(fn-openresty-computed-access-log-format "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.access-log-format=$value'"
|
|
value="$(fn-openresty-computed-access-log-path "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.access-log-path=$value'"
|
|
value="$(fn-openresty-computed-bind-address-ipv4 "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.bind-address-ipv4=$value'"
|
|
value="$(fn-openresty-computed-bind-address-ipv6 "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.bind-address-ipv6=$value'"
|
|
value="$(fn-openresty-computed-client-body-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.client-body-timeout=$value'"
|
|
value="$(fn-openresty-computed-client-header-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.client-header-timeout=$value'"
|
|
value="$(fn-openresty-computed-client-max-body-size "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.client-max-body-size=$value'"
|
|
value="$(fn-openresty-computed-error-log-path "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.error-log-path=$value'"
|
|
value="$(fn-openresty-computed-hsts-include-subdomains "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.hsts-include-subdomains=$value'"
|
|
value="$(fn-openresty-computed-hsts-max-age "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.hsts-max-age=$value'"
|
|
value="$(fn-openresty-computed-hsts-preload "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.hsts-preload=$value'"
|
|
value="$(fn-openresty-hsts-is-enabled "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.hsts=$value'"
|
|
value="443"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.https-port=$value'"
|
|
value="$(plugn trigger domains-list "$APP" | xargs)"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.domains=$value'"
|
|
value="$(plugn trigger network-get-property "$APP" initial-network)"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.initial-network=$value'"
|
|
value="$(fn-openresty-computed-keepalive-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.keepalive-timeout=$value'"
|
|
value="$(fn-openresty-computed-lingering-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.lingering-timeout=$value'"
|
|
value="$(echo "$APP_PORT_MAP" | xargs)"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.port-mapping=$value'"
|
|
value="$(fn-openresty-computed-proxy-buffer-size "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-buffer-size=$value'"
|
|
value="$(fn-openresty-computed-proxy-buffering "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-buffering=$value'"
|
|
value="$(fn-openresty-computed-proxy-buffers "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-buffers=$value'"
|
|
value="$(fn-openresty-computed-proxy-busy-buffers-size "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-busy-buffer-size=$value'"
|
|
value="$(fn-openresty-computed-proxy-connect-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-connect-timeout=$value'"
|
|
value="$(fn-openresty-computed-proxy-read-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-read-timeout=$value'"
|
|
value="$(fn-openresty-computed-proxy-send-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.proxy-send-timeout=$value'"
|
|
value="$(fn-openresty-computed-send-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.send-timeout=$value'"
|
|
value="$(fn-openresty-computed-send-timeout "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.send-timeout=$value'"
|
|
value="$(fn-openresty-computed-underscore-in-headers "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.underscore-in-headers=$value'"
|
|
value="$(fn-openresty-computed-x-forwarded-for-value "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.x-forwarded-for-value=$value'"
|
|
value="$(fn-openresty-computed-x-forwarded-port-value "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.x-forwarded-port-value=$value'"
|
|
value="$(fn-openresty-computed-x-forwarded-proto-value "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.x-forwarded-proto-value=$value'"
|
|
value="$(fn-openresty-computed-x-forwarded-ssl "$APP")"
|
|
[[ -n "$value" ]] && output="$output '--label=openresty.x-forwarded-ssl=$value'"
|
|
|
|
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "openresty" "$APP")
|
|
if [[ -f "$proxy_labels_file_path" ]]; then
|
|
while read -r line; do
|
|
[[ -z "$line" ]] && continue
|
|
output="$output --label '$line'"
|
|
done <"$proxy_labels_file_path"
|
|
fi
|
|
|
|
echo -n "$STDIN $output"
|
|
}
|
|
|
|
trigger-openresty-vhosts-docker-args-process-deploy "$@"
|