forked from suanmeiguo/auto-branch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
65 lines (55 loc) · 1.41 KB
/
deploy.py
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
import boto3
import copy
client = boto3.client('ecs')
IMAGE = '360844283138.dkr.ecr.us-east-1.amazonaws.com/create-branch-from-issue:latest'
APP_NAME = 'create-branch-from-issue'
COMMON_TASK_DEF = {
'name': APP_NAME,
'image': IMAGE,
'cpu': 64,
'memory': 128,
'portMappings': [
{
'containerPort': 5000
},
],
'environment': [
{
'name': 'APP_ENV',
'value': 'production'
},
],
'essential': True,
'command': [
'ruby',
'server.rb'
],
'workingDirectory': '/app'
}
def update_service():
monitor_task_def = copy.deepcopy(COMMON_TASK_DEF)
monitor_task_def.update({'name': APP_NAME})
resp = client.register_task_definition(
family=APP_NAME,
containerDefinitions=[monitor_task_def],
requiresCompatibilities=['EC2']
)
family = resp['taskDefinition']['family']
revision = resp['taskDefinition']['revision']
new_task_arn = family + ':' + str(revision)
print(new_task_arn)
resp = client.update_service(
cluster='ECS',
service=APP_NAME,
desiredCount=1,
taskDefinition=new_task_arn
)
for i in range(revision):
try:
client.deregister_task_definition(
taskDefinition=family + ':' + str(i)
)
except:
continue
if __name__ == '__main__':
update_service()