Merge pull request #5467 from dokku/5049-wait-to-retire
Move DOKKU_WAIT_TO_RETIRE to a checks property
This commit is contained in:
19
plugins/checks/checks-get-property
Executable file
19
plugins/checks/checks-get-property
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/internal-functions"
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-checks-checks-get-property() {
|
||||
declare desc="return the value for an app's checks property"
|
||||
declare trigger="checks-get-property"
|
||||
declare APP="$1" KEY="$2"
|
||||
|
||||
if [[ "$KEY" == "wait-to-retire" ]]; then
|
||||
fn-checks-computed-wait-to-retire "$APP"
|
||||
return
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
trigger-checks-checks-get-property "$@"
|
||||
@@ -2,8 +2,15 @@
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
migrate_checks_vars_0_29_0() {
|
||||
declare desc="migrates deprecated DOKKU_WAIT_TO_RETIRE config variables to property counter part introduced in 0.29.x"
|
||||
|
||||
fn-migrate-config-to-property "checks" "wait-to-retire" "DOKKU_WAIT_TO_RETIRE" "DOKKU_WAIT_TO_RETIRE"
|
||||
}
|
||||
|
||||
migrate_checks_vars_0_5_0() {
|
||||
declare desc="migrates deprecated CHECKS config variables to simplified counter part introduced in 0.5.x"
|
||||
local GLOBAL_SKIP_ALL_CHECKS=$(config_get --global DOKKU_SKIP_ALL_CHECKS || true)
|
||||
@@ -54,8 +61,10 @@ trigger-checks-install() {
|
||||
declare desc="installs the checks plugin"
|
||||
declare trigger="install"
|
||||
|
||||
fn-plugin-property-setup "checks"
|
||||
migrate_checks_vars_0_5_0 "$@"
|
||||
migrate_checks_vars_0_6_0 "$@"
|
||||
migrate_checks_vars_0_29_0 "$@"
|
||||
}
|
||||
|
||||
trigger-checks-install "$@"
|
||||
|
||||
@@ -37,6 +37,9 @@ cmd-checks-report-single() {
|
||||
local flag_map=(
|
||||
"--checks-disabled-list: $(fn-checks-disabled-list "$APP")"
|
||||
"--checks-skipped-list: $(fn-checks-skipped-list "$APP")"
|
||||
"--checks-computed-wait-to-retire: $(fn-checks-computed-wait-to-retire "$APP")"
|
||||
"--checks-global-wait-to-retire: $(fn-checks-global-wait-to-retire "$APP")"
|
||||
"--checks-wait-to-retire: $(fn-checks-wait-to-retire "$APP")"
|
||||
)
|
||||
|
||||
if [[ -z "$INFO_FLAG" ]]; then
|
||||
@@ -80,3 +83,26 @@ fn-checks-skipped-list() {
|
||||
DOKKU_CHECKS_SKIPPED="${DOKKU_CHECKS_SKIPPED:-none}"
|
||||
echo "$DOKKU_CHECKS_SKIPPED"
|
||||
}
|
||||
|
||||
fn-checks-computed-wait-to-retire() {
|
||||
declare APP="$1"
|
||||
|
||||
file="$(fn-checks-wait-to-retire "$APP")"
|
||||
if [[ "$file" == "" ]]; then
|
||||
file="$(fn-checks-global-wait-to-retire "$APP")"
|
||||
fi
|
||||
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
fn-checks-global-wait-to-retire() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "checks" "--global" "wait-to-retire" "60"
|
||||
}
|
||||
|
||||
fn-checks-wait-to-retire() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "checks" "$APP" "wait-to-retire" ""
|
||||
}
|
||||
|
||||
37
plugins/checks/subcommands/set
Executable file
37
plugins/checks/subcommands/set
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-checks-set() {
|
||||
declare desc="set or clear a checks property for an app"
|
||||
declare cmd="checks:set"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" KEY="$2" VALUE="$3"
|
||||
local VALID_KEYS=("wait-to-retire")
|
||||
[[ "$APP" == "--global" ]] || verify_app_name "$APP"
|
||||
|
||||
[[ -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: wait-to-retire"
|
||||
fi
|
||||
|
||||
if [[ -n "$VALUE" ]]; then
|
||||
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
|
||||
fn-plugin-property-write "checks" "$APP" "$KEY" "$VALUE"
|
||||
else
|
||||
dokku_log_info2_quiet "Unsetting ${KEY}"
|
||||
if [[ "$KEY" == "rev-env-var" ]]; then
|
||||
fn-plugin-property-write "checks" "$APP" "$KEY" "$VALUE"
|
||||
else
|
||||
fn-plugin-property-delete "checks" "$APP" "$KEY"
|
||||
if [[ "$KEY" == "enabled" ]]; then
|
||||
fn-plugin-property-destroy "checks" "$APP"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-checks-set "$@"
|
||||
@@ -1143,3 +1143,35 @@ suppress_output() {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fn-migrate-config-to-property() {
|
||||
declare desc="migrates deprecated config variables to property counterpart"
|
||||
declare PLUGIN="$1" KEY="$2" CONFIG_VAR="$3" GLOBAL_CONFIG_VAR="$4"
|
||||
|
||||
# todo: refactor to remove config_unset usage
|
||||
if ! declare -f -F config_unset >/dev/null; then
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
fi
|
||||
|
||||
if ! declare -f -F fn-plugin-property-write >/dev/null; then
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||
fi
|
||||
|
||||
if [[ -n "$GLOBAL_CONFIG_VAR" ]]; then
|
||||
local value=$(plugn trigger config-get-global "$GLOBAL_CONFIG_VAR" || true)
|
||||
if [[ -n "$value" ]]; then
|
||||
dokku_log_info1 "Migrating deprecated global $GLOBAL_CONFIG_VAR to $PLUGIN $KEY property."
|
||||
fn-plugin-property-write "$PLUGIN" --global "$KEY" "$value"
|
||||
DOKKU_QUIET_OUTPUT=1 config_unset --global "$GLOBAL_CONFIG_VAR" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
for app in $(dokku_apps "false"); do
|
||||
local value=$(plugn trigger config-get "$app" "$CONFIG_VAR" || true)
|
||||
if [[ -n "$value" ]]; then
|
||||
dokku_log_info1 "Migrating deprecated $CONFIG_VAR to $PLUGIN $KEY property for $app."
|
||||
fn-plugin-property-write "$PLUGIN" "$app" "$KEY" "$value"
|
||||
DOKKU_QUIET_OUTPUT=1 config_unset --no-restart "$app" "$CONFIG_VAR" || true
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -37,13 +37,8 @@ trigger-scheduler-docker-local-scheduler-deploy() {
|
||||
|
||||
DOKKU_START_CMD="$(config_get "$APP" DOKKU_START_CMD || true)"
|
||||
|
||||
if [[ -z "$DOKKU_WAIT_TO_RETIRE" ]]; then
|
||||
local DOKKU_APP_DOKKU_WAIT_TO_RETIRE=$(config_get "$APP" DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE=$(config_get --global DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_WAIT_TO_RETIRE=${DOKKU_APP_DOKKU_WAIT_TO_RETIRE:="$DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE"}
|
||||
fi
|
||||
|
||||
export DOKKU_WAIT_TO_RETIRE="${DOKKU_WAIT_TO_RETIRE:-60}"
|
||||
local DOKKU_WAIT_TO_RETIRE="$(plugn trigger checks-get-property "$APP" wait-to-retire)"
|
||||
export DOKKU_WAIT_TO_RETIRE
|
||||
|
||||
local TMP_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
||||
trap "rm -rf '$TMP_FILE' >/dev/null" RETURN INT TERM
|
||||
|
||||
Reference in New Issue
Block a user