16
16
# ********************************************************************************
17
17
18
18
# ********************************************************************************
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
20
20
# example, you are doing build and deployment work and you want to call
21
21
# Active Deploy instead of the direct CF or Container commands you are using now.
22
22
# Maybe you are using Jenkins and want to call out to Active Deploy.
@@ -36,30 +36,30 @@ SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
36
36
# Sets up tracing
37
37
set -x # trace steps
38
38
39
- # Log some helpful information for debugging
40
- env
41
- find . -print
42
-
43
-
44
39
# 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.
45
40
46
41
# ## Very fast deploy
47
42
# rampup="1m"
48
43
# test="1s"
49
44
# rampdown="1m"
45
+ # TIMEOUT_IN_MINUTES=6
50
46
51
47
# ## Moderate speed deploy
52
48
# rampup="10m"
53
49
# test="10m"
54
50
# rampdown="5m"
51
+ # TIMEOUT_IN_MINUTES=40
55
52
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
57
57
58
58
# 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 )
60
60
61
61
# 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 )
63
63
64
64
# Status values are listed here => https://www.ng.bluemix.net/docs/services/ActiveDeploy/index.html - Basically they are:
65
65
# Status - Description
@@ -73,17 +73,14 @@ status=$(cf active-deploy-check-status "$id" -q)
73
73
# Loop while active deploy is in progress
74
74
# ## TODO: Also might want to put a counter on this and time out depending on your timing settings after it's clearly hung
75
75
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
81
78
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 )) ]
84
81
do
85
82
sleep 60
86
- status=$( cf active-deploy-check-status " $id " -q )
83
+ status=$( cf active-deploy-check-status " $id " --quiet )
87
84
done
88
85
89
86
if [[ " ${update_status} " == ' paused' ]]; then
@@ -99,12 +96,11 @@ elif [[ "${update_status}" == 'rolled_back' ]]; then
99
96
echo " Deployment is in rolled_back"
100
97
101
98
elif [[ " ${update_status} " == ' failed' ]]; then
102
- echo " Deployment is in failed"
99
+ echo " Deployment failed"
103
100
104
101
else
105
- echo " Deployment is in 'no idea' "
102
+ echo " Deployment status is $update_status "
106
103
107
104
fi
108
105
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