From b7da215ab51219a2ccbbc8f9e3b8200920722cb6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 20 Feb 2017 19:05:38 -0700 Subject: [PATCH] feat: implement storage:report command Refs #2356 --- docs/advanced-usage/persistent-storage.md | 45 +++++++++++++++ plugins/storage/internal-functions | 1 + plugins/storage/subcommands/report | 68 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100755 plugins/storage/subcommands/report diff --git a/docs/advanced-usage/persistent-storage.md b/docs/advanced-usage/persistent-storage.md index 4cf00aafe..72a51f985 100644 --- a/docs/advanced-usage/persistent-storage.md +++ b/docs/advanced-usage/persistent-storage.md @@ -8,6 +8,7 @@ The preferred method to mount external containers to a Dokku managed container, ``` storage:list # List bind mounts for app's container(s) (host:container) storage:mount # Create a new bind mount +storage:report [] [] # Displays a checks report for one or more apps storage:unmount # Remove an existing bind mount ``` @@ -53,6 +54,50 @@ dokku storage:mount app-name /var/lib/dokku/data/storage/node-js-app:/app/storag You can mount one or more directories as desired by following the above pattern. +### Displaying storage reports about an app + +> New as of 0.8.1 + +You can get a report about the app's storage status using the `storage:report` command: + +```shell +dokku storage:report +``` + +``` +=====> node-js-sample storage information + Storage build mounts: + Storage deploy mounts: -v /var/lib/dokku/data/storage/node-js-sample:/app/storage + Storage run mounts: -v /var/lib/dokku/data/storage/node-js-sample:/app/storage +=====> python-sample storage information + Storage build mounts: + Storage deploy mounts: + Storage run mounts: +=====> ruby-sample storage information + Storage build mounts: + Storage deploy mounts: + Storage run mounts: +``` + +You can run the command for a specific app also. + +```shell +dokku storage:report node-js-sample +``` + +``` +=====> node-js-sample storage information + Storage build mounts: + Storage deploy mounts: -v /var/lib/dokku/data/storage/node-js-sample:/app/storage + Storage run mounts: -v /var/lib/dokku/data/storage/node-js-sample:/app/storage +``` + +You can pass flags which will output only the value of the specific information you want. For example: + +```shell +dokku storage:report node-js-sample --storage-deploy-mounts +``` + ## Use Cases ### Persistent storage diff --git a/plugins/storage/internal-functions b/plugins/storage/internal-functions index 745c6a8ed..0c9bf0a64 100755 --- a/plugins/storage/internal-functions +++ b/plugins/storage/internal-functions @@ -9,6 +9,7 @@ storage_help_content_func() { cat<, List bind mounts for app's container(s) (host:container) storage:mount , Create a new bind mount + storage:report [] [], Displays a checks report for one or more apps storage:unmount , Remove an existing bind mount help_content } diff --git a/plugins/storage/subcommands/report b/plugins/storage/subcommands/report new file mode 100755 index 000000000..cc8e0fa60 --- /dev/null +++ b/plugins/storage/subcommands/report @@ -0,0 +1,68 @@ +#!/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" + +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_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=( + "--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 "$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 + + if [[ -z $2 ]]; then + for APP in $INSTALLED_APPS; do + storage_report_single_app "$APP" "true" + done + else + storage_report_single_app "$2" "$3" + fi +} + +storage_report_cmd "$@"