diff --git a/AUTHORS b/AUTHORS index 868b1727..9f07727c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,6 +10,7 @@ Pierre-Louis Bonicoli Greg DeKoenigsberg Sandra Wills Dusty Mabe +Eric D Helms Josiah Goodson Dominik del Bondio Dylan Silva @@ -42,7 +43,6 @@ John Matthews Sean Summers Alex Yanchenko Balazs Zagyvai -Eric D Helms Trishna Guha Ali Asad Lotia szinck1 @@ -56,3 +56,4 @@ John R Barker Sidharth Surana grimmjow Shea Stewart +Michael Carden diff --git a/container/core.py b/container/core.py index 44d9f923..64140325 100644 --- a/container/core.py +++ b/container/core.py @@ -641,6 +641,12 @@ def conductorcmd_build(engine_name, project_name, services, cache=True, local_py continue logger.info(u'Building service...', service=service_name, project=project_name) cur_image_id = engine.get_image_id_by_tag(service['from']) + if not cur_image_id: + cur_image_id = engine.pull_image_by_tag(service['from']) + if not cur_image_id: + raise AnsibleContainerException( + "Failed to find image {}. Try `docker image pull {}`".format(service['from']) + ) # the fingerprint hash tracks cacheability fingerprint_hash = hashlib.sha256('%s::' % cur_image_id) logger.debug(u'Base fingerprint hash = %s', fingerprint_hash.hexdigest(), diff --git a/container/docker/engine.py b/container/docker/engine.py index 8fb46dae..56fa7d61 100644 --- a/container/docker/engine.py +++ b/container/docker/engine.py @@ -297,8 +297,8 @@ def _add_var_list(vars): u"container", conductor_path) volumes[conductor_path] = {'bind': '/_ansible/container', 'mode': 'rw'} - if command in ('login', 'push') and params.get('config_path'): - config_path = params.get('config_path') + if command in ('login', 'push', 'build'): + config_path = params.get('config_path') or self.auth_config_path volumes[config_path] = {'bind': config_path, 'mode': 'rw'} @@ -499,6 +499,18 @@ def get_build_stamp_for_image(self, image_id): build_stamp = [tag for tag in image.tags if not tag.endswith(':latest')][0].split(':')[-1] return build_stamp + @conductor_only + def pull_image_by_tag(self, image): + repo, tag = image.split(':') + if not tag: + tag = 'latest' + logger.debug("Pulling image {}:{}".format(repo, tag)) + try: + image_id = self.client.images.pull(repo, tag=tag) + except docker_errors.APIError as exc: + raise exceptions.AnsibleContainerException("Failed to pull {}: {}".format(image_name, str(exc))) + return image_id + @log_runs @conductor_only def flatten_container(self, diff --git a/container/engine.py b/container/engine.py index 9af0e135..67722d58 100644 --- a/container/engine.py +++ b/container/engine.py @@ -133,6 +133,10 @@ def get_image_id_by_fingerprint(self, fingerprint): def get_image_id_by_tag(self, tag): raise NotImplementedError() + @conductor_only + def pull_image_by_tag(self, image_name): + raise NotImplementedError + def get_latest_image_id_for_service(self, service_name): raise NotImplementedError()