generated from itba-cloud/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pushimages.py
55 lines (43 loc) · 1.31 KB
/
pushimages.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
import os
import sys
region = 'us-east-1'
account = "334568240727"
imagesMap = {
"users": {
'name': "ecr-users",
'location': 'resources/services/users/',
'service': "users-service"
},
"courses": {
'name': "ecr-courses",
'location': 'resources/services/courses/',
'service': "courses-service"
}
}
#select images
images = []
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
if arg in imagesMap:
images.append(imagesMap[arg])
else:
images = imagesMap.values()
# login
os.system(
f"aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {account}.dkr.ecr.{region}.amazonaws.com")
for image in images:
# build
os.system(f"docker build -t {image['name']} {image['location']}")
# tag
os.system(
f"docker tag {image['name']}:latest {account}.dkr.ecr.{region}.amazonaws.com/{image['name']}:latest")
answer = input("(y/n) to push and redeploy...")
if answer != "y":
exit()
for image in images:
# push
os.system(
f"docker push {account}.dkr.ecr.{region}.amazonaws.com/{image['name']}:latest")
# redeploy
os.system(
f"aws ecs update-service --cluster final-cloud-g7-ecs-cluster --service {image['service']} --region {region} --force-new-deployment")