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.
85 lines
2.0 KiB
85 lines
2.0 KiB
import subprocess |
|
from utils import * |
|
|
|
BASE_IMAGE_DIR = '../images/integration-tests' |
|
|
|
# do not reorder |
|
DOCKERFILES = [ |
|
{ |
|
'name': 'u_agent', |
|
'ctx': BASE_IMAGE_DIR, |
|
}, |
|
{ |
|
'name': 'u_server', |
|
'ctx': BASE_IMAGE_DIR, |
|
}, |
|
{ |
|
'name': 'u_db', |
|
'ctx': BASE_IMAGE_DIR, |
|
}, |
|
{ |
|
'name': 'tests_base', |
|
'ctx': '../lib', |
|
}, |
|
{ |
|
'name': 'tests_runner', |
|
'ctx': '../integration', |
|
}, |
|
] |
|
|
|
|
|
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, |
|
ctx, |
|
] |
|
cmd += ['-f', f'{BASE_IMAGE_DIR}/{name}.{df_suffix}'] |
|
if force_rebuild: |
|
cmd += ['--no-cache'] |
|
docker(cmd)
|
|
|