/
build_image.py
57 lines (45 loc) · 1.37 KB
/
build_image.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
import os
from json import loads, dumps
from sys import argv, exit
if __name__ == "__main__":
if len(argv) < 2:
exit(-1)
if argv[1] == "frontend":
from frontend.vars import docker_vars, sec_vars
from frontend.image import build_image
elif argv[1] == "annex":
from annex.vars import docker_vars, sec_vars
from annex.image import build_image
else:
exit(-1)
config = None
if len(argv) == 3:
config = argv[2]
if config is None and os.path.exists(os.path.join(argv[1], "last_config.json")):
from fabric.operations import prompt
use_last_config = prompt("Use last configuration (y or n)? [DEFAULT y]: ")
if len(use_last_config) == 0 or use_last_config == "y":
config = os.path.join(argv[1], "last_config.json")
if config is None:
config = {}
elif type(config) is str:
try:
with open(config, 'rb') as c:
config = loads(c.read())
except Exception as e:
print e
exit(-1)
return_dir = os.getcwd()
os.chdir(argv[1])
from copy import deepcopy
from utils import verify_config
config = verify_config(config, [('docker', docker_vars), ('secrets', sec_vars)])
with open("last_config.json", 'wb+') as c:
last_config = deepcopy(config)
if 'USER_PWD' in last_config['docker'].keys():
del last_config['docker']['USER_PWD']
c.write(dumps(last_config))
del last_config
res = build_image(config)
os.chdir(return_dir)
exit(0 if res else -1)