-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
50 lines (37 loc) · 1.45 KB
/
build.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
import os, sys
import subprocess
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--name", help="name of docker container", default="covid-local-api")
parser.add_argument(
"--version", help="version tag of docker container", default="latest"
)
parser.add_argument(
"--deploy", help="deploy docker container to remote", action="store_true"
)
REMOTE_IMAGE_PREFIX = "cotect/"
args, unknown = parser.parse_known_args()
if unknown:
print("Unknown arguments " + str(unknown))
def call(command):
# Wrapper to print out command
print("Executing: " + command)
return subprocess.call(command, shell=True)
service_name = os.path.basename(os.path.dirname(os.path.realpath(__file__)))
if args.name:
service_name = args.name
versioned_image = service_name + ":" + str(args.version)
latest_image = service_name + ":latest"
failed = call("docker build -t " + versioned_image + " -t " + latest_image + " ./")
if failed:
print("Failed to build container")
sys.exit()
remote_versioned_image = REMOTE_IMAGE_PREFIX + versioned_image
call("docker tag " + versioned_image + " " + remote_versioned_image)
remote_latest_image = REMOTE_IMAGE_PREFIX + latest_image
call("docker tag " + latest_image + " " + remote_latest_image)
if args.deploy:
call("docker push " + remote_versioned_image)
if "SNAPSHOT" not in args.version:
# do not push SNAPSHOT builds as latest version
call("docker push " + remote_latest_image)