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.

82 lines
2.0 KiB

import subprocess
from utils import *
BASE_IMAGE_DIR = '../images/integration-tests'
DOCKERFILES = {
'u_agent': {
'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_agent'
},
'u_server': {
'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_server'
},
'u_db': {
'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_db'
},
'tests_runner': {
'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'tests_runner'
},
}
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_name, data in DOCKERFILES.items():
ctx = data['ctx']
df_prefix = data.get('dockerfile_prefix')
df_suffix = 'Dockerfile'
img_name = f'unki/{img_name}'
log(f'Building docker image {img_name}')
cmd = [
'build',
'-t',
img_name,
ctx,
]
if df_prefix:
cmd += ['-f', f'{ctx}/{df_prefix}.{df_suffix}']
if force_rebuild:
cmd += ['--no-cache']
docker(cmd)