1
0
mirror of https://github.com/1C-Company/docker_fresh.git synced 2024-12-04 10:24:48 +02:00
docker_fresh/install.py

65 lines
1.8 KiB
Python
Raw Normal View History

2020-04-05 15:06:36 +02:00
import subprocess
2020-04-09 18:31:00 +02:00
import sys
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'
def image_exist(image_name):
full_image_name = 'fresh/' + image.name
2020-07-21 16:49:06 +02:00
result = subprocess.run(['docker' ,'images'], 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
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())
images.append(core.New())
images.append(gate.New())
2020-04-09 18:31:00 +02:00
debug = '-debug' in sys.argv
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)
2020-04-18 12:57:11 +02:00
result = subprocess.run(['docker', 'build', '-t', 'fresh/' + image.name, 'images/' + image.name],
2020-04-09 18:31:00 +02:00
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)