Skip to content

Commit dbd7ecd

Browse files
committed
Script cleanup
1 parent f3709c9 commit dbd7ecd

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

integration/ActiveDeploy-script_integration-example.sh

100644100755
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#********************************************************************************
1717

1818
#********************************************************************************
19-
# Purpose: This script shows you how to call Active Deploy from an script. For
19+
# Purpose: This script shows you how to call Active Deploy from a script. For
2020
# example, you are doing build and deployment work and you want to call
2121
# Active Deploy instead of the direct CF or Container commands you are using now.
2222
# Maybe you are using Jenkins and want to call out to Active Deploy.
@@ -36,30 +36,30 @@ SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3636
# Sets up tracing
3737
set -x # trace steps
3838

39-
# Log some helpful information for debugging
40-
env
41-
find . -print
42-
43-
4439
# Setup for Active Deploy phase times - you may or may not use these, although you probably should control how long you want it to run.
4540

4641
### Very fast deploy
4742
# rampup="1m"
4843
# test="1s"
4944
# rampdown="1m"
45+
# TIMEOUT_IN_MINUTES=6
5046

5147
### Moderate speed deploy
5248
# rampup="10m"
5349
# test="10m"
5450
# rampdown="5m"
51+
# TIMEOUT_IN_MINUTES=40
5552

56-
53+
if [[ -z ${rampup} ]]; then echo "You must set rampup"; exit 1; fi
54+
if [[ -z ${test} ]]; then echo "You must set test"; exit 1; fi
55+
if [[ -z ${rampdown} ]]; then echo "You must set rampdown"; exit 1; fi
56+
if [[ -z ${TIMEOUT_IN_MINUTES} ]]; then echo "You must set TIMEOUT_IN_MINUTES"; exit 1; fi
5757

5858
# Start the active deploy - record back the Active Deploy identification
59-
id=$(cf active-deploy-create $old_app_name $new_app_name -u $rampup -t $test -w $rampdown | grep "deployment id:" | awk '{print $3}')
59+
id=$(cf active-deploy-create $old_app_name $new_app_name -u $rampup -t $test -w $rampdown --quiet)
6060

6161
# Get the status of deploy using id
62-
status=$(cf active-deploy-check-status "$id" -q)
62+
status=$(cf active-deploy-check-status "$id" --quiet)
6363

6464
#Status values are listed here => https://www.ng.bluemix.net/docs/services/ActiveDeploy/index.html - Basically they are:
6565
# Status - Description
@@ -73,17 +73,14 @@ status=$(cf active-deploy-check-status "$id" -q)
7373
# Loop while active deploy is in progress
7474
### TODO: Also might want to put a counter on this and time out depending on your timing settings after it's clearly hung
7575

76-
# ED: Can you please write a variable that indexes base on some setable timer? Like 50% longer than their entire phase timings?
77-
# so if your timings bring you to say 75 min - and say +15 min you should bail and declare failure
78-
# Like TIMEOUT = rampup+test+rampdown + 1.50
79-
# Then if that timeout is passed?
80-
# Or something like that
76+
# We can use the -check-phase subcommand or poll from the script to wait for completion
77+
# cf active-deploy-check-phase "$id" --phase final --wait $(TIMEOUT_IN_MINUTES)m
8178

82-
83-
while [ $status = "in_progress" ] && [ PAST TIMEOUT RANGE ]
79+
# $SECONDS is a Bash built-in from the start f script execution
80+
while [ $status = "in_progress" ] && [ $SECONDS -lt $(( TIMEOUT_IN_MINUTES*60 )) ]
8481
do
8582
sleep 60
86-
status=$(cf active-deploy-check-status "$id" -q)
83+
status=$(cf active-deploy-check-status "$id" --quiet)
8784
done
8885

8986
if [[ "${update_status}" == 'paused' ]]; then
@@ -99,12 +96,11 @@ elif [[ "${update_status}" == 'rolled_back' ]]; then
9996
echo "Deployment is in rolled_back"
10097

10198
elif [[ "${update_status}" == 'failed' ]]; then
102-
echo "Deployment is in failed"
99+
echo "Deployment failed"
103100

104101
else
105-
echo "Deployment is in 'no idea'"
102+
echo "Deployment status is $update_status"
106103

107104
fi
108105

109-
#ED: What else should we mention to them here? Clean up? Deleting the noew v1 1 instance group?
110-
106+
# At this point use `cf delete` or `cf ic group rm` to remove the old v1 1 instance group.

0 commit comments

Comments
 (0)