-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateTaskSet-Green.sh
executable file
·103 lines (67 loc) · 3.83 KB
/
CreateTaskSet-Green.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# Use this scrip for your new deployments - It will be always considered Green in regards to this script
# DON`T Miss to update TaskDefinition and task_set_blue value for new deployment and current PRIMARY deployment id before running this script
# set these values to resources that exist in your account:
cluster_name=default
service_name=BlueGreenTaskSetTesting
launch_type=FARGATE
vpc_id=vpc-2786cc40
vpc_subnets=subnet-0f2f0046,subnet-7c02301b,subnet-a00da0f8
vpc_security_group=sg-11de8369
requestedDesiredCount=100
taskdef_family=nginx_fargate
taskdef_family_version=2
task_set_blue="ecs-svc/4826018505467357700"
echo "Deployment Started.." | ts
#Create TaskSet without Scale
task_set_out="$(aws ecs create-task-set --cluster $cluster_name --service $service_name --external-id green --task-definition $taskdef_family:$taskdef_family_version --launch-type $launch_type --network-configuration "awsvpcConfiguration={subnets=[$vpc_subnets],securityGroups=[$vpc_security_group],assignPublicIp=ENABLED}")"
task_set_green="$(echo $task_set_out | jq -r .taskSet.id)"
echo "TaskSet green Created ... task_set_green : " $task_set_green | ts
#Wait for it to reach "STEADY_STATE"
while [ "$stabilityStatus" != "STEADY_STATE" ]
do
#To prevent other API throttling wait 1 sec - can use exponential backoff in production
sleep 1
task_set_out="$(aws ecs describe-task-sets --service $service_name --cluster default --task-set $task_set_green)"
stabilityStatus="$(echo $task_set_out | jq -r .taskSets[0].stabilityStatus)"
echo "stabilityStatus :" $stabilityStatus | ts
done
#Now Scale it to 100%
echo "Scaling to 100%"
task_set_out="$(aws ecs update-task-set --cluster $cluster_name --service $service_name --scale unit=PERCENT,value=100 --task-set $task_set_green)"
task_set_green="$(echo $task_set_out | jq -r .taskSet.id)"
echo "TaskSet Green scaled ... task_set_green : " $task_set_green | ts
task_set_out="$(aws ecs describe-task-sets --service $service_name --cluster default --task-set $task_set_green)"
stabilityStatus="$(echo $task_set_out | jq -r .taskSets[0].stabilityStatus)"
echo "stabilityStatus :" $stabilityStatus | ts
#Wait for greent to reach "STEADY_STATE"
echo "Wait for green to reach STEADY_STATE"
while [ "$stabilityStatus" != "STEADY_STATE" ]
do
#To prevent other API throttling wait 1 sec - can use exponential backoff in production
sleep 1
task_set_out="$(aws ecs describe-task-sets --service $service_name --cluster default --task-set $task_set_green)"
stabilityStatus="$(echo $task_set_out | jq -r .taskSets[0].stabilityStatus)"
echo "stabilityStatus :" $stabilityStatus | ts
done
#Make green TaskSet Primary
echo "Make green TaskSet Primary"
aws ecs update-service-primary-task-set --cluster $cluster_name --service $service_name --primary-task-set $task_set_green
aws ecs describe-services --cluster $cluster_name --services $service_name
task_set_out="$(aws ecs describe-task-sets --service $service_name --cluster default --task-set $task_set_green)"
stabilityStatus="$(echo $task_set_out | jq -r .taskSets[0].stabilityStatus)"
echo "stabilityStatus :" $stabilityStatus | ts
echo "Wait for green to reach STEADY_STATE"
while [ "$stabilityStatus" != "STEADY_STATE" ]
do
#To prevent other API throttling wait 1 sec - can use exponential backoff in production
sleep 1
task_set_out="$(aws ecs describe-task-sets --service $service_name --cluster default --task-set $task_set_green)"
stabilityStatus="$(echo $task_set_out | jq -r .taskSets[0].stabilityStatus)"
echo "stabilityStatus :" $stabilityStatus | ts
done
#Scale down Blue TaskSet.
echo "Scale down Blue TaskSet."
aws ecs delete-task-set --cluster $cluster_name --service $service_name --task-set $task_set_blue --force
echo "Deployment Finished.." | ts
echo "Now you can roll out Green TaskSet..."