diff --git a/Makefile b/Makefile index 190879c4e..bc8a65931 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,15 @@ go-build: fi ;\ done + +go-build-plugin: +ifndef PLUGIN_NAME + $(error PLUGIN_NAME not specified) +endif + if [ -e plugins/$(PLUGIN_NAME)/Makefile ]; then \ + $(MAKE) -e -C plugins/$(PLUGIN_NAME) $(PLUGIN_MAKE_TARGET) || exit $$? ;\ + fi + go-clean: basedir=$(PWD); \ for dir in plugins/*; do \ diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 5a3cf8345..79d4fc32b 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1105,6 +1105,22 @@ APP="$1"; HOSTNAME=$(hostname -s) mail -s "$APP containers on $HOSTNAME failed to retire" ops@example.com ``` +### `report` + +- Description: Allows you to report on any custom configuration in use by your application +- Invoked by: `dokku report` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1"; + +# TODO +``` + ### `scheduler-deploy` - Description: Allows you to run scheduler commands when an app is deployed diff --git a/plugins/00_dokku-standard/subcommands/report b/plugins/00_dokku-standard/subcommands/report index b940d67e1..ce5badb20 100755 --- a/plugins/00_dokku-standard/subcommands/report +++ b/plugins/00_dokku-standard/subcommands/report @@ -5,6 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_report_cmd() { declare desc="reports dokku vitals for troubleshooting" local cmd="report" + declare APP="$2" dokku_log_info1 "uname: $(uname -a)" dokku_log_info1 "memory: " @@ -19,6 +20,10 @@ dokku_report_cmd() { dokku_log_info1 "dokku version: $(dokku version)" dokku_log_info1 "dokku plugins: " dokku plugin:list | sed "s/^/ /" + + if [[ -n "$APP" ]]; then + plugn trigger report "$APP" + fi } dokku_report_cmd "$@" diff --git a/plugins/apps/internal-functions b/plugins/apps/internal-functions index 252d68a5d..741334949 100755 --- a/plugins/apps/internal-functions +++ b/plugins/apps/internal-functions @@ -1,6 +1,81 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/apps/functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-apps-report() { + declare desc="displays the app report for one or more apps" + local cmd="apps:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-apps-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-apps-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-apps-report-single() { + declare APP="$1" INFO_FLAG="$2" + local APP_DIR="$DOKKU_ROOT/$APP" + local use_echo; + if [[ "$INFO_FLAG" == "true" ]]; then + use_echo=true + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--app-dir: $APP_DIR" + "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" + "--deploy-source: $(: | plugn trigger deploy-source "$APP")" + "--locked: $(apps_is_locked "$APP")" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP app information" + if (is_deployed "$APP"); then + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" + done + else + if [[ "$use_echo" ]]; then + echo "not deployed" + else + dokku_log_fail "not deployed" + fi + fi + 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + apps_help_content_func() { declare desc="return apps plugin help content" diff --git a/plugins/apps/report b/plugins/apps/report new file mode 100755 index 000000000..ef68b67a0 --- /dev/null +++ b/plugins/apps/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-apps-report-single "$@" diff --git a/plugins/apps/subcommands/report b/plugins/apps/subcommands/report index bb3484987..02bf6ff5b 100755 --- a/plugins/apps/subcommands/report +++ b/plugins/apps/subcommands/report @@ -1,83 +1,5 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - local use_echo; - if [[ "$INFO_FLAG" == "true" ]]; then - use_echo=true - INFO_FLAG="" - fi - verify_app_name "$APP" - local flag_map=( - "--app-dir: $APP_DIR" - "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" - "--deploy-source: $(: | plugn trigger deploy-source "$APP")" - "--locked: $(apps_is_locked "$APP")" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP app information" - if (is_deployed "$APP"); then - for flag in "${flag_map[@]}"; do - key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" - dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")" - done - else - if [[ "$use_echo" ]]; then - echo "not deployed" - else - dokku_log_fail "not deployed" - fi - fi - 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 -} - -apps_report_cmd() { - declare desc="displays the app report for one or more apps" - local cmd="apps:report" - local INSTALLED_APPS=$(dokku_apps) - local APP="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -apps_report_cmd "$@" +cmd-apps-report "$@" diff --git a/plugins/certs/internal-functions b/plugins/certs/internal-functions index 77f4f0c79..864f07351 100755 --- a/plugins/certs/internal-functions +++ b/plugins/certs/internal-functions @@ -1,7 +1,73 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/certs/functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-certs-report() { + declare desc="displays an ssl report for one or more apps" + local cmd="certs:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-certs-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-certs-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-certs-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--ssl-dir: $DOKKU_ROOT/$APP/tls" + "--ssl-enabled: $(fn-ssl-enabled "$APP")" + "--ssl-hostnames: $(fn-ssl-hostnames "$APP")" + "--ssl-expires-at: $(fn-ssl-expires-at "$APP")" + "--ssl-issuer: $(fn-ssl-issuer "$APP")" + "--ssl-starts-at: $(fn-ssl-starts-at "$APP")" + "--ssl-subject: $(fn-ssl-subject "$APP")" + "--ssl-verified: $(fn-ssl-verified "$APP")" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP ssl information" + 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; 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} certs_help_content_func() { declare desc="return certs plugin help content" @@ -69,3 +135,74 @@ certs_info_cmd() { dokku_log_info1 "$APP does not have an SSL endpoint" fi } + +fn-ssl-enabled() { + declare APP="$1" + local SSL_ENABLED=false + + if is_ssl_enabled "$APP"; then + SSL_ENABLED=true + fi + echo "$SSL_ENABLED" +} + +fn-ssl-expires-at() { + declare APP="$1" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + + if is_ssl_enabled "$APP"; then + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }' + fi +} + +fn-ssl-hostnames() { + declare APP="$1" + + if is_ssl_enabled "$APP"; then + get_ssl_hostnames "$APP" | xargs + fi +} + +fn-ssl-issuer() { + declare APP="$1" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + + if is_ssl_enabled "$APP"; then + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g" + fi +} + +fn-ssl-starts-at() { + declare APP="$1" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + + if is_ssl_enabled "$APP"; then + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }' + fi +} + +fn-ssl-subject() { + declare APP="$1" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + + if is_ssl_enabled "$APP"; then + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g" + fi +} + +fn-ssl-verified() { + declare APP="$1" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + local SSL_VERIFY_OUTPUT=false SSL_SELF_SIGNED="self signed" + + if ! is_ssl_enabled "$APP"; then + return + fi + + SSL_VERIFY_OUTPUT="$(openssl verify -verbose -purpose sslserver "$APP_SSL_PATH/server.crt" | awk -F ':' '{ print $2 }' | tail -1 | xargs || true)" + if [[ "$SSL_VERIFY_OUTPUT" == "OK" ]]; then + SSL_SELF_SIGNED="verified by a certificate authority" + fi + + echo "$SSL_SELF_SIGNED" +} diff --git a/plugins/certs/report b/plugins/certs/report new file mode 100755 index 000000000..be3d9b76e --- /dev/null +++ b/plugins/certs/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-certs-report-single "$@" diff --git a/plugins/certs/subcommands/report b/plugins/certs/subcommands/report index 27bf32b7d..b85fd69a2 100755 --- a/plugins/certs/subcommands/report +++ b/plugins/certs/subcommands/report @@ -1,147 +1,5 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/certs/functions" -fn-ssl-enabled() { - declare APP="$1" - local SSL_ENABLED=false - - if is_ssl_enabled "$APP"; then - SSL_ENABLED=true - fi - echo "$SSL_ENABLED" -} - -fn-ssl-expires-at() { - declare APP="$1" - local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - - if is_ssl_enabled "$APP"; then - openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }' - fi -} - -fn-ssl-hostnames() { - declare APP="$1" - - if is_ssl_enabled "$APP"; then - get_ssl_hostnames "$APP" | xargs - fi -} - -fn-ssl-issuer() { - declare APP="$1" - local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - - if is_ssl_enabled "$APP"; then - openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g" - fi -} - -fn-ssl-starts-at() { - declare APP="$1" - local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - - if is_ssl_enabled "$APP"; then - openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }' - fi -} - -fn-ssl-subject() { - declare APP="$1" - local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - - if is_ssl_enabled "$APP"; then - openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g" - fi -} - -fn-ssl-verified() { - declare APP="$1" - local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - local SSL_VERIFY_OUTPUT=false SSL_SELF_SIGNED="self signed" - - if ! is_ssl_enabled "$APP"; then - return - fi - - SSL_VERIFY_OUTPUT="$(openssl verify -verbose -purpose sslserver "$APP_SSL_PATH/server.crt" | awk -F ':' '{ print $2 }' | tail -1 | xargs || true)" - if [[ "$SSL_VERIFY_OUTPUT" == "OK" ]]; then - SSL_SELF_SIGNED="verified by a certificate authority" - fi - - echo "$SSL_SELF_SIGNED" -} - -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - if [[ "$INFO_FLAG" == "true" ]]; then - INFO_FLAG="" - fi - verify_app_name "$APP" - local flag_map=( - "--ssl-dir: $APP_DIR/tls" - "--ssl-enabled: $(fn-ssl-enabled "$APP")" - "--ssl-hostnames: $(fn-ssl-hostnames "$APP")" - "--ssl-expires-at: $(fn-ssl-expires-at "$APP")" - "--ssl-issuer: $(fn-ssl-issuer "$APP")" - "--ssl-starts-at: $(fn-ssl-starts-at "$APP")" - "--ssl-subject: $(fn-ssl-subject "$APP")" - "--ssl-verified: $(fn-ssl-verified "$APP")" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP ssl 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 -} - -certs_report_cmd() { - declare desc="displays an ssl report for one or more apps" - local cmd="certs:report" - local INSTALLED_APPS=$(dokku_apps) - local APP="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -certs_report_cmd "$@" +cmd-certs-report "$@" diff --git a/plugins/checks/internal-functions b/plugins/checks/internal-functions index d0ebad465..6cd3219a2 100755 --- a/plugins/checks/internal-functions +++ b/plugins/checks/internal-functions @@ -1,6 +1,67 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/checks/functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-checks-report() { + declare desc="shows reports for an app" + local cmd="checks:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-checks-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-checks-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-checks-report-single() { + declare APP="$1" 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_quiet "$APP checks information" + 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; 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} checks_help_content_func() { declare desc="return checks plugin help content" @@ -30,3 +91,19 @@ checks_help_cmd() { help_desc fi } + +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" +} diff --git a/plugins/checks/report b/plugins/checks/report new file mode 100755 index 000000000..1d08a5830 --- /dev/null +++ b/plugins/checks/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/checks/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-checks-report-single "$@" diff --git a/plugins/checks/subcommands/report b/plugins/checks/subcommands/report index 4aae64f80..c70362f87 100755 --- a/plugins/checks/subcommands/report +++ b/plugins/checks/subcommands/report @@ -1,86 +1,5 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/checks/internal-functions" 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" -} - -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - 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_quiet "$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="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -checks_report_cmd "$@" +cmd-checks-report "$@" diff --git a/plugins/docker-options/internal-functions b/plugins/docker-options/internal-functions new file mode 100755 index 000000000..b73e7e421 --- /dev/null +++ b/plugins/docker-options/internal-functions @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-docker-options-report() { + declare desc="displays a docker options report for one or more apps" + local cmd="docker-options:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-docker-options-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-docker-options-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-docker-options-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--docker-options-build: $(fn-docker-options "$APP" build)" + "--docker-options-deploy: $(fn-docker-options "$APP" deploy)" + "--docker-options-run: $(fn-docker-options "$APP" run)" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP docker options information" + 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; 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + +fn-docker-options() { + declare APP="$1" PHASE="$2" + local PHASE_FILE="$(fn-get-phase-file-path "$APP" "$PHASE")" + if [[ -r "$PHASE_FILE" ]]; then + tr '\n' ' ' < "$PHASE_FILE" + fi +} diff --git a/plugins/docker-options/report b/plugins/docker-options/report new file mode 100755 index 000000000..b83b2df2f --- /dev/null +++ b/plugins/docker-options/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/docker-options/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-docker-options-report-single "$@" diff --git a/plugins/docker-options/subcommands/report b/plugins/docker-options/subcommands/report index 2a30dbe7c..4cb6cefbc 100755 --- a/plugins/docker-options/subcommands/report +++ b/plugins/docker-options/subcommands/report @@ -1,79 +1,5 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/docker-options/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" -fn-docker-options() { - declare APP="$1" PHASE="$2" - local PHASE_FILE="$(fn-get-phase-file-path "$APP" "$PHASE")" - if [[ -r "$PHASE_FILE" ]]; then - tr '\n' ' ' < "$PHASE_FILE" - fi -} - -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - if [[ "$INFO_FLAG" == "true" ]]; then - INFO_FLAG="" - fi - verify_app_name "$APP" - local flag_map=( - "--docker-options-build: $(fn-docker-options "$APP" build)" - "--docker-options-deploy: $(fn-docker-options "$APP" deploy)" - "--docker-options-run: $(fn-docker-options "$APP" run)" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP docker options 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 -} - -docker_options_report_cmd() { - declare desc="displays a docker options report for one or more apps" - local cmd="docker-options:report" - local INSTALLED_APPS=$(dokku_apps) - local APP="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -docker_options_report_cmd "$@" +cmd-docker-options-report "$@" diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions index fb4ab8fce..b5043d213 100755 --- a/plugins/domains/internal-functions +++ b/plugins/domains/internal-functions @@ -1,6 +1,70 @@ #!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/domains/functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +cmd-domains-report() { + declare desc="displays a domains report for one or more apps" + local cmd="domains:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-domains-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-domains-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-domains-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--domains-app-enabled: $(fn-domains-app-enabled "$APP")" + "--domains-app-vhosts: $(fn-domains-app-vhosts "$APP")" + "--domains-global-enabled: $(fn-domains-global-enabled)" + "--domains-global-vhosts: $(fn-domains-global-vhosts)" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP domains information" + 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; 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + domains_help_content_func () { declare desc="return domains plugin help content" cat</dev/null | sort -t . -k 2 -n | xargs)" + local CONTAINER_FILE + local DOKKU_APP_RESTORE=$(config_get "$APP" DOKKU_APP_RESTORE || true) + local STATUSES=() + if [[ "$DOKKU_APP_RESTORE" != 0 ]]; then RESTORE="true"; else RESTORE="false"; fi + local APP_CONTAINER_STATUS + for CONTAINER_FILE in $CONTAINER_FILES; do + CID=$(< "$DOKKU_ROOT/$APP/$CONTAINER_FILE") + APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$CID" 2> /dev/null || true) + [[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="missing" + STATUSES+=("${CONTAINER_FILE#*.}:$APP_CONTAINER_STATUS#${CID:0:12}") + done + local flag_map=( + "--processes: $PROCS" + "--deployed: $DEPLOYED" + "--running: $RUNNING" + "--restore: $RESTORE" + "--restart-policy: $RESTARTPOLICY" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP ps information" + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" + done + for STATUS in "${STATUSES[@]}"; do + name=${STATUS%:*} + value=${STATUS#*:} + status=${value%#*} + cid=${value#*#} + dokku_log_verbose "$(printf "%-30s %-10s (CID: %s)" "Status $name:" "$status" "$cid")" + done + else + local match=false; local value_exists=false + for STATUS in "${STATUSES[@]}"; do + name=${STATUS%:*} + value=${STATUS#*:} + status=${value%#*} + cid=${value#*#} + status_flag="--status-$name" + flag_map+=("$status_flag: $status") + done + 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 +} diff --git a/plugins/ps/report b/plugins/ps/report new file mode 100755 index 000000000..d7bbce270 --- /dev/null +++ b/plugins/ps/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-ps-report-single "$@" diff --git a/plugins/ps/subcommands/report b/plugins/ps/subcommands/report index 941201317..88d64b5c1 100755 --- a/plugins/ps/subcommands/report +++ b/plugins/ps/subcommands/report @@ -1,122 +1,5 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" -source "$PLUGIN_AVAILABLE_PATH/ps/functions" -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - [[ "$INFO_FLAG" == "true" ]] && INFO_FLAG="" - - local passed_phases="deploy" - local APP_CIDS=$(get_app_container_ids "$APP"); local PROCS=0; local RUNNING="" - - for CID in $APP_CIDS; do - if (is_container_status "$CID" "Running"); then - RUNNING+="0" - else - RUNNING+="1" - fi - PROCS=$((PROCS + 1)) - done - - if [[ "${#RUNNING}" -eq 0 ]] || [[ "${#RUNNING}" -ne 0 ]] && [[ "$RUNNING" != *"0"* ]]; then - RUNNING="false" - elif [[ "$RUNNING" != *"1"* ]] && [[ "${#RUNNING}" -ne 0 ]]; then - RUNNING="true"; - else - RUNNING="mixed" - fi - - if (is_deployed "$APP"); then DEPLOYED="true"; else DEPLOYED="false"; fi - RESTARTPOLICY=$(get_restart_policies "$(get_phase_file_path "$passed_phases")" || true) - - local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 2 -n | xargs)" - local CONTAINER_FILE - local DOKKU_APP_RESTORE=$(config_get "$APP" DOKKU_APP_RESTORE || true) - local STATUSES=() - if [[ "$DOKKU_APP_RESTORE" != 0 ]]; then RESTORE="true"; else RESTORE="false"; fi - local APP_CONTAINER_STATUS - for CONTAINER_FILE in $CONTAINER_FILES; do - CID=$(< "$DOKKU_ROOT/$APP/$CONTAINER_FILE") - APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$CID" 2> /dev/null || true) - [[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="missing" - STATUSES+=("${CONTAINER_FILE#*.}:$APP_CONTAINER_STATUS#${CID:0:12}") - done - local flag_map=( - "--processes: $PROCS" - "--deployed: $DEPLOYED" - "--running: $RUNNING" - "--restore: $RESTORE" - "--restart-policy: $RESTARTPOLICY" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP process information" - for flag in "${flag_map[@]}"; do - key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" - dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")" - done - for STATUS in "${STATUSES[@]}"; do - name=${STATUS%:*} - value=${STATUS#*:} - status=${value%#*} - cid=${value#*#} - dokku_log_verbose "$(printf "%-20s %-10s (CID: %s)" "Status $name" "$status" "$cid")" - done - else - local match=false; local value_exists=false - for STATUS in "${STATUSES[@]}"; do - name=${STATUS%:*} - value=${STATUS#*:} - status=${value%#*} - cid=${value#*#} - status_flag="--status-$name" - flag_map+=("$status_flag: $status") - done - 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 -} - -ps_report_cmd() { - declare desc="shows reports for an app" - local cmd="ps:report" - local INSTALLED_APPS=$(dokku_apps) - local APP="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -ps_report_cmd "$@" +cmd-ps-report "$@" diff --git a/plugins/storage/internal-functions b/plugins/storage/internal-functions index 6224e4966..edbfdfcab 100755 --- a/plugins/storage/internal-functions +++ b/plugins/storage/internal-functions @@ -1,8 +1,77 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/storage/functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-storage-report() { + declare desc="displays a storage report for one or more apps" + local cmd="storage:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-storage-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-storage-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-storage-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--storage-build-mounts: $(fn-storage-bind-mounts "$APP" build)" + "--storage-deploy-mounts: $(fn-storage-bind-mounts "$APP" deploy)" + "--storage-run-mounts: $(fn-storage-bind-mounts "$APP" run)" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "$APP storage information" + 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; 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 + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + +fn-storage-bind-mounts() { + declare APP="$1" PHASE="$2" + local PHASE_FILE="$(fn-get-phase-file-path "$APP" "$PHASE")" + if [[ -r "$PHASE_FILE" ]]; then + sed -e '/^-v/!d' "$PHASE_FILE" | tr '\n' ' ' + fi +} storage_help_content_func() { declare desc="return storage plugin help content" diff --git a/plugins/storage/report b/plugins/storage/report new file mode 100755 index 000000000..0b7c7f98a --- /dev/null +++ b/plugins/storage/report @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/storage/internal-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-storage-report-single "$@" diff --git a/plugins/storage/subcommands/report b/plugins/storage/subcommands/report index 445ffec4a..36798f90c 100755 --- a/plugins/storage/subcommands/report +++ b/plugins/storage/subcommands/report @@ -1,79 +1,5 @@ #!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/storage/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" -fn-storage-bind-mounts() { - declare APP="$1" PHASE="$2" - local PHASE_FILE="$(fn-get-phase-file-path "$APP" "$PHASE")" - if [[ -r "$PHASE_FILE" ]]; then - sed -e '/^-v/!d' "$PHASE_FILE" | tr '\n' ' ' - fi -} - -report_single_app() { - declare APP="$1" INFO_FLAG="$2" - local APP_DIR="$DOKKU_ROOT/$APP" - if [[ "$INFO_FLAG" == "true" ]]; then - INFO_FLAG="" - fi - verify_app_name "$APP" - local flag_map=( - "--storage-build-mounts: $(fn-storage-bind-mounts "$APP" build)" - "--storage-deploy-mounts: $(fn-storage-bind-mounts "$APP" deploy)" - "--storage-run-mounts: $(fn-storage-bind-mounts "$APP" run)" - ) - - if [[ -z "$INFO_FLAG" ]]; then - dokku_log_info2_quiet "$APP storage 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 -} - -storage_report_cmd() { - declare desc="displays a storage report for one or more apps" - local cmd="storage:report" - local INSTALLED_APPS=$(dokku_apps) - local APP="$2" INFO_FLAG="$3" - - if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then - INFO_FLAG="$APP" - APP="" - fi - - if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then - INFO_FLAG="true" - fi - - if [[ -z "$APP" ]]; then - for app in $INSTALLED_APPS; do - report_single_app "$app" "$INFO_FLAG" | tee || true - done - else - report_single_app "$APP" "$INFO_FLAG" - fi -} - -storage_report_cmd "$@" +cmd-storage-report "$@"