From 51217521e337dbb0b714d67f5f0abccc1b30a426 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 16:39:43 -0700 Subject: [PATCH 01/22] feat: add certs:report Refs #2356 --- docs/configuration/ssl.md | 55 +++++++++++++ plugins/certs/commands | 1 + plugins/certs/subcommands/report | 136 +++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100755 plugins/certs/subcommands/report diff --git a/docs/configuration/ssl.md b/docs/configuration/ssl.md index 31d8a080f..8e574562b 100644 --- a/docs/configuration/ssl.md +++ b/docs/configuration/ssl.md @@ -9,6 +9,7 @@ certs:add CRT KEY # Add an ssl endpoint to an app. Can al certs:generate DOMAIN # Generate a key and certificate signing request (and self-signed certificate) certs:info # Show certificate information for an ssl endpoint. certs:remove # Remove an SSL Endpoint from an app. +certs:report [] [] # Displays an ssl report for one or more apps certs:update CRT KEY # Update an SSL Endpoint on an app. Can also import from a tarball on stdin ``` @@ -76,6 +77,60 @@ dokku certs:info node-js-app The `certs:remove` command only works on app-specific certificates. It will `rm` the app-specific tls directory, rebuild the nginx configuration, and reload nginx. +### Displaying ssl reports about an app + +> New as of 0.8.1 + +You can get a report about the apps ssl status using the `certs:report` command: + +```shell +dokku certs:report +``` + +``` +=====> node-js-sample + Ssl dir: /home/dokku/node-js-sample/tls + Ssl enabled: true + Ssl hostnames: *.node-js-sample.org node-js-sample.org + Ssl expires at: Oct 5 23:59:59 2019 GMT + Ssl issuer: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO RSA Domain Validation Secure Server CA + Ssl starts at: Oct 5 00:00:00 2016 GMT + Ssl subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.node-js-sample.org + Ssl verified: self signed. +=====> python-sample + Ssl dir: /home/dokku/python-sample/tls + Ssl enabled: false + Ssl hostnames: + Ssl expires at: + Ssl issuer: + Ssl starts at: + Ssl subject: + Ssl verified: +``` + +You can run the command for a specific app also. + +```shell +dokku certs:report node-js-sample +``` + +``` +=====> node-js-sample ssl information + Ssl dir: /home/dokku/node-js-sample/tls + Ssl enabled: true + Ssl hostnames: *.example.org example.org + Ssl expires at: Oct 5 23:59:59 2019 GMT + Ssl issuer: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO RSA Domain Validation Secure Server CA + Ssl starts at: Oct 5 00:00:00 2016 GMT + Ssl subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.example.org + Ssl verified: self signed. +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku certs:report node-js-sample --ssl-enabled +``` ## HSTS Header diff --git a/plugins/certs/commands b/plugins/certs/commands index c34b902c8..550d97f8d 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -14,6 +14,7 @@ case "$1" in certs:info , Show certificate information for an ssl endpoint certs:key CRT KEY [KEY ...], [NOT IMPLEMENTED] Print the correct key for the given certificate certs:remove , Remove an SSL Endpoint from an app + certs:report [] [], Displays an ssl report for one or more apps certs:rollback , [NOT IMPLEMENTED] Rollback an SSL Endpoint for an app certs:update CRT KEY, Update an SSL Endpoint on an app. Can also import from a tarball on stdin help_content diff --git a/plugins/certs/subcommands/report b/plugins/certs/subcommands/report new file mode 100755 index 000000000..6f0e59031 --- /dev/null +++ b/plugins/certs/subcommands/report @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +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 + echo "$(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 + echo "$(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 + echo "$(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 + echo "$(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" +} + +certs_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=( + "--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 "$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 + + if [[ -z $2 ]]; then + for APP in $INSTALLED_APPS; do + certs_report_single_app "$APP" "true" + done + else + certs_report_single_app "$2" "$3" + fi +} + +certs_report_cmd "$@" From dcb88226b5f77c34163c0728e1f69ac30eb63233 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 16:47:14 -0700 Subject: [PATCH 02/22] refactor: ensure that certs:default and certs:info are deprecated in favor of certs:report Refs #2356 --- docs/configuration/ssl.md | 23 +------------------ plugins/certs/functions | 33 --------------------------- plugins/certs/internal-functions | 38 +++++++++++++++++++++++++++++++ plugins/certs/subcommands/default | 12 +++------- plugins/certs/subcommands/info | 4 ++-- 5 files changed, 44 insertions(+), 66 deletions(-) create mode 100755 plugins/certs/internal-functions mode change 100644 => 100755 plugins/certs/subcommands/default diff --git a/docs/configuration/ssl.md b/docs/configuration/ssl.md index 8e574562b..4c9b25e8f 100644 --- a/docs/configuration/ssl.md +++ b/docs/configuration/ssl.md @@ -7,7 +7,6 @@ Dokku supports SSL/TLS certificate inspection and CSR/Self-signed certificate ge ``` certs:add CRT KEY # Add an ssl endpoint to an app. Can also import from a tarball on stdin. certs:generate DOMAIN # Generate a key and certificate signing request (and self-signed certificate) -certs:info # Show certificate information for an ssl endpoint. certs:remove # Remove an SSL Endpoint from an app. certs:report [] [] # Displays an ssl report for one or more apps certs:update CRT KEY # Update an SSL Endpoint on an app. Can also import from a tarball on stdin @@ -53,31 +52,11 @@ The `certs:generate` command will walk you through the correct `openssl` command If you decide to obtain a CA signed certificate, you can import that certificate using the aforementioned `dokku certs:add` command. -### Certificate information - -The `certs:info` command will simply inspect the install SSL cert and print out details. NOTE: The server-wide certificate will be inspect if installed and no app-specific certificate exists. - -```shell -dokku certs:info node-js-app -``` - -``` ------> Fetching SSL Endpoint info for node-js-app... ------> Certificate details: -=====> Common Name(s): -=====> test.dokku.me -=====> Expires At: Aug 24 23:32:59 2016 GMT -=====> Issuer: C=US, ST=California, L=San Francisco, O=dokku.me, CN=test.dokku.me -=====> Starts At: Aug 25 23:32:59 2015 GMT -=====> Subject: C=US; ST=California; L=San Francisco; O=dokku.me; CN=test.dokku.me -=====> SSL certificate is self signed. -``` - ### Certificate removal The `certs:remove` command only works on app-specific certificates. It will `rm` the app-specific tls directory, rebuild the nginx configuration, and reload nginx. -### Displaying ssl reports about an app +### Displaying certificate reports about an app > New as of 0.8.1 diff --git a/plugins/certs/functions b/plugins/certs/functions index 55c0ea953..a130c993e 100755 --- a/plugins/certs/functions +++ b/plugins/certs/functions @@ -2,39 +2,6 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -certs_info_cmd() { - # This is here because it's used in both the info and the default - declare desc="prints SSL certificate info for app" - local cmd="certs:info" - [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - verify_app_name "$2" - local APP="$2"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - - if [[ -n "$APP_SSL_PATH" ]]; then - dokku_log_info1 "Fetching SSL Endpoint info for $APP..." - dokku_log_info1 "Certificate details:" - dokku_log_info2 "Common Name(s): " - - for domain in $(get_ssl_hostnames "$APP" | xargs); do - dokku_log_info2 " $domain" - done - - dokku_log_info2 "Expires At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }')" - dokku_log_info2 "Issuer: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g")" - dokku_log_info2 "Starts At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }')" - dokku_log_info2 "Subject: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g")" - local 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 - local SSL_SELF_SIGNED="verified by a certificate authority." - else - local SSL_SELF_SIGNED="self signed." - fi - dokku_log_info2 "SSL certificate is $SSL_SELF_SIGNED" - else - dokku_log_info1 "$APP does not have an SSL endpoint" - fi -} - is_ssl_enabled() { declare desc="returns 0 if ssl is enabled for given app" local APP=$1; verify_app_name "$APP" diff --git a/plugins/certs/internal-functions b/plugins/certs/internal-functions new file mode 100755 index 000000000..3e319812b --- /dev/null +++ b/plugins/certs/internal-functions @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/certs/functions" + +certs_info_cmd() { + # This is here because it's used in both the info and the default + declare desc="prints SSL certificate info for app" + local cmd="certs:info" + [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" + verify_app_name "$2" + local APP="$2" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + + if [[ -n "$APP_SSL_PATH" ]]; then + dokku_log_info1 "Fetching SSL Endpoint info for $APP..." + dokku_log_info1 "Certificate details:" + dokku_log_info2 "Common Name(s): " + + for domain in $(get_ssl_hostnames "$APP" | xargs); do + dokku_log_info2 " $domain" + done + + dokku_log_info2 "Expires At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }')" + dokku_log_info2 "Issuer: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g")" + dokku_log_info2 "Starts At: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }')" + dokku_log_info2 "Subject: $(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g")" + local 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 + local SSL_SELF_SIGNED="verified by a certificate authority." + else + local SSL_SELF_SIGNED="self signed." + fi + dokku_log_info2 "SSL certificate is $SSL_SELF_SIGNED" + else + dokku_log_info1 "$APP does not have an SSL endpoint" + fi +} diff --git a/plugins/certs/subcommands/default b/plugins/certs/subcommands/default old mode 100644 new mode 100755 index 5eabd33b8..9591bedae --- a/plugins/certs/subcommands/default +++ b/plugins/certs/subcommands/default @@ -1,12 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/certs/functions" +source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" -certs_main_cmd() { - declare desc="an alias for certs:info" - local cmd="certs" - certs_info_cmd "$@" -} - -certs_main_cmd "$@" +dokku_log_warn "Deprecated: Please use certs:report" +certs_info_cmd "$@" diff --git a/plugins/certs/subcommands/info b/plugins/certs/subcommands/info index 77fd90b7c..9591bedae 100755 --- a/plugins/certs/subcommands/info +++ b/plugins/certs/subcommands/info @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/certs/functions" +source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" +dokku_log_warn "Deprecated: Please use certs:report" certs_info_cmd "$@" From 507ae1de331c640dc28afa5898e7126383c012c5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 16:50:38 -0700 Subject: [PATCH 03/22] =?UTF-8?q?fix:=20ensure=20certs:info=20doesn?= =?UTF-8?q?=E2=80=99t=20output=20error=20information=20when=20ssl=20files?= =?UTF-8?q?=20are=20missing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/certs/internal-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/certs/internal-functions b/plugins/certs/internal-functions index 3e319812b..a225ae6d7 100755 --- a/plugins/certs/internal-functions +++ b/plugins/certs/internal-functions @@ -12,7 +12,7 @@ certs_info_cmd() { local APP="$2" local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" - if [[ -n "$APP_SSL_PATH" ]]; then + if is_ssl_enabled "$APP"; then dokku_log_info1 "Fetching SSL Endpoint info for $APP..." dokku_log_info1 "Certificate details:" dokku_log_info2 "Common Name(s): " From cb71d8a0be01abe078a72331b75dc3174d231c98 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 16:51:46 -0700 Subject: [PATCH 04/22] fix: clean up certs help output --- plugins/certs/commands | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/certs/commands b/plugins/certs/commands index 550d97f8d..972968821 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -7,11 +7,11 @@ case "$1" in help_content_func () { declare desc="return certs plugin help content" cat< CRT KEY, Add an ssl endpoint to an app. Can also import from a tarball on stdin certs:chain CRT [CRT ...], [NOT IMPLEMENTED] Print the ordered and complete chain for the given certificate certs:generate DOMAIN, Generate a key and certificate signing request (and self-signed certificate) - certs:info , Show certificate information for an ssl endpoint + certs:info , [DEPRECATED] Alternative for certs:report certs:key CRT KEY [KEY ...], [NOT IMPLEMENTED] Print the correct key for the given certificate certs:remove , Remove an SSL Endpoint from an app certs:report [] [], Displays an ssl report for one or more apps @@ -21,14 +21,18 @@ help_content } if [[ $1 = "certs:help" ]] ; then - echo -e 'Usage: dokku certs:COMMAND' - echo '' - echo 'Manage Dokku apps SSL (TLS) certs.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, + echo -e 'Usage: dokku certs:COMMAND' + echo '' + echo 'Manage Dokku apps SSL (TLS) certs.' + echo '' + echo 'Additional commands:' + help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + help_content_func else - help_content_func + cat< Date: Mon, 20 Feb 2017 17:11:53 -0700 Subject: [PATCH 05/22] refactor: move certs:help into internal-functions --- plugins/certs/commands | 32 ++----------------------------- plugins/certs/internal-functions | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/plugins/certs/commands b/plugins/certs/commands index 972968821..9e13305ab 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -1,39 +1,11 @@ #!/usr/bin/env bash [[ " help certs:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | certs:help) - help_content_func () { - declare desc="return certs plugin help content" - cat< CRT KEY, Add an ssl endpoint to an app. Can also import from a tarball on stdin - certs:chain CRT [CRT ...], [NOT IMPLEMENTED] Print the ordered and complete chain for the given certificate - certs:generate DOMAIN, Generate a key and certificate signing request (and self-signed certificate) - certs:info , [DEPRECATED] Alternative for certs:report - certs:key CRT KEY [KEY ...], [NOT IMPLEMENTED] Print the correct key for the given certificate - certs:remove , Remove an SSL Endpoint from an app - certs:report [] [], Displays an ssl report for one or more apps - certs:rollback , [NOT IMPLEMENTED] Rollback an SSL Endpoint for an app - certs:update CRT KEY, Update an SSL Endpoint on an app. Can also import from a tarball on stdin -help_content - } - - if [[ $1 = "certs:help" ]] ; then - echo -e 'Usage: dokku certs:COMMAND' - echo '' - echo 'Manage Dokku apps SSL (TLS) certs.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then - help_content_func - else - cat< CRT KEY, Add an ssl endpoint to an app. Can also import from a tarball on stdin + certs:chain CRT [CRT ...], [NOT IMPLEMENTED] Print the ordered and complete chain for the given certificate + certs:generate DOMAIN, Generate a key and certificate signing request (and self-signed certificate) + certs:info , [DEPRECATED] Alternative for certs:report + certs:key CRT KEY [KEY ...], [NOT IMPLEMENTED] Print the correct key for the given certificate + certs:remove , Remove an SSL Endpoint from an app + certs:report [] [], Displays an ssl report for one or more apps + certs:rollback , [NOT IMPLEMENTED] Rollback an SSL Endpoint for an app + certs:update CRT KEY, Update an SSL Endpoint on an app. Can also import from a tarball on stdin +help_content +} + +certs_help_cmd() { + if [[ $1 = "certs:help" ]] ; then + echo -e 'Usage: dokku certs[:COMMAND]' + echo '' + echo 'Manage Dokku apps SSL (TLS) certs.' + echo '' + echo 'Additional commands:' + certs_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + certs_help_content_func + else + cat< Date: Mon, 20 Feb 2017 17:18:29 -0700 Subject: [PATCH 06/22] feat: implement apps:list Also deprecate the `apps` command in favor of `apps:list` --- plugins/apps/commands | 3 ++- plugins/apps/internal-functions | 14 ++++++++++++++ plugins/apps/subcommands/default | 16 +++------------- plugins/apps/subcommands/list | 5 +++++ 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100755 plugins/apps/internal-functions create mode 100755 plugins/apps/subcommands/list diff --git a/plugins/apps/commands b/plugins/apps/commands index 97b8fae13..d6a140f4b 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -7,10 +7,11 @@ case "$1" in help_content_func () { declare desc="return apps plugin help content" cat< , Clones an app apps:create , Create a new app apps:destroy , Permanently destroy an app + apps:list, List your apps apps:rename , Rename an app apps:report [] [], Display report about an app help_content diff --git a/plugins/apps/internal-functions b/plugins/apps/internal-functions new file mode 100755 index 000000000..1374bda6b --- /dev/null +++ b/plugins/apps/internal-functions @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +apps_list_cmd() { + declare desc="lists all apps" + local cmd="apps" + local app + + dokku_log_info2_quiet "My Apps" + for app in $(dokku_apps); do + echo "$app" + done +} diff --git a/plugins/apps/subcommands/default b/plugins/apps/subcommands/default index 47f5973a6..ac2c04ed3 100755 --- a/plugins/apps/subcommands/default +++ b/plugins/apps/subcommands/default @@ -1,16 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" -apps_main_cmd() { - declare desc="lists all apps" - local cmd="apps" - local app - - dokku_log_info2_quiet "My Apps" - for app in $(dokku_apps); do - echo "$app" - done -} - -apps_main_cmd "$@" +dokku_log_warn "Deprecated: Please use apps:list" +apps_list_cmd "$@" diff --git a/plugins/apps/subcommands/list b/plugins/apps/subcommands/list new file mode 100755 index 000000000..b9573fac2 --- /dev/null +++ b/plugins/apps/subcommands/list @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" + +apps_list_cmd "$@" From cd3e637387d1560ea3c9f5465e42fb065dc66642 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 17:22:41 -0700 Subject: [PATCH 07/22] refactor: move apps:help to internal-functions --- plugins/apps/commands | 32 ++-------------------------- plugins/apps/internal-functions | 37 +++++++++++++++++++++++++++++++++ plugins/apps/subcommands/report | 2 +- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/plugins/apps/commands b/plugins/apps/commands index d6a140f4b..84cd4b172 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -1,39 +1,11 @@ #!/usr/bin/env bash [[ " help apps:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | apps:help) - help_content_func () { - declare desc="return apps plugin help content" - cat< , Clones an app - apps:create , Create a new app - apps:destroy , Permanently destroy an app - apps:list, List your apps - apps:rename , Rename an app - apps:report [] [], Display report about an app -help_content - } - - if [[ $1 = "apps:help" ]] ; then - echo -e 'Usage: dokku apps[:COMMAND]' - echo '' - echo 'List your apps.' - echo '' - echo 'Example:' - echo '' - echo '$ dokku apps' - echo '=====> My Apps' - echo 'example' - echo 'example2' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - else - help_content_func - fi + apps_help_cmd "$@" ;; *) diff --git a/plugins/apps/internal-functions b/plugins/apps/internal-functions index 1374bda6b..274132560 100755 --- a/plugins/apps/internal-functions +++ b/plugins/apps/internal-functions @@ -2,6 +2,43 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +apps_help_content_func() { + declare desc="return apps plugin help content" + cat< , Clones an app + apps:create , Create a new app + apps:destroy , Permanently destroy an app + apps:list, List your apps + apps:rename , Rename an app + apps:report [] [], Display report about an app +help_content +} + +apps_help_cmd() { + if [[ $1 = "apps:help" ]] ; then + echo -e 'Usage: dokku apps[:COMMAND]' + echo '' + echo 'Manage Dokku apps' + echo '' + echo 'Example:' + echo '' + echo '$ dokku apps' + echo '=====> My Apps' + echo 'example' + echo 'example2' + echo '' + echo 'Additional commands:' + apps_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + apps_help_content_func + else + cat< Date: Mon, 20 Feb 2017 17:24:09 -0700 Subject: [PATCH 08/22] cleanup: move from apps to apps:list subcommand for tests and docs --- docs/deployment/application-management.md | 11 +++++++---- tests/unit/10_apps.bats | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/deployment/application-management.md b/docs/deployment/application-management.md index 679246815..27d220af8 100644 --- a/docs/deployment/application-management.md +++ b/docs/deployment/application-management.md @@ -3,10 +3,10 @@ > New as of 0.3.1 ``` -apps # List your apps apps:clone # Clones an app apps:create # Create a new app apps:destroy # Permanently destroy an app +apps:list # List your apps apps:rename # Rename an app apps:report [] [] # Display report about an app ``` @@ -15,10 +15,12 @@ apps:report [] [] # Display report about an app ### Listing Applications -You can easily list all available applications using the `apps` command: +> New as of 0.8.1. Use the `apps` command for older versions. + +You can easily list all available applications using the `apps:list` command: ```shell -dokku apps +dokku apps:list ``` ``` @@ -30,7 +32,7 @@ python-app Note that you can easily hide extra output from Dokku commands by using the `--quiet` flag, which makes it easier to parse on the command-line. ```shell -dokku --quiet apps +dokku --quiet apps:list ``` ``` @@ -179,6 +181,7 @@ dokku apps:report node-js-sample ``` You can pass flags which will output only the value of the specific information you want. For example: + ```shell dokku apps:report node-js-sample --git-sha ``` diff --git a/tests/unit/10_apps.bats b/tests/unit/10_apps.bats index 17ed29be3..797304716 100644 --- a/tests/unit/10_apps.bats +++ b/tests/unit/10_apps.bats @@ -15,7 +15,7 @@ teardown () { echo "output: "$output echo "status: "$status assert_success - run bash -c "dokku apps | grep $TEST_APP" + run bash -c "dokku apps:list | grep $TEST_APP" echo "output: "$output echo "status: "$status assert_output $TEST_APP @@ -36,7 +36,7 @@ teardown () { echo "output: "$output echo "status: "$status assert_success - run bash -c "dokku apps | grep $TEST_APP" + run bash -c "dokku apps:list | grep $TEST_APP" echo "output: "$output echo "status: "$status assert_output $TEST_APP @@ -64,7 +64,7 @@ teardown () { echo "output: "$output echo "status: "$status assert_success - run bash -c "dokku apps | grep $TEST_APP" + run bash -c "dokku apps:list | grep $TEST_APP" echo "output: "$output echo "status: "$status assert_output "" @@ -97,7 +97,7 @@ teardown () { echo "output: "$output echo "status: "$status assert_success - run bash -c "dokku apps | grep $TEST_APP" + run bash -c "dokku apps:list | grep $TEST_APP" echo "output: "$output echo "status: "$status assert_success From cbcb720228055f84eb02cc24d5f36eb9910d1e97 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 18:04:57 -0700 Subject: [PATCH 09/22] 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 10/22] 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 11/22] 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 12/22] 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 From 40262915726557b32a3e961400667aa18c3fe10a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 19:22:18 -0700 Subject: [PATCH 13/22] SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'. --- plugins/certs/subcommands/report | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/certs/subcommands/report b/plugins/certs/subcommands/report index 6f0e59031..43aa31648 100755 --- a/plugins/certs/subcommands/report +++ b/plugins/certs/subcommands/report @@ -18,7 +18,7 @@ fn-ssl-expires-at() { local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if is_ssl_enabled "$APP"; then - echo "$(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }')" + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not After :" | awk -F " : " '{ print $2 }' fi } @@ -35,7 +35,7 @@ fn-ssl-issuer() { local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if is_ssl_enabled "$APP"; then - echo "$(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g")" + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Issuer:" | xargs | sed -e "s/Issuer: //g" fi } @@ -44,7 +44,7 @@ fn-ssl-starts-at() { local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if is_ssl_enabled "$APP"; then - echo "$(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }')" + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -text | grep "Not Before:" | awk -F ": " '{ print $2 }' fi } @@ -53,7 +53,7 @@ fn-ssl-subject() { local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if is_ssl_enabled "$APP"; then - echo "$(openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g")" + openssl x509 -in "$APP_SSL_PATH/server.crt" -noout -subject | sed -e "s:subject= ::g"| sed -e "s:^/::g" | sed -e "s:/:; :g" fi } From a09560542bfac3554d6efb20148fda8f65003010 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 20:08:38 -0700 Subject: [PATCH 14/22] refactor: move ssh-keys:help to internal-functions --- plugins/ssh-keys/commands | 22 ++-------------------- plugins/ssh-keys/internal-functions | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100755 plugins/ssh-keys/internal-functions diff --git a/plugins/ssh-keys/commands b/plugins/ssh-keys/commands index bfd36a0ce..1aabfd445 100755 --- a/plugins/ssh-keys/commands +++ b/plugins/ssh-keys/commands @@ -1,29 +1,11 @@ #!/usr/bin/env bash [[ " help ssh-keys:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/ssh-keys/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | ssh-keys:help) - help_content_func () { - declare desc="return ssh-keys plugin help content" - cat< [/path/to/key], Add a new public key by pipe or path - ssh-keys:remove , Remove SSH public key by name -help_content - } - - if [[ $1 = "ssh-keys:help" ]] ; then - echo -e 'Usage: dokku ssh-keys[:COMMAND]' - echo '' - echo 'Manage public ssh keys that are allowed to connect to Dokku' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - else - help_content_func - fi + ssh_keys_help_cmd "$@" ;; *) diff --git a/plugins/ssh-keys/internal-functions b/plugins/ssh-keys/internal-functions new file mode 100755 index 000000000..bc4d868e7 --- /dev/null +++ b/plugins/ssh-keys/internal-functions @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +ssh_keys_help_content_func() { + declare desc="return ssh-keys plugin help content" + cat< [/path/to/key], Add a new public key by pipe or path + ssh-keys:remove , Remove SSH public key by name +help_content +} + +ssh_keys_help_cmd() { + if [[ $1 = "ssh-keys:help" ]] ; then + echo -e 'Usage: dokku ssh-keys[:COMMAND]' + echo '' + echo 'Manage public ssh keys that are allowed to connect to Dokku' + echo '' + echo 'Additional commands:' + ssh_keys_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + ssh_keys_help_content_func + else + cat< Date: Mon, 20 Feb 2017 20:09:09 -0700 Subject: [PATCH 15/22] refactor: alias ssh-keys:default to ssh-keys:help --- plugins/ssh-keys/subcommands/default | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) mode change 100644 => 100755 plugins/ssh-keys/subcommands/default diff --git a/plugins/ssh-keys/subcommands/default b/plugins/ssh-keys/subcommands/default old mode 100644 new mode 100755 index abdbaa619..20fea35c3 --- a/plugins/ssh-keys/subcommands/default +++ b/plugins/ssh-keys/subcommands/default @@ -1,12 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/ssh-keys/functions" +source "$PLUGIN_AVAILABLE_PATH/ssh-keys/internal-functions" -ssh_keys_main_cmd() { - declare desc="an alias for ssh-keys:list" - local cmd="ssh-keys" - list_ssh_keys -} - -ssh_keys_main_cmd "$@" \ No newline at end of file +ssh_keys_help_cmd "$@" From 0e899cdd1395af71388600a973a7c5fbf7fb9f32 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 21:41:19 -0700 Subject: [PATCH 16/22] feat: implement proxy:report command Also deprecate `proxy:default` in favor of `proxy:report` Refs #2356 --- docs/advanced-usage/proxy-management.md | 54 +++++++++++++++++-- plugins/proxy/commands | 1 + plugins/proxy/functions | 14 +++-- plugins/proxy/subcommands/default | 1 + plugins/proxy/subcommands/report | 70 +++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 8 deletions(-) create mode 100755 plugins/proxy/subcommands/report diff --git a/docs/advanced-usage/proxy-management.md b/docs/advanced-usage/proxy-management.md index 31d695530..09f88c0c4 100644 --- a/docs/advanced-usage/proxy-management.md +++ b/docs/advanced-usage/proxy-management.md @@ -3,19 +3,21 @@ > New as of 0.5.0, Enhanced in 0.6.0 ``` -proxy # Show proxy settings for app proxy:disable # Disable proxy for app proxy:enable # Enable proxy for app proxy:ports # List proxy port mappings for app proxy:ports-add :: [::...] # Set proxy port mappings for app proxy:ports-clear # Clear all proxy port mappings for app proxy:ports-remove [|::...] # Unset proxy port mappings for app +proxy:report [] [] # Displays a proxy report for one or more apps proxy:set # Set proxy type for app ``` In Dokku 0.5.0, port proxying was decoupled from the `nginx-vhosts` plugin into the proxy plugin. Dokku 0.6.0 introduced the ability to map host ports to specific container ports. In the future this will allow other proxy software - such as HAProxy or Caddy - to be used in place of nginx. -## Container network interface binding +## Usage + +### Container network interface binding > New as of 0.5.0 @@ -58,7 +60,51 @@ CONTAINER ID IMAGE COMMAND CREATED d6499edb0edb dokku/node-js-app:latest "/bin/bash -c '/star About a minute ago Up About a minute 0.0.0.0:49153->5000/tcp node-js-app.web.1 ``` -## Proxy port mapping +### Displaying proxy reports about an app + +> New as of 0.8.1 + +You can get a report about the app's proxy status using the `proxy:report` command: + +```shell +dokku proxy:report +``` + +``` +=====> node-js-app proxy information + Proxy enabled: true + Proxy type: nginx + Proxy port map: http:80:5000 https:443:5000 +=====> python-sample proxy information + Proxy enabled: true + Proxy type: nginx + Proxy port map: http:80:5000 +=====> ruby-sample proxy information + Proxy enabled: true + Proxy type: nginx + Proxy port map: http:80:5000 +``` + +You can run the command for a specific app also. + +```shell +dokku proxy:report node-js-app +``` + +``` +=====> node-js-app proxy information + Proxy enabled: true + Proxy type: nginx + Proxy port map: http:80:5000 https:443:5000 +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku proxy:report node-js-app --proxy-type +``` + +### Proxy port mapping > New as of 0.6.0 @@ -141,7 +187,7 @@ By default, buildpack apps and dockerfile apps **without** explicitly exposed po > Note: This default behavior **will not** be automatically changed on subsequent pushes and must be manipulated with the `proxy:ports-*` syntax detailed above. -## Proxy Port Scheme +#### Proxy Port Scheme The proxy port scheme is as follows: diff --git a/plugins/proxy/commands b/plugins/proxy/commands index 25d60d2ea..7df9f973b 100755 --- a/plugins/proxy/commands +++ b/plugins/proxy/commands @@ -14,6 +14,7 @@ case "$1" in proxy:ports-clear , Clear all proxy port mappings for app proxy:ports-add :: [::...], Set proxy port mappings for app proxy:ports-remove [|::...], Unset proxy port mappings for app + proxy:report [] [], Displays a proxy report for one or more apps proxy:set , Set proxy type for app help_content } diff --git a/plugins/proxy/functions b/plugins/proxy/functions index d7d3b1a2f..5202a21ef 100755 --- a/plugins/proxy/functions +++ b/plugins/proxy/functions @@ -24,10 +24,16 @@ get_app_proxy_type() { echo "$APP_PROXY_TYPE" } +get_app_proxy_port_map() { + declare desc="return a list of configured port mappings" + local APP="$1"; local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + echo "$PROXY_PORT_MAP" +} + list_app_proxy_ports() { declare desc="list proxy port mappings for an app" local APP="$1"; verify_app_name "$APP" - local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" if [[ -n "$PROXY_PORT_MAP" ]]; then dokku_log_info1_quiet "Port mappings for $APP" @@ -45,7 +51,7 @@ filter_app_proxy_ports() { declare desc="list proxy port mappings for an app that start with a particular scheme and a host port" local APP="$1"; verify_app_name "$APP" local SCHEME="$2" HOST_PORT="$3" - local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" if [[ -n "$PROXY_PORT_MAP" ]]; then local port_map @@ -62,7 +68,7 @@ filter_app_proxy_ports() { add_proxy_ports() { declare desc="add proxy port mappings from an app" local APP="$1" - local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" shift 1 local INPUT_PORTS="$*" @@ -78,7 +84,7 @@ add_proxy_ports() { remove_proxy_ports() { declare desc="remove specific proxy port mappings from an app" local APP="$1" - local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" local RE_PORT='^[0-9]+$' shift 1 diff --git a/plugins/proxy/subcommands/default b/plugins/proxy/subcommands/default index 4e867c850..03c08f400 100755 --- a/plugins/proxy/subcommands/default +++ b/plugins/proxy/subcommands/default @@ -12,6 +12,7 @@ proxy_main_cmd() { local APPS="$1" fi + dokku_log_warn "Deprecated: Please use proxy:report" dokku_col_log_info1_quiet "App Name" "Proxy Type" local app for app in $APPS; do diff --git a/plugins/proxy/subcommands/report b/plugins/proxy/subcommands/report new file mode 100755 index 000000000..260483417 --- /dev/null +++ b/plugins/proxy/subcommands/report @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +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" +} + +proxy_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=( + "--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 "$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 + + if [[ -z $2 ]]; then + for APP in $INSTALLED_APPS; do + proxy_report_single_app "$APP" "true" + done + else + proxy_report_single_app "$2" "$3" + fi +} + +proxy_report_cmd "$@" From 225840b79d004d0b4befcdd33826c2ff0867ee7a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 21:48:58 -0700 Subject: [PATCH 17/22] refactor: move proxy:help to internal-functions --- plugins/proxy/commands | 27 ++----------------------- plugins/proxy/internal-functions | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 plugins/proxy/internal-functions diff --git a/plugins/proxy/commands b/plugins/proxy/commands index 7df9f973b..db59fda92 100755 --- a/plugins/proxy/commands +++ b/plugins/proxy/commands @@ -1,34 +1,11 @@ #!/usr/bin/env bash [[ " help proxy:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/proxy/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | proxy:help) - help_content_func () { - declare desc="return proxy plugin help content" - cat<, Show proxy settings for app - proxy:enable , Enable proxy for app - proxy:disable , Disable proxy for app - proxy:ports , List proxy port mappings for app - proxy:ports-clear , Clear all proxy port mappings for app - proxy:ports-add :: [::...], Set proxy port mappings for app - proxy:ports-remove [|::...], Unset proxy port mappings for app - proxy:report [] [], Displays a proxy report for one or more apps - proxy:set , Set proxy type for app -help_content - } - - if [[ $1 = "proxy:help" ]] ; then - echo -e 'Usage: dokku proxy[:COMMAND]' - echo '' - echo 'Control the proxy used by dokku, per app.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - else - help_content_func - fi + proxy_vhosts_help_cmd "$@" ;; *) diff --git a/plugins/proxy/internal-functions b/plugins/proxy/internal-functions new file mode 100644 index 000000000..ec85d4ab2 --- /dev/null +++ b/plugins/proxy/internal-functions @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +proxy_vhosts_help_content_func() { + declare desc="return proxy plugin help content" + cat<, [DEPRECATED] Show proxy settings for app + proxy:enable , Enable proxy for app + proxy:disable , Disable proxy for app + proxy:ports , List proxy port mappings for app + proxy:ports-clear , Clear all proxy port mappings for app + proxy:ports-add :: [::...], Set proxy port mappings for app + proxy:ports-remove [|::...], Unset proxy port mappings for app + proxy:report [] [], Displays a proxy report for one or more apps + proxy:set , Set proxy type for app +help_content +} + +proxy_vhosts_help_cmd() { + if [[ $1 = "proxy:help" ]] ; then + echo -e 'Usage: dokku proxy[:COMMAND]' + echo '' + echo 'Manage the proxy used by dokku on a per app.' + echo '' + echo 'Additional commands:' + proxy_vhosts_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + proxy_vhosts_help_content_func + else + cat< Date: Mon, 20 Feb 2017 22:35:52 -0700 Subject: [PATCH 18/22] refactor: move nginx:help to internal-functions --- plugins/nginx-vhosts/commands | 14 ++++--------- plugins/nginx-vhosts/functions | 19 ----------------- plugins/nginx-vhosts/internal-functions | 28 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 29 deletions(-) create mode 100755 plugins/nginx-vhosts/internal-functions diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 2995231d7..3dbfc98d8 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -1,21 +1,15 @@ #!/usr/bin/env bash [[ " help nginx:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" case "$1" in help | nginx:help) - - - if [[ $1 = "nginx:help" ]] ; then - help_formatted - else - help_content_func - fi - ;; + nginx_vhosts_help_cmd "$@" + ;; *) exit "$DOKKU_NOT_IMPLEMENTED_EXIT" - ;; + ;; esac diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 8f1af2c40..c68d9aa66 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -6,25 +6,6 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/domains/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" -help_formatted (){ - echo -e 'Usage: dokku nginx[:COMMAND]' - echo '' - echo 'Interact with Dokku'"'"'s Nginx proxy.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, -} - -help_content_func () { - declare desc="return nginx plugin help content" - cat<, (Re)builds nginx config for given app - nginx:access-logs [-t], Show the nginx access logs for an application (-t follows) - nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) -help_content - } - validate_nginx() { declare desc="validate entire nginx config" set +e diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions new file mode 100755 index 000000000..93d929bb6 --- /dev/null +++ b/plugins/nginx-vhosts/internal-functions @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +nginx_vhosts_help_content_func() { + declare desc="return nginx plugin help content" + cat<, (Re)builds nginx config for given app + nginx:access-logs [-t], Show the nginx access logs for an application (-t follows) + nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) +help_content +} + +nginx_vhosts_help_cmd() { + if [[ $1 = "nginx:help" ]] ; then + echo -e 'Usage: dokku nginx[:COMMAND]' + echo '' + echo 'Interact with Dokku'"'"'s Nginx proxy.' + echo '' + echo 'Additional commands:' + nginx_vhosts_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + nginx_vhosts_help_content_func + else + cat< Date: Mon, 20 Feb 2017 22:39:53 -0700 Subject: [PATCH 19/22] refactor: alias nginx:default to nginx:help --- plugins/nginx-vhosts/subcommands/default | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) mode change 100644 => 100755 plugins/nginx-vhosts/subcommands/default diff --git a/plugins/nginx-vhosts/subcommands/default b/plugins/nginx-vhosts/subcommands/default old mode 100644 new mode 100755 index 30cb86061..5a4deae9b --- a/plugins/nginx-vhosts/subcommands/default +++ b/plugins/nginx-vhosts/subcommands/default @@ -1,13 +1,5 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -source "$PLUGIN_AVAILABLE_PATH/config/functions" -source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" -nginx_main_cmd() { - declare desc="display nginx plugin help content" - local cmd="nginx" - help_formatted -} - -nginx_main_cmd "$@" +nginx_vhosts_help_cmd "$@" From 48653e566319f75ca289543d2049cb90b856894f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 22:44:51 -0700 Subject: [PATCH 20/22] chore: properly name functions --- plugins/proxy/commands | 2 +- plugins/proxy/internal-functions | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 plugins/proxy/internal-functions diff --git a/plugins/proxy/commands b/plugins/proxy/commands index db59fda92..3802db5ef 100755 --- a/plugins/proxy/commands +++ b/plugins/proxy/commands @@ -5,7 +5,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | proxy:help) - proxy_vhosts_help_cmd "$@" + proxy_help_cmd "$@" ;; *) diff --git a/plugins/proxy/internal-functions b/plugins/proxy/internal-functions old mode 100644 new mode 100755 index ec85d4ab2..3ff81c845 --- a/plugins/proxy/internal-functions +++ b/plugins/proxy/internal-functions @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x -proxy_vhosts_help_content_func() { +proxy_help_content_func() { declare desc="return proxy plugin help content" cat<, [DEPRECATED] Show proxy settings for app @@ -16,16 +16,16 @@ proxy_vhosts_help_content_func() { help_content } -proxy_vhosts_help_cmd() { +proxy_help_cmd() { if [[ $1 = "proxy:help" ]] ; then echo -e 'Usage: dokku proxy[:COMMAND]' echo '' echo 'Manage the proxy used by dokku on a per app.' echo '' echo 'Additional commands:' - proxy_vhosts_help_content_func | sort | column -c2 -t -s, + proxy_help_content_func | sort | column -c2 -t -s, elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then - proxy_vhosts_help_content_func + proxy_help_content_func else cat< Date: Mon, 20 Feb 2017 22:50:07 -0700 Subject: [PATCH 21/22] refactor: move domains:help to internal-functions --- plugins/domains/commands | 28 ++---------------------- plugins/domains/internal-functions | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 26 deletions(-) create mode 100755 plugins/domains/internal-functions diff --git a/plugins/domains/commands b/plugins/domains/commands index 5b2018369..1ed2fde7f 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -1,35 +1,11 @@ #!/usr/bin/env bash [[ " help domains:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/domains/internal-functions" set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x case "$1" in help | domains:help) - help_content_func () { - declare desc="return domains plugin help content" - cat<], List domains - domains:add [ ...], Add domains to app - domains:add-global [ ...], Add global domain names - domains:clear , Clear all domains for app - domains:disable , Disable VHOST support - domains:enable , Enable VHOST support - domains:remove [ ...], Remove domains from app - domains:remove-global [ ...], Remove global domain names - domains:set [ ...], Set domains for app - domains:set-global [ ...], Set global domain names -help_content - } - - if [[ $1 = "domains:help" ]] ; then - echo -e 'Usage: dokku domains[:COMMAND]' - echo '' - echo 'Manage vhost domains used by the Dokku proxy.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, - else - help_content_func - fi + domains_help_cmd "$@" ;; *) diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions new file mode 100755 index 000000000..33ab2dd1c --- /dev/null +++ b/plugins/domains/internal-functions @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +domains_help_content_func () { + declare desc="return domains plugin help content" + cat<], List domains + domains:add [ ...], Add domains to app + domains:add-global [ ...], Add global domain names + domains:clear , Clear all domains for app + domains:disable , Disable VHOST support + domains:enable , Enable VHOST support + domains:remove [ ...], Remove domains from app + domains:remove-global [ ...], Remove global domain names + domains:set [ ...], Set domains for app + domains:set-global [ ...], Set global domain names +help_content +} + +domains_help_cmd() { + if [[ $1 = "domains:help" ]] ; then + echo -e 'Usage: dokku domains[:COMMAND]' + echo '' + echo 'Manage vhost domains used by the Dokku proxy.' + echo '' + echo 'Additional commands:' + domains_help_content_func | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + domains_help_content_func + else + cat< Date: Mon, 20 Feb 2017 23:17:35 -0700 Subject: [PATCH 22/22] feat: implement domains:report command Also deprecate `domains:default` in favor of `domains:report` Refs #2356 --- docs/configuration/domains.md | 52 +++++++++++++++- plugins/domains/internal-functions | 3 +- plugins/domains/subcommands/default | 1 + plugins/domains/subcommands/report | 92 +++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100755 plugins/domains/subcommands/report diff --git a/docs/configuration/domains.md b/docs/configuration/domains.md index 048a495ef..6f7402d3a 100644 --- a/docs/configuration/domains.md +++ b/docs/configuration/domains.md @@ -3,7 +3,6 @@ > New as of 0.3.10 ``` -domains [|--global] # List domains domains:add [ ...] # Add domains to app domains:add-global [ ...] # Add global domain names domains:clear # Clear all domains for app @@ -11,6 +10,7 @@ domains:disable # Disable VHOST support domains:enable # Enable VHOST support domains:remove [ ...] # Remove domains from app domains:remove-global [ ...] # Remove global domain names +domains:report [] [] # Displays a domains report for one or more apps domains:set [ ...] # Set domains for app domains:set-global [ ...] # Set global domain names ``` @@ -41,7 +41,7 @@ NEW_SUBDOMAIN=`echo $SUBDOMAIN | rev` echo "$NEW_SUBDOMAIN.$VHOST" ``` -If the `nginx-hostname` has no output, the normal hostname algorithm will be executed. +If the `nginx-hostname` plugin has no output, the normal hostname algorithm will be executed. ## Disabling VHOSTS @@ -75,6 +75,54 @@ dokku domains:remove myapp example.com dokku domains:set myapp example.com example.org ``` +## Displaying domains reports about an app + +> New as of 0.8.1 + +You can get a report about the app's domains status using the `domains:report` command: + +```shell +dokku domains:report +``` + +``` +=====> node-js-app domains information + Domains app enabled: true + Domains app vhosts: ruby-sample.example.org + Domains global enabled: true + Domains global vhosts: example.org +=====> python-sample domains information + Domains app enabled: true + Domains app vhosts: ruby-sample.example.org + Domains global enabled: true + Domains global vhosts: example.org +=====> ruby-sample domains information + Domains app enabled: true + Domains app vhosts: ruby-sample.example.org + Domains global enabled: true + Domains global vhosts: example.org +``` + +You can run the command for a specific app also. + +```shell +dokku domains:report node-js-app +``` + +``` +=====> node-js-app domains information + Domains app enabled: true + Domains app vhosts: node-js-app.example.org + Domains global enabled: true + Domains global vhosts: example.org +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku domains:report node-js-app --domains-app-enabled +``` + ## Default site By default, Dokku will route any received request with an unknown HOST header value to the lexicographically first site in the nginx config stack. If this is not the desired behavior, you may want to add the following configuration to the global nginx configuration. diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions index 33ab2dd1c..fb4ab8fce 100755 --- a/plugins/domains/internal-functions +++ b/plugins/domains/internal-functions @@ -4,7 +4,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x domains_help_content_func () { declare desc="return domains plugin help content" cat<], List domains + domains [], [DEPRECATED] Alternative for domains:report domains:add [ ...], Add domains to app domains:add-global [ ...], Add global domain names domains:clear , Clear all domains for app @@ -12,6 +12,7 @@ domains_help_content_func () { domains:enable , Enable VHOST support domains:remove [ ...], Remove domains from app domains:remove-global [ ...], Remove global domain names + domains:report [] [], Displays a domains report for one or more apps domains:set [ ...], Set domains for app domains:set-global [ ...], Set global domain names help_content diff --git a/plugins/domains/subcommands/default b/plugins/domains/subcommands/default index c046e7fac..27728e49c 100755 --- a/plugins/domains/subcommands/default +++ b/plugins/domains/subcommands/default @@ -8,6 +8,7 @@ domains_main_cmd() { local cmd="domains" local APP="$2" + dokku_log_warn "Deprecated: Please use domains:report" if [[ "$(is_global_vhost_enabled)" == "true" ]]; then dokku_log_info2_quiet "Global Domain Name" get_global_vhosts diff --git a/plugins/domains/subcommands/report b/plugins/domains/subcommands/report new file mode 100755 index 000000000..ce7f3078a --- /dev/null +++ b/plugins/domains/subcommands/report @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +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 +} + +domains_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=( + "--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 "$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 + + if [[ -z $2 ]]; then + for APP in $INSTALLED_APPS; do + domains_report_single_app "$APP" "true" + done + else + domains_report_single_app "$2" "$3" + fi +} + +domains_report_cmd "$@"