Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from Heavybullets8/container_updates
Browse files Browse the repository at this point in the history
- Add container updates back to heavyscript. 
- dont allow container updates to enter rollback
  • Loading branch information
Heavybullets8 authored Aug 24, 2022
2 parents 7a66c99 + 2bc4ba3 commit 63af8c7
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions functions/update_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rm deploying 2>/dev/null
rm finished 2>/dev/null
while true
do
if while_status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' 2>/dev/null) ; then
if while_status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' 2>/dev/null) ; then
((while_count++))
[[ -z $while_status ]] && continue || echo -e "$while_count\n$while_status" > all_app_status
mapfile -t deploying_check < <(grep ",DEPLOYING," all_app_status)
Expand Down Expand Up @@ -107,7 +107,6 @@ if [[ $stop_before_update == "true" && "$startstatus" != "STOPPED" ]]; then # C
else
echo_array+=("Error: Failed to stop $app_name")
echo_array
final_check
return 1
fi
fi
Expand All @@ -117,16 +116,13 @@ if update_app ;then
else
echo_array+=("Failed to update\nManual intervention may be required")
echo_array
final_check
return
fi
if grep -qs "^$app_name,true" external_services ; then
echo_array
final_check
return
else
after_update_actions
final_check
fi
}
export -f pre_process
Expand All @@ -136,12 +132,12 @@ update_app(){
current_loop=0
while true
do
update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')
if [[ $update_avail == "true" ]]; then
update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3","$6}')
if [[ $update_avail =~ "true" ]]; then
if ! cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null ; then
before_loop=$(head -n 1 all_app_status)
current_loop=0
until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')" != "$update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by.
until [[ "$(grep "^$app_name," all_app_status | awk -F ',' '{print $3","$6}')" != "$update_avail" ]] # Wait for a specific change to app status, or 3 refreshes of the file to go by.
do
if [[ $current_loop -gt 2 ]]; then
cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null || return 1 # After waiting, attempt an update once more, if fails, return error code
Expand All @@ -153,7 +149,7 @@ do
done
fi
break
elif [[ $update_avail == "false" ]]; then
elif [[ ! $update_avail =~ "true" ]]; then
break
else
sleep 3
Expand Down Expand Up @@ -224,7 +220,13 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then
fi
elif [[ "$SECONDS" -ge "$timeout" ]]; then
if [[ $rollback == "true" ]]; then
if [[ "$failed" != "true" ]]; then
if [[ $old_full_ver == "$new_full_ver" ]]; then
echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)")
echo_array+=("This is the result of a container image update..")
echo_array+=("Reverting is not possible, Abandoning")
echo_array
return 1
elif [[ "$failed" != "true" ]]; then
echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)")
echo_array+=("If this is a slow starting application, set a higher timeout with -t")
echo_array+=("If this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration")
Expand Down Expand Up @@ -283,10 +285,10 @@ export -f after_update_actions

rollback_app(){
count=0
update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')
while [[ $update_avail == "false" ]]
app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')
while [[ $app_update_avail == "false" ]]
do
update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')
app_update_avail=$(grep "^$app_name," all_app_status | awk -F ',' '{print $3}')
if [[ $count -gt 2 ]]; then # If failed to rollback app 3 times, return failure to parent shell
return 1
elif ! cli -c "app chart_release rollback release_name=\"$app_name\" rollback_options={\"item_version\": \"$rollback_version\"}" &> /dev/null ; then
Expand All @@ -308,10 +310,11 @@ for i in "${echo_array[@]}"
do
echo -e "$i"
done

final_check
}
export -f echo_array


final_check(){
[[ ! -e finished ]] && touch finished
echo "$app_name,finished" >> finished
Expand Down

0 comments on commit 63af8c7

Please sign in to comment.