From 9f38ef9bb90f329c788678334835e0af30e9c5ef Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 26 Nov 2019 21:58:46 +0100 Subject: [PATCH] new: dev: debug messages on launcher Using ``DEBUG=1`` on binary compose docker launcher prints pretty-printed docker command launched as well as important system variables. Signed-off-by: Valentin Lab --- bin/compose | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bin/compose b/bin/compose index 019ce76..e542a7e 100755 --- a/bin/compose +++ b/bin/compose @@ -454,6 +454,17 @@ mk_docker_run_options() { mkdir -p "$COMPOSE_VAR"/sessions mv "$filename" "$dest" echo "$dest" + + if [ "$DEBUG" ]; then + echo "${WHITE}Environment:${NORMAL}" + echo " COMPOSE_DOCKER_IMAGE: $COMPOSE_DOCKER_IMAGE" + echo " CHARM_STORE: $CHARM_STORE" + echo " DATASTORE: $DATASTORE" + echo " CONFIGSTORE: $CONFIGSTORE" + echo " COMPOSE_VAR: $COMPOSE_VAR" + echo " COMPOSE_CACHE: $COMPOSE_CACHE" + fi >&2 + } @@ -496,6 +507,20 @@ get_tz() { } +pretty_print() { + while [ "$#" != 0 ]; do + case "$1" in + "-v"|"-e"|"-w") + e "$1" "$2" "\\"$'\n' + shift;; + *) + e "$1 ";; + esac + shift + done +} + + run() { local os docker_run_opts @@ -519,6 +544,14 @@ run() { [ -t 0 ] && docker_run_opts+=("-i") [ -t 1 ] && docker_run_opts+=("-t") + if [ "$DEBUG" ]; then + echo "${WHITE}Launching:${NORMAL}" + echo " docker run --rm \\" + pretty_print "${docker_run_opts[@]}" | sed -r 's/^/ /g' >&2 + echo "\\"$'\n' >&2 + echo " ${COMPOSE_DOCKER_IMAGE} \\" + echo " " "$@" + fi >&2 exec docker run --rm "${docker_run_opts[@]}" "${COMPOSE_DOCKER_IMAGE}" "$@" }