feat: add report trigger

This allows users to quickly show the state of any configured application, as well as the state of their server. In doing so, we make it easy for them to provide information necessary for debugging in a single command.
This commit is contained in:
Jose Diaz-Gonzalez
2018-04-07 04:49:21 -04:00
parent a21761d48d
commit 4aac1fd936
34 changed files with 924 additions and 815 deletions

View File

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

View File

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

View File

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

View File

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

5
plugins/apps/report Executable file
View File

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

View File

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

View File

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

5
plugins/certs/report Executable file
View File

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

View File

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

View File

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

5
plugins/checks/report Executable file
View File

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

View File

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

View File

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

5
plugins/docker-options/report Executable file
View File

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

View File

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

View File

@@ -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<<help_content
@@ -34,3 +98,34 @@ domains_help_cmd() {
help_desc
fi
}
fn-domains-app-enabled() {
declare APP="$1"
local DOMAINS_APP_ENABLED=false
if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then
DOMAINS_APP_ENABLED=true
fi
echo "$DOMAINS_APP_ENABLED"
}
fn-domains-app-vhosts() {
declare APP="$1"
local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST"
if [[ -f "$APP_VHOST_FILE" ]]; then
tr '\n' ' ' < "$APP_VHOST_FILE"
fi
}
fn-domains-global-enabled() {
local DOMAINS_GLOBAL_ENABLED=false
if [[ "$(is_global_vhost_enabled)" == "true" ]]; then
DOMAINS_GLOBAL_ENABLED=true
fi
echo "$DOMAINS_GLOBAL_ENABLED"
}
fn-domains-global-vhosts() {
if [[ "$(is_global_vhost_enabled)" == "true" ]]; then
get_global_vhosts | tr '\n' ' '
fi
}

5
plugins/domains/report Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/domains/internal-functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
cmd-domains-report-single "$@"

View File

@@ -1,103 +1,5 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/domains/internal-functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
fn-domains-app-enabled() {
declare APP="$1"
local DOMAINS_APP_ENABLED=false
if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then
DOMAINS_APP_ENABLED=true
fi
echo "$DOMAINS_APP_ENABLED"
}
fn-domains-app-vhosts() {
declare APP="$1"
local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST"
if [[ -f "$APP_VHOST_FILE" ]]; then
tr '\n' ' ' < "$APP_VHOST_FILE"
fi
}
fn-domains-global-enabled() {
local DOMAINS_GLOBAL_ENABLED=false
if [[ "$(is_global_vhost_enabled)" == "true" ]]; then
DOMAINS_GLOBAL_ENABLED=true
fi
echo "$DOMAINS_GLOBAL_ENABLED"
}
fn-domains-global-vhosts() {
if [[ "$(is_global_vhost_enabled)" == "true" ]]; then
get_global_vhosts | 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=(
"--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 "%-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
}
domains_report_cmd() {
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
report_single_app "$app" "$INFO_FLAG" | tee || true
done
else
report_single_app "$APP" "$INFO_FLAG"
fi
}
domains_report_cmd "$@"
cmd-domains-report "$@"

View File

@@ -1,29 +1,52 @@
#!/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-git-report() {
declare desc="Display the configured git status for an application"
declare cmd="git:report" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare APP="$1" INFO_FLAG="$2"
local flag flag_map key match valid_flags value_exists
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$APP"
declare desc="displays a git report for one or more apps"
local cmd="git:report"
local INSTALLED_APPS=$(dokku_apps)
local APP="$2" INFO_FLAG="$3"
flag_map=(
"--git-rev-env-var: $(fn-plugin-property-get "$APP" "rev-env-var" "GIT_REV")"
"--git-deploy-branch: $(fn-plugin-property-get "$APP" "deploy-branch" "master")"
"--git-global-deploy-branch: $(fn-plugin-property-get "--global" "deploy-branch" "master")"
)
if [[ -z "$INFO_FLAG" ]]; then
dokku_log_info2_quiet "${APP} Git Information"
for flag in "${flag_map[@]}"; do
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")"
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-git-report-single "$app" "$INFO_FLAG" | tee || true
done
else
match=false
value_exists=false
cmd-git-report-single "$APP" "$INFO_FLAG"
fi
}
cmd-git-report-single() {
declare APP="$1" INFO_FLAG="$2"
if [[ "$INFO_FLAG" == "true" ]]; then
INFO_FLAG=""
fi
verify_app_name "$APP"
local flag_map=(
"--git-rev-env-var: $(fn-plugin-property-get "git" "$APP" "rev-env-var" "GIT_REV")"
"--git-deploy-branch: $(fn-plugin-property-get "git" "$APP" "deploy-branch" "master")"
"--git-global-deploy-branch: $(fn-plugin-property-get "git" "--global" "deploy-branch" "master")"
)
if [[ -z "$INFO_FLAG" ]]; then
dokku_log_info2_quiet "${APP} git 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

5
plugins/git/report Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/git/internal-functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
cmd-git-report-single "$@"

View File

@@ -5,3 +5,4 @@
/install
/post-create
/post-delete
/report

View File

@@ -3,7 +3,7 @@ include ../../common.mk
GO_ARGS ?= -a
SUBCOMMANDS = subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set
TRIGGERS = triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-create triggers/post-delete
TRIGGERS = triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-create triggers/post-delete triggers/report
build-in-docker: clean
docker run --rm \
-v $$PWD/../..:$(GO_REPO_ROOT) \
@@ -22,7 +22,7 @@ subcommands/%: src/subcommands/*/%.go
go build $(GO_ARGS) -o $@ $<
clean:
rm -rf commands subcommands triggers network-* install post-create post-delete
rm -rf commands subcommands triggers network-* install post-create post-delete report
src-clean:
rm -rf .gitignore src triggers vendor Makefile *.go

View File

@@ -3,7 +3,9 @@ package network
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
@@ -177,3 +179,50 @@ func HasNetworkConfig(appName string) bool {
return common.FileExists(ipfile) && common.FileExists(portfile)
}
// ReportSingleApp is an internal function that displays the app report for one or more apps
func ReportSingleApp(appName, infoFlag string) {
if err := common.VerifyAppName(appName); err != nil {
common.LogFail(err.Error())
}
infoFlags := map[string]string{
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
"--network-listeners": strings.Join(GetListeners(appName), " "),
}
if len(infoFlag) == 0 {
common.LogInfo2Quiet(fmt.Sprintf("%s network information", appName))
for k, v := range infoFlags {
key := common.UcFirst(strings.Replace(strings.TrimPrefix(k, "--"), "-", " ", -1))
common.LogVerbose(fmt.Sprintf("%s%s", Right(fmt.Sprintf("%s:", key), 31, " "), v))
}
return
}
for k, v := range infoFlags {
if infoFlag == k {
fmt.Fprintln(os.Stdout, v)
return
}
}
keys := reflect.ValueOf(infoFlags).MapKeys()
strkeys := make([]string, len(keys))
for i := 0; i < len(keys); i++ {
strkeys[i] = keys[i].String()
}
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
}
func times(str string, n int) (out string) {
for i := 0; i < n; i++ {
out += str
}
return
}
// Right right-pads the string with pad up to len runes
func Right(str string, length int, pad string) string {
return str + times(pad, length-len(str))
}

View File

@@ -2,45 +2,12 @@ package main
import (
"flag"
"fmt"
"os"
"reflect"
"strings"
"github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/network"
)
func reportSingleApp(appName, infoFlag string) {
infoFlags := map[string]string{
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
"--network-listeners": strings.Join(network.GetListeners(appName), " "),
}
if len(infoFlag) == 0 {
common.LogInfo2Quiet(fmt.Sprintf("%s network information", appName))
for k, v := range infoFlags {
key := common.UcFirst(strings.Replace(strings.TrimPrefix(k, "--"), "-", " ", -1))
common.LogVerbose(fmt.Sprintf("%s: %s", key, v))
}
return
}
for k, v := range infoFlags {
if infoFlag == k {
fmt.Fprintln(os.Stdout, v)
return
}
}
keys := reflect.ValueOf(infoFlags).MapKeys()
strkeys := make([]string, len(keys))
for i := 0; i < len(keys); i++ {
strkeys[i] = keys[i].String()
}
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
}
// displays a network report for one or more apps
func main() {
flag.Parse()
@@ -58,10 +25,10 @@ func main() {
return
}
for _, appName := range apps {
reportSingleApp(appName, infoFlag)
network.ReportSingleApp(appName, infoFlag)
}
return
}
reportSingleApp(appName, infoFlag)
network.ReportSingleApp(appName, infoFlag)
}

View File

@@ -0,0 +1,15 @@
package main
import (
"flag"
"github.com/dokku/dokku/plugins/network"
)
// displays a network report for one or more apps
func main() {
flag.Parse()
appName := flag.Arg(0)
network.ReportSingleApp(appName, "")
}

View File

@@ -1,6 +1,79 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/proxy/functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
cmd-proxy-report() {
declare desc="displays a proxy report for one or more apps"
local cmd="proxy: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-proxy-report-single "$app" "$INFO_FLAG" | tee || true
done
else
cmd-proxy-report-single "$APP" "$INFO_FLAG"
fi
}
cmd-proxy-report-single() {
declare APP="$1" INFO_FLAG="$2"
if [[ "$INFO_FLAG" == "true" ]]; then
INFO_FLAG=""
fi
verify_app_name "$APP"
local flag_map=(
"--proxy-enabled: $(fn-proxy-enabled "$APP")"
"--proxy-type: $(get_app_proxy_type "$APP")"
"--proxy-port-map: $(get_app_proxy_port_map "$APP")"
)
if [[ -z "$INFO_FLAG" ]]; then
dokku_log_info2_quiet "$APP proxy 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-proxy-enabled() {
declare APP="$1"
local PROXY_ENABLED=false
if [[ "$(is_app_proxy_enabled "$APP")" == "true" ]]; then
PROXY_ENABLED=true
fi
echo "$PROXY_ENABLED"
}
proxy_help_content_func() {
declare desc="return proxy plugin help content"
cat<<help_content

5
plugins/proxy/report Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/proxy/internal-functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
cmd-proxy-report-single "$@"

View File

@@ -1,81 +1,5 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/proxy/internal-functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/proxy/functions"
fn-proxy-enabled() {
declare APP="$1"
local PROXY_ENABLED=false
if [[ "$(is_app_proxy_enabled "$APP")" == "true" ]]; then
PROXY_ENABLED=true
fi
echo "$PROXY_ENABLED"
}
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=(
"--proxy-enabled: $(fn-proxy-enabled "$APP")"
"--proxy-type: $(get_app_proxy_type "$APP")"
"--proxy-port-map: $(get_app_proxy_port_map "$APP")"
)
if [[ -z "$INFO_FLAG" ]]; then
dokku_log_info2_quiet "$APP proxy 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
}
proxy_report_cmd() {
declare desc="displays a proxy report for one or more apps"
local cmd="proxy: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
}
proxy_report_cmd "$@"
cmd-proxy-report "$@"

120
plugins/ps/internal-functions Executable file
View File

@@ -0,0 +1,120 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
cmd-ps-report() {
declare desc="displays a ps report for one or more apps"
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
cmd-ps-report-single "$app" "$INFO_FLAG" | tee || true
done
else
cmd-ps-report-single "$APP" "$INFO_FLAG"
fi
}
cmd-ps-report-single() {
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 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
}

5
plugins/ps/report Executable file
View File

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

View File

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

View File

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

5
plugins/storage/report Executable file
View File

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

View File

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