mirror of
https://github.com/dokku/dokku.git
synced 2026-07-11 13:01:51 +02:00
The `<plugin>-global-<property>` keys in `:report` output returned the resolved value with the built-in default substituted in, so external tooling could not distinguish a property that had been set globally to the default from one that had never been set. The bare keys for caddy, haproxy, and traefik global-only properties had the same shape. The `global-<property>` keys now hold the raw stored value and are empty when nothing has been set, and a new `computed-<property>` key holds the effective value used at runtime, falling back through the per-app value (where one exists), the global value, and the built-in default. The bare global-only keys for the three proxy plugins are removed in favor of the raw/computed pair. Closes #8631.
209 lines
6.1 KiB
Bash
Executable File
209 lines
6.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/proxy/command-functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/haproxy-vhosts/internal-functions"
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
cmd-haproxy-labels-add() {
|
|
declare desc="adds container label to app for specified proxy"
|
|
declare cmd="haproxy:labels:add"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
cmd-proxy-labels-add "proxy:labels:add" "haproxy" "$@"
|
|
}
|
|
|
|
cmd-haproxy-labels-remove() {
|
|
declare desc="removes container label from app for specified proxy"
|
|
declare cmd="haproxy:labels:remove"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
cmd-proxy-labels-remove "proxy:labels:remove" "haproxy" "$@"
|
|
}
|
|
|
|
cmd-haproxy-labels-show() {
|
|
declare desc="shows container labels for app for specified proxy"
|
|
declare cmd="haproxy:labels:show"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
cmd-proxy-labels-show "proxy:labels:show" "haproxy" "$@"
|
|
}
|
|
|
|
cmd-haproxy-report() {
|
|
declare desc="displays a haproxy report for one or more apps"
|
|
declare cmd="haproxy:report"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
fn-report-parse-args "$@"
|
|
set -- "${REPORT_ARGS[@]}"
|
|
declare APP="${1:-}" INFO_FLAG="${2:-}"
|
|
|
|
if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then
|
|
INFO_FLAG="$APP"
|
|
APP=""
|
|
fi
|
|
|
|
if [[ "$REPORT_IS_GLOBAL" == "true" ]]; then
|
|
APP="--global"
|
|
fi
|
|
|
|
if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then
|
|
INFO_FLAG="true"
|
|
fi
|
|
|
|
if [[ "$APP" == "--global" ]]; then
|
|
cmd-haproxy-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
|
elif [[ -z "$APP" ]]; then
|
|
for app in $(dokku_apps); do
|
|
cmd-haproxy-report-single "$app" "$INFO_FLAG" "$REPORT_FORMAT" | tee || true
|
|
done
|
|
else
|
|
cmd-haproxy-report-single "$APP" "$INFO_FLAG" "$REPORT_FORMAT"
|
|
fi
|
|
}
|
|
|
|
cmd-haproxy-report-single() {
|
|
declare APP="$1" INFO_FLAG="$2" FORMAT="${3:-stdout}"
|
|
if [[ "$INFO_FLAG" == "true" ]]; then
|
|
INFO_FLAG=""
|
|
fi
|
|
if [[ "$APP" != "--global" ]]; then
|
|
verify_app_name "$APP"
|
|
fi
|
|
local flag_map=(
|
|
"--haproxy-computed-image: $(fn-haproxy-computed-image)"
|
|
"--haproxy-computed-letsencrypt-email: $(fn-haproxy-computed-letsencrypt-email)"
|
|
"--haproxy-computed-letsencrypt-server: $(fn-haproxy-computed-letsencrypt-server)"
|
|
"--haproxy-computed-log-level: $(fn-haproxy-computed-log-level)"
|
|
"--haproxy-computed-refresh-conf: $(fn-haproxy-computed-refresh-conf)"
|
|
"--haproxy-global-image: $(fn-haproxy-global-image)"
|
|
"--haproxy-global-letsencrypt-email: $(fn-haproxy-global-letsencrypt-email)"
|
|
"--haproxy-global-letsencrypt-server: $(fn-haproxy-global-letsencrypt-server)"
|
|
"--haproxy-global-log-level: $(fn-haproxy-global-log-level)"
|
|
"--haproxy-global-refresh-conf: $(fn-haproxy-global-refresh-conf)"
|
|
)
|
|
|
|
fn-report-validate-format "$FORMAT" "$INFO_FLAG"
|
|
|
|
if [[ "$FORMAT" == "json" ]]; then
|
|
fn-report-emit-json flag_map "haproxy"
|
|
return
|
|
fi
|
|
|
|
if [[ -z "$INFO_FLAG" ]]; then
|
|
if [[ "$APP" == "--global" ]]; then
|
|
dokku_log_info2_quiet "global haproxy information"
|
|
else
|
|
dokku_log_info2_quiet "${APP} haproxy information"
|
|
fi
|
|
for flag in "${flag_map[@]}"; do
|
|
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
|
|
dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")"
|
|
done
|
|
else
|
|
local match=false
|
|
for flag in "${flag_map[@]}"; do
|
|
valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)"
|
|
if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
|
|
value=${flag#*: }
|
|
size="${#value}"
|
|
if [[ "$size" -ne 0 ]]; then
|
|
echo "$value" && match=true
|
|
else
|
|
match=true
|
|
fi
|
|
fi
|
|
done
|
|
[[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
|
|
fi
|
|
}
|
|
|
|
cmd-haproxy-logs() {
|
|
declare desc="display haproxy logs from command line"
|
|
declare cmd="haproxy:logs"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
local NUM="100" TAIL=false
|
|
|
|
local TEMP=$(getopt -o htn: --long help,tail,num: -n 'dokku haproxy:logs' -- "$@")
|
|
local EXIT_CODE="$?"
|
|
if [[ "$EXIT_CODE" != 0 ]]; then
|
|
fn-haproxy-logs-usage >&2
|
|
exit 1
|
|
fi
|
|
eval set -- "$TEMP"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-t | --tail)
|
|
local TAIL=true
|
|
shift
|
|
;;
|
|
-n | --num)
|
|
local NUM="$2"
|
|
shift 2
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
*) dokku_log_fail "Internal error" ;;
|
|
esac
|
|
done
|
|
|
|
fn-haproxy-logs "$TAIL" "$NUM"
|
|
}
|
|
|
|
cmd-haproxy-show-config() {
|
|
declare desc="display haproxy config"
|
|
declare cmd="haproxy:show-config"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
if ! fn-is-compose-installed; then
|
|
dokku_log_fail "Required docker compose plugin is not installed"
|
|
fi
|
|
|
|
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE"
|
|
cat "$TMP_COMPOSE_FILE"
|
|
}
|
|
|
|
cmd-haproxy-start() {
|
|
declare desc="Starts the haproxy server"
|
|
declare cmd="haproxy:start"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
if ! fn-is-compose-installed; then
|
|
dokku_log_fail "Required docker compose plugin is not installed"
|
|
fi
|
|
|
|
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
fn-plugin-property-write "haproxy" "--global" "proxy-status" "started"
|
|
fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE"
|
|
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-up "haproxy" "$TMP_COMPOSE_FILE"; then
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
cmd-haproxy-stop() {
|
|
declare desc="Stops the haproxy server"
|
|
declare cmd="haproxy:stop"
|
|
[[ "$1" == "$cmd" ]] && shift 1
|
|
|
|
if ! fn-is-compose-installed; then
|
|
dokku_log_fail "Required docker compose plugin is not installed"
|
|
fi
|
|
|
|
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
|
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
|
|
|
|
fn-plugin-property-write "haproxy" "--global" "proxy-status" "stopped"
|
|
fn-haproxy-template-compose-file "$TMP_COMPOSE_FILE"
|
|
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-down "haproxy" "$TMP_COMPOSE_FILE"; then
|
|
return 1
|
|
fi
|
|
}
|