69 lines
2.0 KiB
Bash
Executable File
69 lines
2.0 KiB
Bash
Executable File
#!/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 "$@"
|