refactor: move DOKKU_WAIT_TO_RETIRE to a checks property

This centralizes the property and removes one more dokku-specific property from the app environment variables.

Closes #5049
This commit is contained in:
Jose Diaz-Gonzalez
2022-11-15 23:25:58 -05:00
parent 4749d1529e
commit f5c3b5dc34
10 changed files with 140 additions and 14 deletions

View File

@@ -3,4 +3,8 @@
## Changes
- The output of `run:detached` now uses the container name - eg. `node-js-app.run.1` - vs the container id.
- The ID of `cron` tasks is now base36-encoded instead of base64-encoded.
- The ID of `cron` tasks is now base36-encoded instead of base64-encoded.
## Removals
- The `DOKKU_WAIT_TO_RETIRE` environment variable has been migrated to a `checks` property named `wait-to-retire` and will be ignored if set as an environment variable.

View File

@@ -125,4 +125,3 @@ The following config variables have special meanings and can be set in a variety
| `DOKKU_START_CMD` | none | `dokku config:set` | Command to run instead of `/start $PROC_TYPE` |
| `DOKKU_SYSTEM_GROUP` | `dokku` | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | System group to chown files as. |
| `DOKKU_SYSTEM_USER` | `dokku` | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | System user to chown files as. |
| `DOKKU_WAIT_TO_RETIRE` | `60` | `dokku config:set` | After a successful deploy, the grace period given to old containers before they are stopped/terminated. This is useful for ensuring completion of long-running http connections. |

View File

@@ -22,13 +22,24 @@ You may both create user-defined checks for web processes using a `CHECKS` file,
> - Allow checks from all hostnames: Modify your application to accept a dynamically provided hostname.
> - Specify the domain within the check: See below for further documentation.
## Configuring checks settings
### wait-to-retire
After a successful deploy, the grace period given to old containers before they are stopped/terminated is determined by the value of `wait-to-retire`. This is useful for ensuring completion of long-running HTTP connections.
```shell
dokku checks:set node-js-app wait-to-retire 30
```
Defaults to `60`.
## Configuring check settings using the `config` plugin
There are certain settings that can be configured via environment variables:
- `DOKKU_DEFAULT_CHECKS_WAIT`: (default: `10`) If no user-defined checks are specified - or if the process being checked is not a `web` process - this is the period of time Dokku will wait before checking that a container is still running.
- `DOKKU_DOCKER_STOP_TIMEOUT`: (default: `10`) Configurable grace period given to the `docker stop` command. If a container has not stopped by this time, a `kill -9` signal or equivalent is sent in order to force-terminate the container. Both the `ps:stop` and `apps:destroy` commands *also* respect this value. If not specified, the Docker defaults for the [`docker stop` command](https://docs.docker.com/engine/reference/commandline/stop/) will be used.
- `DOKKU_WAIT_TO_RETIRE`: (default: `60`) After a successful deploy, the grace period given to old containers before they are stopped/terminated. This is useful for ensuring completion of long-running HTTP connections.
The following settings may also be specified in the `CHECKS` file, though are available as environment variables in order to ease application reuse.

View File

@@ -262,6 +262,22 @@ if [[ "$DOKKU_DISABLE_DEPLOY" = "true" ]]; then
fi
```
### `checks-get-property`
- Description: Return the value for an app's checks property
- Invoked by:
- Arguments: `$APP $KEY`
- Example:
```shell
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"; PROPERTY="$2"
# TODO
```
### `commands help` and `commands <PLUGIN_NAME>:help`
- Description: Your plugin should implement a `help` command in your `commands` file to take advantage of this plugin trigger. `commands help` is used by `dokku help` to aggregate all plugins abbreviated `help` output. Implementing `<PLUGIN_NAME>:help` in your `commands` file gives users looking for help, a more detailed output. 'commands help' must be implemented inside the `commands` plugin file. It's recommended that `PLUGIN_NAME:help` be added to the commands file to ensure consistency among community plugins and give you a new avenue to share rich help content with your user.
@@ -869,9 +885,9 @@ fi
### `logs-get-property`
- Description: Fetches a given logs property value
- Description: Return the value for an app's log property
- Invoked by:
- Arguments: `$APP` `$PROPERTY`
- Arguments: `$APP $KEY`
- Example:
```shell
@@ -990,7 +1006,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
### `network-get-property`
- Description: Return the network value for an app's property
- Description: Return the value for an app's network property
- Invoked by: `internally triggered by a deploy`
- Arguments: `$APP $KEY`
- Example:

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $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 "$@"

View File

@@ -4,6 +4,26 @@ set -eo pipefail
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
migrate_checks_vars_0_29_0() {
declare desc="migrates deprecated DOKKU_WAIT_TO_RETIRE config variables to simplified counter part introduced in 0.29.x"
local wait_to_retire=$(config_get --global DOKKU_WAIT_TO_RETIRE || true)
if [[ -n "$wait_to_retire" ]]; then
dokku_log_info1 "Migrating deprecated global DOKKU_WAIT_TO_RETIRE to scheduler-docker-local property."
fn-plugin-property-write "checks" --global "wait-to-retire" "$wait_to_retire"
DOKKU_QUIET_OUTPUT=1 config_unset --global DOKKU_WAIT_TO_RETIRE || true
fi
for app in $(dokku_apps "false"); do
local wait_to_retire=$(config_get "$app" DOKKU_WAIT_TO_RETIRE || true)
if [[ -n "$wait_to_retire" ]]; then
dokku_log_info1 "Migrating deprecated DOKKU_WAIT_TO_RETIRE to scheduler-docker-local property for $app."
fn-plugin-property-write "checks" "$app" "wait-to-retire" "$wait_to_retire"
DOKKU_QUIET_OUTPUT=1 config_unset --no-restart "$app" DOKKU_WAIT_TO_RETIRE || true
fi
done
}
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)

View File

@@ -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
View 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-git-set "$@"

View File

@@ -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

View File

@@ -5,7 +5,7 @@ load test_helper
setup() {
global_setup
create_app
dokku config:set $TEST_APP DOKKU_WAIT_TO_RETIRE=30
dokku checks:set $TEST_APP wait-to-retire=30
}
teardown() {