118
118
# deploy.status
119
119
deploy .get_deployment (deploy .deploymentId )
120
120
121
- while deploy .status in ['Created' , 'InProgress' ]:
121
+ def stop_deploy (deployment_id ):
122
+ try :
123
+ deploy .stop_deployment (deployment_id )
124
+ print ('Rollback deployment success' )
125
+ except :
126
+ print ('Rollback deployment failed' )
127
+ finally :
128
+ exit (1 )
129
+
130
+ while deploy .status in ['Created' , 'InProgress' , 'Queued' ]:
122
131
# Tail logs from ECS service
123
132
ecs_events = task .tail_ecs_events (cluster_name , app_name )
124
133
for event in ecs_events :
133
142
134
143
if last_task_status == 'STOPPED' :
135
144
print ('Containers are being stoped: %s' % last_task_reason )
136
- try :
137
- deploy .stop_deployment (deploy .deploymentId )
138
- print ('Rollback deployment success' )
139
- except :
140
- print ('Rollback deployment failed' )
141
- finally :
142
- exit (1 )
145
+ stop_deploy (deploy .deploymentId )
143
146
144
147
# Rechead limit
145
148
if deploy_timeout_period >= deploy_timeout :
146
149
print ('Deployment timeout: %s seconds' % deploy_timeout )
147
- try :
148
- deploy .stop_deployment (deploy .deploymentId )
149
- print ('Rollback deployment success' )
150
- except :
151
- print ('Rollback deployment failed' )
152
- finally :
153
- exit (1 )
150
+ stop_deploy (deploy .deploymentId )
154
151
155
152
# Get status, increment limit and sleep
156
153
deploy .get_deployment (deploy .deploymentId )
161
158
deployment_info = deploy .get_deployment (deploy .deploymentId )
162
159
163
160
print ()
164
- if deploy .status not in ['Ready' , 'Succeeded' ]:
165
- print ('Deployment failed: %s' % deployment_info ['deploymentInfo' ]['errorInformation' ]['code' ])
166
- print ('Error: %s' % deployment_info ['deploymentInfo' ]['errorInformation' ]['message' ])
167
-
168
161
if deploy .status == "Ready" :
169
162
print ('Deployment of application %s on deployment group %s ready and waiting for cutover' % (application_name , deployment_group ))
170
-
163
+ exit (0 )
164
+
171
165
if deploy .status == "Succeeded" :
172
166
print ('Deployment of application %s on deployment group %s succeeded' % (application_name , deployment_group ))
173
-
167
+ exit (0 )
168
+
169
+ if deployment_info .get ('deploymentInfo' , {}).get ('errorInformation' ):
170
+ print ('Deployment failed: %s' % deployment_info .get ('deploymentInfo' , {}).get ('errorInformation' , {}).get ('code' ))
171
+ print ('Error: %s' % deployment_info .get ('deploymentInfo' , {}).get ('errorInformation' , {}).get ('message' ))
172
+ exit (1 )
0 commit comments