Re-factor version output logic and fix bug

It was showing empty strings for deployed versions it could not find.
Now, it will not change messages to output if it can not detect the
versions deployed (containers dont have the tag).
This commit is contained in:
Luke Murphy 2021-03-04 13:10:00 +01:00
parent d3776f4424
commit 7f5e753dfd
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

56
abra
View File

@ -421,6 +421,24 @@ if [ -z "$ABRA_ENV" ] && [ -f .env ] && type direnv > /dev/null 2>&1 && ! direnv
error "direnv is blocked, run direnv allow" error "direnv is blocked, run direnv allow"
fi fi
require_consent_for_update (){
if [ "$CONSENT_TO_UPDATE" = "false" ] && \
[ -n "$deployed_version" ] && \
[ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then
error "This deployment will be an app update from version ${deployed_version} -> ${ABRA_TYPE_VERSION}
Please pass the --update option to the deploy to deploy the update"
fi
if [ "$CONSENT_TO_UPDATE" = "false" ] && \
[ "$ABRA_TYPE_VERSION" = "$deployed_version" ] && \
[ "$ABRA_TYPE_DIGEST" != "$deployed_digest" ]; then
error "The app version is the same but the image digest has changed from ${deployed_digest} -> ${ABRA_TYPE_DIGEST}
This should not happen! This may mean that the upstream app developers are overwriting their image tags
Get in touch and let's make the builds stable together: https://docs.cloud.autonomic.zone/contact/
Please pass the --update option to deploy the update anyway"
fi
}
###### Run-time loading ###### Run-time loading
load_abra_sh() { load_abra_sh() {
@ -887,26 +905,22 @@ sub_app_deploy (){
deployed_version=$(echo "$deployed_version_digest" | cut -d- -f1) deployed_version=$(echo "$deployed_version_digest" | cut -d- -f1)
deployed_digest=$(echo "$deployed_version_digest" | cut -d- -f2) deployed_digest=$(echo "$deployed_version_digest" | cut -d- -f2)
if [ "$CONSENT_TO_UPDATE" = "false" ] && [ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then about_to_deploy_msg="About to deploy:"
error "This deployment will be an app update from version ${deployed_version} -> ${ABRA_TYPE_VERSION} version_msg=" Version: $(tput setaf 2)${ABRA_TYPE_VERSION} (digest: ${ABRA_TYPE_DIGEST})$(tput sgr0)"
Please pass the --update option to the deploy to deploy the update"
fi if [ -n "$deployed_version" ] && [ -n "$deployed_digest" ]; then
require_consent_for_update
if [ "$CONSENT_TO_UPDATE" = "false" ] && \
[ "$ABRA_TYPE_VERSION" = "$deployed_version" ] && \ if [ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then
[ "$ABRA_TYPE_DIGEST" != "$deployed_digest" ]; then about_to_deploy_msg="About to deploy (NEW VERSION):"
error "The app version is the same but the image digest has changed from ${deployed_digest} -> ${ABRA_TYPE_DIGEST} fi
This should not happen! This may mean that the upstream app developers are overwriting their image tags
Get in touch and let's make the builds stable together: https://docs.cloud.autonomic.zone/contact/ if [ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then
Please pass the --update option to deploy the update anyway" version_msg=" Version: $(tput setaf 2)$deployed_version -> ${ABRA_TYPE_VERSION} (digest: $deployed_digest -> ${ABRA_TYPE_DIGEST})$(tput sgr0)"
fi fi
if [ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then
echo "About to deploy (NEW VERSION):"
else
echo "About to deploy:"
fi fi
echo "$about_to_deploy_msg"
echo " Server: $(tput setaf 4)${SERVER}$(tput sgr0)" echo " Server: $(tput setaf 4)${SERVER}$(tput sgr0)"
if [ "${COMPOSE_FILE/:/}" == "${COMPOSE_FILE}" ]; then if [ "${COMPOSE_FILE/:/}" == "${COMPOSE_FILE}" ]; then
@ -925,11 +939,7 @@ sub_app_deploy (){
fi fi
if [ -n "$ABRA_TYPE_VERSION" ] && [ -n "$ABRA_TYPE_DIGEST" ]; then if [ -n "$ABRA_TYPE_VERSION" ] && [ -n "$ABRA_TYPE_DIGEST" ]; then
if [ "$ABRA_TYPE_VERSION" != "$deployed_version" ]; then echo "$version_msg"
echo " Version: $(tput setaf 2)$deployed_version -> ${ABRA_TYPE_VERSION} (digest: $deployed_digest -> ${ABRA_TYPE_DIGEST})$(tput sgr0)"
else
echo " Version: $(tput setaf 2)${ABRA_TYPE_VERSION} (digest: ${ABRA_TYPE_DIGEST})$(tput sgr0)"
fi
fi fi
echo " Stack: $(tput setaf 1)${STACK_NAME}$(tput sgr0)" echo " Stack: $(tput setaf 1)${STACK_NAME}$(tput sgr0)"