Use local marker and scan services only once

This commit is contained in:
decentral1se 2021-03-16 08:38:11 +01:00
parent bc0ef0d6fc
commit b04bfea1c7
Signed by untrusted user who does not match committer: decentral1se
GPG Key ID: 92DAD76BD9567B8A

13
abra
View File

@ -503,14 +503,21 @@ output_version_summary() {
echo " Versions:" echo " Versions:"
CONSENT_TO_UPDATE=$abra___update CONSENT_TO_UPDATE=$abra___update
IS_AN_UPDATE="false"
UNABLE_TO_DETECT="false" local -a IS_AN_UPDATE="false"
local -a UNABLE_TO_DETECT="false"
local -a CHECKED_SERVICES # array
IFS=':' read -ra COMPOSE_FILES <<< "$COMPOSE_FILE" IFS=':' read -ra COMPOSE_FILES <<< "$COMPOSE_FILE"
for COMPOSE in "${COMPOSE_FILES[@]}"; do for COMPOSE in "${COMPOSE_FILES[@]}"; do
SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE}") SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE}")
for SERVICE in $SERVICES; do for SERVICE in $SERVICES; do
if [[ "${CHECKED_SERVICES[@]}" =~ "${SERVICE}" ]]; then
debug "already inspected ${STACK_NAME}_${SERVICE} for versions, skipping..."
continue
fi
filter="{{index .Spec.Labels \"coop-cloud.$STACK_NAME.$SERVICE.version\" }}" filter="{{index .Spec.Labels \"coop-cloud.$STACK_NAME.$SERVICE.version\" }}"
label=$(docker service inspect -f "$filter" "${STACK_NAME}_${SERVICE}" 2>/dev/null) label=$(docker service inspect -f "$filter" "${STACK_NAME}_${SERVICE}" 2>/dev/null)
@ -532,11 +539,11 @@ output_version_summary() {
IS_AN_UPDATE="true" IS_AN_UPDATE="true"
echo " to de deployed: $(tput setaf 1)$app_version ($app_digest)$(tput sgr0)" echo " to de deployed: $(tput setaf 1)$app_version ($app_digest)$(tput sgr0)"
fi fi
else else
warning "Unable to detect deployed version of ${STACK_NAME}_${SERVICE}, please proceed with caution" warning "Unable to detect deployed version of ${STACK_NAME}_${SERVICE}, please proceed with caution"
UNABLE_TO_DETECT="true" UNABLE_TO_DETECT="true"
fi fi
CHECKED_SERVICES+=("$SERVICE")
done done
done done