From dd92acac8700ba4e2de37b6ed160514b236d1f5b Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 30 Jan 2016 17:28:51 +0700 Subject: [PATCH] new: check compose file yaml before usage. --- bin/compose | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/compose b/bin/compose index c8bb035..3af5792 100755 --- a/bin/compose +++ b/bin/compose @@ -1799,6 +1799,18 @@ export DOCKER_DATASTORE=${DOCKER_DATASTORE:-/srv/docker-datastore} export COMPOSE_YML_FILE=$(get_compose_yml_location) || exit 1 debug "Found 'compose.yml' file in '$COMPOSE_YML_FILE'." +output=$(shyaml get-value < "$COMPOSE_YML_FILE" 2>&1) +if [ "$?" != 0 ]; then + err "Invalid YAML in '$COMPOSE_YML_FILE':" + while IFS='' read -r line1 && IFS='' read -r line2; do + echo "$line1 $GRAY($line2)$NORMAL" + done < <(echo "$output" | grep ^yaml.scanner -A 100 | + sed -r 's/^ in "", //g' | sed -r 's/^yaml.scanner.[a-zA-Z]+: //g') | + prefix " $GRAY|$NORMAL " + exit 1 +fi + + if ! [ -d "$CHARM_STORE" ]; then err "Charm store path $YELLOW$CHARM_STORE$NORMAL does not exists. " err "Please check your $YELLOW\$CHARM_STORE$NORMAL variable value."