From cbcb720228055f84eb02cc24d5f36eb9910d1e97 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 18:04:57 -0700 Subject: [PATCH 1/4] feat: implement checks:report command Refs #2356 --- docs/deployment/zero-downtime-deploys.md | 41 +++++++++++++ plugins/checks/commands | 1 + plugins/checks/subcommands/report | 75 ++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100755 plugins/checks/subcommands/report diff --git a/docs/deployment/zero-downtime-deploys.md b/docs/deployment/zero-downtime-deploys.md index c1b24c9d5..731eb3e4d 100644 --- a/docs/deployment/zero-downtime-deploys.md +++ b/docs/deployment/zero-downtime-deploys.md @@ -6,6 +6,7 @@ checks Show zero-downtime status checks:disable [process-type(s)] Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** checks:enable [process-type(s)] Enable zero-downtime deployment for all processes (or comma-separated process-type list) +checks:report [] [] Displays a checks report for one or more apps checks:run [process-type(s)] Runs zero-downtime checks for all processes (or comma-separated process-type list) checks:skip [process-type(s)] Skip zero-downtime checks for all processes (or comma-separated process-type list) ``` @@ -61,6 +62,46 @@ dokku checks:disable node-js-app worker DOKKU_CHECKS_SKIPPED: web ``` +### Displaying checks reports about an app + +> New as of 0.8.1 + +You can get a report about the app's checks status using the `checks:report` command: + +```shell +dokku checks:report +``` + +``` +=====> search checks information + Checks disabled list: none + Checks skipped list: none +=====> python-sample + Checks disabled list: none + Checks skipped list: none +=====> ruby-sample + Checks disabled list: _all_ + Checks skipped list: none +``` + +You can run the command for a specific app also. + +```shell +dokku checks:report node-js-sample +``` + +``` +=====> node-js-sample checks information + Checks disabled list: none + Checks skipped list: none +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku checks:report node-js-sample --git-sha +``` + ## Customizing Checks If your application needs a longer period to boot up - perhaps to load data into memory, or because of slow boot time - you may also use dokku's `checks` functionality to more precisely check whether an application can serve traffic or not. diff --git a/plugins/checks/commands b/plugins/checks/commands index 5f27055ac..efbfb70ef 100755 --- a/plugins/checks/commands +++ b/plugins/checks/commands @@ -10,6 +10,7 @@ case "$1" in checks , Show zero-downtime status checks:disable [process-type(s)], Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** checks:enable [process-type(s)], Enable zero-downtime deployment for all processes (or comma-separated process-type list) + checks:report [] [], Displays a checks report for one or more apps checks:run [process-type(s)], Runs zero-downtime checks for all processes (or comma-separated process-type list) checks:skip [process-type(s)], Skip zero-downtime checks for all processes (or comma-separated process-type list) help_content diff --git a/plugins/checks/subcommands/report b/plugins/checks/subcommands/report new file mode 100755 index 000000000..e0caf4cdd --- /dev/null +++ b/plugins/checks/subcommands/report @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/checks/functions" + +fn-checks-disabled-list() { + declare APP="$1" + + local DOKKU_CHECKS_DISABLED=$(config_get "$APP" DOKKU_CHECKS_DISABLED) + DOKKU_CHECKS_DISABLED="${DOKKU_CHECKS_DISABLED:-none}" + echo "$DOKKU_CHECKS_DISABLED" +} + +fn-checks-skipped-list() { + declare APP="$1" + + local DOKKU_CHECKS_SKIPPED=$(config_get "$APP" DOKKU_CHECKS_SKIPPED) + DOKKU_CHECKS_SKIPPED="${DOKKU_CHECKS_SKIPPED:-none}" + echo "$DOKKU_CHECKS_SKIPPED" +} + +checks_report_single_app() { + local APP="$1"; local APP_DIR="$DOKKU_ROOT/$APP"; local INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--checks-disabled-list: $(fn-checks-disabled-list "$APP")" + "--checks-skipped-list: $(fn-checks-skipped-list "$APP")" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2 "$APP checks information" + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")" + done + else + local match=false; local value_exists=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 && value_exists=true + else + match=true + fi + fi + done + if [[ "$match" == "true" ]]; then + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + else + dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + fi + fi +} + +checks_report_cmd() { + declare desc="shows reports for an app" + local cmd="checks:report" + local INSTALLED_APPS=$(dokku_apps); local APP + + if [[ -z $2 ]]; then + for APP in $INSTALLED_APPS; do + checks_report_single_app "$APP" "true" + done + else + checks_report_single_app "$2" "$3" + fi +} + +checks_report_cmd "$@" From 3b3eefcb73a8d7602a412546e439bc114b9af149 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 18:06:32 -0700 Subject: [PATCH 2/4] refactor: deprecate the checks command in favor of checks:report --- plugins/checks/commands | 2 +- plugins/checks/subcommands/default | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/checks/commands b/plugins/checks/commands index efbfb70ef..50414215f 100755 --- a/plugins/checks/commands +++ b/plugins/checks/commands @@ -7,7 +7,7 @@ case "$1" in help_content_func () { declare desc="return checks plugin help content" cat<, Show zero-downtime status + checks , [DEPRECATED] Alternative for checks:report checks:disable [process-type(s)], Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** checks:enable [process-type(s)], Enable zero-downtime deployment for all processes (or comma-separated process-type list) checks:report [] [], Displays a checks report for one or more apps diff --git a/plugins/checks/subcommands/default b/plugins/checks/subcommands/default index f1102fb14..783ef3e31 100755 --- a/plugins/checks/subcommands/default +++ b/plugins/checks/subcommands/default @@ -12,6 +12,7 @@ checks_main_cmd() { local APPS="$1" fi + dokku_log_warn "Deprecated: Please use checks:report" dokku_col_log_info1_quiet "App Name" "Proctypes Disabled" "Proctypes Skipped" local app for app in $APPS; do From dd4960f1ce07e286ae8323e29bdaa0e437c27844 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 18:18:44 -0700 Subject: [PATCH 3/4] refactor: move checks:help to internal-functions --- plugins/checks/commands | 24 ++--------------------- plugins/checks/internal-functions | 32 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 22 deletions(-) create mode 100755 plugins/checks/internal-functions diff --git a/plugins/checks/commands b/plugins/checks/commands index 50414215f..0aed38a1b 100755 --- a/plugins/checks/commands +++ b/plugins/checks/commands @@ -1,31 +1,11 @@ #!/usr/bin/env bash [[ " help checks:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/checks/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | checks:help) - help_content_func () { - declare desc="return checks plugin help content" - cat<, [DEPRECATED] Alternative for checks:report - checks:disable [process-type(s)], Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** - checks:enable [process-type(s)], Enable zero-downtime deployment for all processes (or comma-separated process-type list) - checks:report [] [], Displays a checks report for one or more apps - checks:run [process-type(s)], Runs zero-downtime checks for all processes (or comma-separated process-type list) - checks:skip [process-type(s)], Skip zero-downtime checks for all processes (or comma-separated process-type list) -help_content - } - - if [[ $1 = "checks:help" ]] ; then - echo -e 'Usage: dokku checks[:COMMAND]' - echo '' - echo 'Manage zero-downtime settings.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - else - help_content_func - fi + checks_help_cmd "$@" ;; *) diff --git a/plugins/checks/internal-functions b/plugins/checks/internal-functions new file mode 100755 index 000000000..d0ebad465 --- /dev/null +++ b/plugins/checks/internal-functions @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +checks_help_content_func() { + declare desc="return checks plugin help content" + cat<, [DEPRECATED] Alternative for checks:report + checks:disable [process-type(s)], Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** + checks:enable [process-type(s)], Enable zero-downtime deployment for all processes (or comma-separated process-type list) + checks:report [] [], Displays a checks report for one or more apps + checks:run [process-type(s)], Runs zero-downtime checks for all processes (or comma-separated process-type list) + checks:skip [process-type(s)], Skip zero-downtime checks for all processes (or comma-separated process-type list) +help_content +} + +checks_help_cmd() { + if [[ $1 = "checks:help" ]] ; then + echo -e 'Usage: dokku checks[:COMMAND]' + echo '' + echo 'Manage zero-downtime settings.' + echo '' + echo 'Additional commands:' + checks_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + checks_help_content_func + else + cat< Date: Mon, 20 Feb 2017 19:07:10 -0700 Subject: [PATCH 4/4] Correct docs for checks:report [ci skip] --- docs/deployment/zero-downtime-deploys.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/deployment/zero-downtime-deploys.md b/docs/deployment/zero-downtime-deploys.md index 731eb3e4d..69c05730b 100644 --- a/docs/deployment/zero-downtime-deploys.md +++ b/docs/deployment/zero-downtime-deploys.md @@ -76,10 +76,10 @@ dokku checks:report =====> search checks information Checks disabled list: none Checks skipped list: none -=====> python-sample +=====> python-sample checks information Checks disabled list: none Checks skipped list: none -=====> ruby-sample +=====> ruby-sample checks information Checks disabled list: _all_ Checks skipped list: none ``` @@ -99,7 +99,7 @@ dokku checks:report node-js-sample You can pass flags which will output only the value of the specific information you want. For example: ```shell -dokku checks:report node-js-sample --git-sha +dokku checks:report node-js-sample --checks-disabled-list ``` ## Customizing Checks