From 6e61c08b2ce298382a946f52fb65b00165018501 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 18 Mar 2021 17:20:31 +0100 Subject: [PATCH] Handle undeployed state for version output summary Closes https://git.autonomic.zone/coop-cloud/abra/issues/104. --- abra | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/abra b/abra index 9b44e4c..3cf1e19 100755 --- a/abra +++ b/abra @@ -507,8 +507,13 @@ output_version_summary() { local -a IS_AN_UPDATE="false" local -a UNABLE_TO_DETECT="false" + local -a UNDEPLOYED_STATE="false" local -a CHECKED_SERVICES # array + if ! docker stack ls --format "{{ .Name }}" | grep -q "$STACK_NAME"; then + UNDEPLOYED_STATE="true" + fi + IFS=':' read -ra COMPOSE_FILES <<< "$COMPOSE_FILE" for COMPOSE in "${COMPOSE_FILES[@]}"; do SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE}") @@ -541,8 +546,14 @@ output_version_summary() { echo " to de deployed: $(tput setaf 1)$app_version ($app_digest)$(tput sgr0)" fi else - warning "Unable to detect deployed version of ${STACK_NAME}_${SERVICE}, please proceed with caution" - UNABLE_TO_DETECT="true" + if [[ $UNDEPLOYED_STATE == "true" ]]; then + image=$($YQ e ".services.${SERVICE}.image" "${APP_DIR}/${COMPOSE}" | cut -d':' -f1) + echo " ${STACK_NAME}_${SERVICE} (${image}):" + echo " undeployed!" + else + warning "Unable to detect deployed version of ${STACK_NAME}_${SERVICE}, please proceed with caution" + UNABLE_TO_DETECT="true" + fi fi CHECKED_SERVICES+=("$SERVICE") done @@ -551,7 +562,7 @@ output_version_summary() { if [[ $IS_AN_UPDATE == "true" ]] && [[ $FORCE_DEPLOY != "true" ]]; then require_consent_for_update else - if [[ ! $UNABLE_TO_DETECT == "true" ]] && [[ $FORCE_DEPLOY != "true" ]]; then + if [[ ! $UNABLE_TO_DETECT == "true" ]] && [[ $FORCE_DEPLOY != "true" ]] && [[ ! $UNDEPLOYED_STATE == "true" ]]; then success "Nothing to deploy, you're on latest (use --force to re-deploy anyway)" exit 0 fi