2020-04-05 15:06:36 +02:00
|
|
|
import subprocess
|
2020-04-09 18:31:00 +02:00
|
|
|
import sys
|
2020-07-23 19:57:47 +02:00
|
|
|
import platform
|
2020-04-09 18:31:00 +02:00
|
|
|
from datetime import datetime
|
2020-04-05 17:07:02 +02:00
|
|
|
|
2020-04-05 15:06:36 +02:00
|
|
|
import modules.site as site
|
|
|
|
import modules.centos as centos
|
|
|
|
import modules.db as db
|
2020-04-05 15:23:33 +02:00
|
|
|
import modules.forum as forum
|
2020-04-05 17:07:02 +02:00
|
|
|
import modules.core as core
|
|
|
|
import modules.gate as gate
|
2020-04-09 18:31:00 +02:00
|
|
|
|
|
|
|
class colors:
|
|
|
|
GREEN = '\033[92m'
|
|
|
|
WHITE = '\033[97m'
|
2020-04-18 12:57:11 +02:00
|
|
|
RED = '\033[91m'
|
|
|
|
|
2020-07-23 19:57:47 +02:00
|
|
|
def get_docker_image_command():
|
|
|
|
if platform.system().lower() == 'windows':
|
|
|
|
return ['docker', 'images']
|
|
|
|
else:
|
|
|
|
return ['docker images']
|
|
|
|
|
2020-04-18 12:57:11 +02:00
|
|
|
def image_exist(image_name):
|
|
|
|
full_image_name = 'fresh/' + image.name
|
2020-07-23 19:57:47 +02:00
|
|
|
result = subprocess.run(get_docker_image_command(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2020-04-18 12:57:11 +02:00
|
|
|
|
|
|
|
return full_image_name in str(result.stdout)
|
2020-04-05 15:06:36 +02:00
|
|
|
|
2022-06-08 09:29:36 +02:00
|
|
|
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
|
|
|
|
|
2020-04-05 15:06:36 +02:00
|
|
|
images = []
|
2020-04-11 15:23:52 +02:00
|
|
|
images.append(centos.New())
|
|
|
|
images.append(db.New())
|
2020-04-05 20:21:05 +02:00
|
|
|
images.append(site.New())
|
2020-04-11 15:23:52 +02:00
|
|
|
images.append(forum.New())
|
2022-06-08 09:29:36 +02:00
|
|
|
images.append(core.New(is_new_path_to_platform))
|
2020-04-11 15:23:52 +02:00
|
|
|
images.append(gate.New())
|
2020-04-09 18:31:00 +02:00
|
|
|
|
|
|
|
debug = '-debug' in sys.argv
|
2022-06-08 09:29:36 +02:00
|
|
|
|
2020-04-09 18:31:00 +02:00
|
|
|
start_time = datetime.now()
|
|
|
|
print('{}Build is starting{}'.format(colors.GREEN, colors.WHITE))
|
|
|
|
|
2020-04-18 12:57:11 +02:00
|
|
|
if debug:
|
2020-04-09 18:31:00 +02:00
|
|
|
stdout = None
|
|
|
|
stderr = None
|
|
|
|
else:
|
|
|
|
stdout = subprocess.PIPE
|
|
|
|
stderr = subprocess.PIPE
|
2020-04-05 15:06:36 +02:00
|
|
|
|
|
|
|
for image in images:
|
|
|
|
|
2020-04-09 18:31:00 +02:00
|
|
|
print('Building', image.name, '...', end='\r')
|
|
|
|
|
2020-04-05 17:07:02 +02:00
|
|
|
for command in image.commands_before:
|
2020-04-09 18:31:00 +02:00
|
|
|
if debug: print(command)
|
|
|
|
subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr)
|
|
|
|
|
2022-06-08 09:29:36 +02:00
|
|
|
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)
|
2020-04-05 17:07:02 +02:00
|
|
|
|
2020-04-18 12:57:11 +02:00
|
|
|
if result.returncode != 0 or not image_exist(image.name):
|
|
|
|
print('Building', image.name , '...', '{}error'.format(colors.RED), colors.WHITE)
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-05 17:07:02 +02:00
|
|
|
for command in image.commands_after:
|
2020-04-09 18:31:00 +02:00
|
|
|
if debug: print(command)
|
|
|
|
subprocess.call(' '.join(command), shell=True, stdout=stdout, stderr=stderr)
|
2020-04-05 17:07:02 +02:00
|
|
|
|
2020-04-09 18:31:00 +02:00
|
|
|
print('Building', image.name , '...', '{}done'.format(colors.GREEN), colors.WHITE)
|
2020-04-05 15:06:36 +02:00
|
|
|
|
2020-04-09 18:31:00 +02:00
|
|
|
end_time = datetime.now() - start_time
|
|
|
|
print('{}Build finished{}'.format(colors.GREEN, colors.WHITE), 'Duration:', end_time)
|