Merge "Add new --skip-existing option to kolla-build"

This commit is contained in:
Jenkins 2017-07-07 02:58:48 +00:00 committed by Gerrit Code Review
commit ccc1911ad8
4 changed files with 28 additions and 7 deletions

View File

@ -190,6 +190,8 @@ _CLI_OPTS = [
help='Turn on debugging log level'),
cfg.BoolOpt('skip-parents', default=False,
help='Do not rebuild parents of matched images'),
cfg.BoolOpt('skip-existing', default=False,
help='Do not rebuild images present in the docker cache'),
cfg.DictOpt('build-args',
help='Set docker build time variables'),
cfg.BoolOpt('keep', default=False,

View File

@ -139,7 +139,7 @@ class DockerTask(task.Task):
class Image(object):
def __init__(self, name, canonical_name, path, parent_name='',
status=STATUS_UNPROCESSED, parent=None,
source=None, logger=None):
source=None, logger=None, docker_client=None):
self.name = name
self.canonical_name = canonical_name
self.path = path
@ -153,6 +153,7 @@ class Image(object):
self.children = []
self.plugins = []
self.additions = []
self.dc = docker_client
def copy(self):
c = Image(self.name, self.canonical_name, self.path,
@ -168,6 +169,9 @@ class Image(object):
c.additions = list(self.additions)
return c
def in_docker_cache(self):
return len(self.dc.images(name=self.canonical_name, quiet=True)) == 1
def __repr__(self):
return ("Image(%s, %s, %s, parent_name=%s,"
" status=%s, parent=%s, source=%s)") % (
@ -397,7 +401,7 @@ class BuildTask(DockerTask):
self.logger.debug('Processing')
if image.status == STATUS_SKIPPED:
self.logger.info('Skipping %s (--skip-parents)' % image.name)
self.logger.info('Skipping %s' % image.name)
return
if image.status == STATUS_UNMATCHED:
@ -573,6 +577,9 @@ class KollaWorker(object):
self.image_statuses_skipped = dict()
self.maintainer = conf.maintainer
docker_kwargs = docker.utils.kwargs_from_env()
self.dc = docker.APIClient(version='auto', **docker_kwargs)
def _get_images_dir(self):
possible_paths = (
PROJECT_ROOT,
@ -809,6 +816,9 @@ class KollaWorker(object):
image = image.parent
if self.conf.skip_parents:
image.status = STATUS_SKIPPED
elif (self.conf.skip_existing and
image.in_docker_cache()):
image.status = STATUS_SKIPPED
else:
image.status = STATUS_MATCHED
LOG.debug('Image %s matched regex', image.name)
@ -866,9 +876,9 @@ class KollaWorker(object):
})
if self.image_statuses_skipped:
LOG.debug("=====================================")
LOG.debug("Images skipped due to --skip-parents")
LOG.debug("=====================================")
LOG.debug("================================")
LOG.debug("Images skipped due build options")
LOG.debug("================================")
for name in self.image_statuses_skipped.keys():
LOG.debug(name)
results['skipped'].append({
@ -936,7 +946,8 @@ class KollaWorker(object):
del match
image = Image(image_name, canonical_name, path,
parent_name=parent_name,
logger=make_a_logger(self.conf, image_name))
logger=make_a_logger(self.conf, image_name),
docker_client=self.dc)
if self.install_type == 'source':
# NOTE(jeffrey4l): register the opts if the section didn't

View File

@ -227,6 +227,9 @@ class KollaWorkerTest(base.TestCase):
self.images = [image, image_child, image_unmatched,
image_error, image_built]
patcher = mock.patch('docker.APIClient')
self.addCleanup(patcher.stop)
self.mock_client = patcher.start()
def test_supported_base_type(self):
rh_base = ['centos', 'oraclelinux', 'rhel']
@ -409,7 +412,8 @@ class MainTest(base.TestCase):
self.assertEqual(1, result)
@mock.patch('sys.argv')
def test_run_build(self, mock_sys):
@mock.patch('docker.APIClient')
def test_run_build(self, mock_client, mock_sys):
result = build.run_build()
self.assertTrue(result)

View File

@ -0,0 +1,4 @@
---
features:
- Add new `--skip-existing` kolla-build option that skips images present in
the docker cache.