forked from WizaXxX/docker_fresh
-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.py
91 lines (71 loc) · 2.59 KB
/
install.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import subprocess
import sys
import platform
from datetime import datetime
import modules.site as site
import modules.centos as centos
import modules.db as db
import modules.forum as forum
import modules.core as core
import modules.gate as gate
class colors:
GREEN = '\033[92m'
WHITE = '\033[97m'
RED = '\033[91m'
def get_docker_image_command():
if platform.system().lower() == 'windows':
return ['docker', 'images']
else:
return ['docker images']
def image_exist(image_name):
full_image_name = 'fresh/' + image.name
result = subprocess.run(get_docker_image_command(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return full_image_name in str(result.stdout)
if '-v' not in sys.argv:
print('parameter -v not specified')
exit(1)
else:
platform_ver = sys.argv[sys.argv.index('-v') + 1]
is_new_path_to_platform = int(platform_ver.split('.')[2]) >= 20
images = []
images.append(centos.New())
images.append(db.New())
images.append(site.New())
images.append(forum.New())
images.append(core.New(is_new_path_to_platform))
images.append(gate.New())
debug = '-debug' in sys.argv
start_time = datetime.now()
print('{}Build is starting{}'.format(colors.GREEN, colors.WHITE))
if debug:
stdout = None
stderr = None
else:
stdout = subprocess.PIPE
stderr = subprocess.PIPE
for image in images:
print('Building', image.name, '...', end='\r')
for command in image.commands_before:
if debug: print(command)
subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr)
command_to_run = [
'docker',
'build',
'-t',
'fresh/' + image.name]
if image.name == 'core' and is_new_path_to_platform:
command_to_run.append('-f')
command_to_run.append('images/' + image.name + '/Dockerfile_20')
command_to_run.append('--build-arg')
command_to_run.append('DISTR_VERSION=' + platform_ver)
command_to_run.append('images/' + image.name)
result = subprocess.run(command_to_run, stdout=stdout, stderr=stderr)
if result.returncode != 0 or not image_exist(image.name):
print('Building', image.name , '...', '{}error'.format(colors.RED), colors.WHITE)
exit(1)
for command in image.commands_after:
if debug: print(command)
subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr)
print('Building', image.name , '...', '{}done'.format(colors.GREEN), colors.WHITE)
end_time = datetime.now() - start_time
print('{}Build finished{}'.format(colors.GREEN, colors.WHITE), 'Duration:', end_time)