You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

import subprocess
from utils import *
BASE_IMAGE_DIR = '../images/integration-tests'
DOCKERFILES = [
{
'name': 'u_agent',
'ctx': BASE_IMAGE_DIR,
},
{
'name': 'u_server',
'ctx': BASE_IMAGE_DIR,
},
{
'name': 'u_db',
'ctx': BASE_IMAGE_DIR,
},
{
'name': 'tests_runner',
'ctx': BASE_IMAGE_DIR,
},
]
def docker(args):
cmd = ['docker'] + args
log(f'Running docker command: {cmd}')
return subprocess.run(
cmd,
check=True,
)
def print_errors(errors):
err_msg = '\n'.join(
' {container}: {error}'.format(container=item['container'],
error=item['error'])
for item in errors)
err('There are some errors in next containers:\n%s' % err_msg)
def check_state(containers):
errors = []
for container in containers:
ret, out = subprocess.getstatusoutput(
'docker inspect --format \'{{ .State.Running }}\' %s'
% container)
out = out.strip()
if ret == 0:
if out == 'true':
continue
else:
errors.append({'container': container,
'error': 'Bad state: Running=%s' % out})
else:
errors.append({'container': container,
'error': out})
return errors
def rebuild_images_if_needed(force_rebuild=False):
for img in DOCKERFILES:
ctx = img['ctx']
name = img.get('name')
df_suffix = 'Dockerfile'
img_name = f'unki/{name}'
log(f'Building docker image {img_name}')
cmd = [
'build',
'-t', img_name,
'-f', f'{BASE_IMAGE_DIR}/{name}.{df_suffix}',
ctx,
]
if force_rebuild:
cmd += ['--no-cache']
docker(cmd)