Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Pull missing images during build (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Houseknecht authored Jul 11, 2017
1 parent 0d54b0e commit 5108f41
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Pierre-Louis Bonicoli <[email protected]>
Greg DeKoenigsberg <[email protected]>
Sandra Wills <[email protected]>
Dusty Mabe <[email protected]>
Eric D Helms <[email protected]>
Josiah Goodson <[email protected]>
Dominik del Bondio <[email protected]>
Dylan Silva <[email protected]>
Expand Down Expand Up @@ -42,7 +43,6 @@ John Matthews <[email protected]>
Sean Summers <[email protected]>
Alex Yanchenko <[email protected]>
Balazs Zagyvai <[email protected]>
Eric D Helms <[email protected]>
Trishna Guha <[email protected]>
Ali Asad Lotia <[email protected]>
szinck1 <[email protected]>
Expand All @@ -56,3 +56,4 @@ John R Barker <[email protected]>
Sidharth Surana <[email protected]>
grimmjow <[email protected]>
Shea Stewart <[email protected]>
Michael Carden <[email protected]>
6 changes: 6 additions & 0 deletions container/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 14 additions & 2 deletions container/docker/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions container/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 5108f41

Please sign in to comment.