Child images should not be built if parent build failed

Change-Id: Ief35fcf2acb23aea8305096b59b7d9f876ba4d98
This commit is contained in:
Andrey Pavlov 2016-09-08 09:07:15 +03:00
parent c82a1b1b65
commit fb0d94f51c
2 changed files with 50 additions and 3 deletions

View File

@ -227,8 +227,14 @@ def process_dockerfile(dockerfile, tmp_dir, config, executor, future_list,
for child in dockerfile['children']:
if child['match'] or (CONF.builder.keep_image_tree_consistency and
child['name'] in ready_images):
submit_dockerfile_processing(child, tmp_dir, config, executor,
future_list, ready_images)
if dockerfile['build_result'] == 'Failure':
LOG.error("%s: Build will be skipped due to parent image (%s) "
"build failure", child['name'], dockerfile['name'])
child['build_result'] = 'Failure'
child['push_result'] = 'Failure'
else:
submit_dockerfile_processing(child, tmp_dir, config, executor,
future_list, ready_images)
def submit_dockerfile_processing(dockerfile, tmp_dir, config, executor,

View File

@ -101,7 +101,8 @@ class TestBuild(base.TestCase):
'parent': 'root',
'children': ['leaf'],
'match': True,
'path': '/tmp'
'path': '/tmp',
'build_result': 'Success'
},
'leaf': {
'name': 'leaf',
@ -129,6 +130,46 @@ class TestBuild(base.TestCase):
dockerfiles["leaf"], mock.ANY, mock.ANY, mock.ANY,
mock.ANY, ["root", "middle", "leaf"])
@mock.patch("docker.Client")
@mock.patch("fuel_ccp.build.build_dockerfile")
@mock.patch("fuel_ccp.build.submit_dockerfile_processing")
@mock.patch("fuel_ccp.build.create_rendered_dockerfile")
def test_process_dockerfile_parent_build_failed(
self, render_mock, submit_dockerfile_processing_mock,
build_dockerfile_mock, dc_mock):
dockerfiles = {
'parent': {
'name': 'parent',
'full_name': 'ms/parent',
'parent': None,
'children': ['child'],
'match': True,
'path': '/tmp',
'build_result': 'Failure'
},
'child': {
'name': 'child',
'full_name': 'ms/child',
'parent': 'parent',
'children': [],
'match': True,
'path': '/tmp'
}
}
for dockerfile in dockerfiles.values():
if dockerfile['parent']:
dockerfile['parent'] = dockerfiles[dockerfile['parent']]
for i in range(len(dockerfile['children'])):
dockerfile['children'][i] = (
dockerfiles[dockerfile['children'][i]]
)
build.process_dockerfile(
dockerfiles["parent"], mock.ANY, mock.ANY, mock.ANY, mock.ANY,
[])
submit_dockerfile_processing_mock.assert_not_called()
@mock.patch("docker.Client")
@mock.patch("fuel_ccp.build.build_dockerfile")
@mock.patch("fuel_ccp.build.submit_dockerfile_processing")