def task_dependency_puller(docker_client, dockerfileList, configuration, task): """ Pulls dependency images before building """ def pull_image(image): print ' -> Pull base image %s ' % image if configuration.get('dryRun'): return True pull_image_name = DockerfileUtility.image_basename(image) pull_image_tag = DockerfileUtility.extract_image_name_tag(image) pull_status = False for retry_count in range(0, configuration.get('retry')): pull_status = docker_client.pull_image( name=pull_image_name, tag=pull_image_tag, ) if pull_status: break elif retry_count < (configuration.get('retry') - 1): print ' failed, retrying... (try %s)' % (retry_count + 1) else: print ' failed, giving up' if not pull_status: return False return True image_list = [] for dockerfile in dockerfileList: # Pull base image (FROM: xxx) first if DockerfileUtility.check_if_base_image_needs_pull( dockerfile['image']['from'], configuration): image_list.append(dockerfile['image']['from']) # Pull straged images (multi-stage dockerfiles) for multiStageImage in dockerfile['image']['multiStageImages']: if DockerfileUtility.check_if_base_image_needs_pull( multiStageImage, configuration): image_list.append(multiStageImage) # filter only unique image names image_list = set(image_list) # pull images for image in set(image_list): if not pull_image(image): return False return True
def task_dependency_puller(docker_client, dockerfileList, configuration, task): """ Pulls dependency images before building """ def pull_image(image): print ' -> Pull base image %s ' % image if configuration.get('dryRun'): return True pull_image_name = DockerfileUtility.image_basename(image) pull_image_tag = DockerfileUtility.extract_image_name_tag(image) pull_status = False for retry_count in range(0, configuration.get('retry')): pull_status = docker_client.pull_image( name=pull_image_name, tag=pull_image_tag, ) if pull_status: break elif retry_count < (configuration.get('retry') - 1): print ' failed, retrying... (try %s)' % (retry_count + 1) else: print ' failed, giving up' if not pull_status: return False return True image_list = [] for dockerfile in dockerfileList: # Pull base image (FROM: xxx) first if DockerfileUtility.check_if_base_image_needs_pull(dockerfile['image']['from'], configuration): image_list.append(dockerfile['image']['from']) # Pull straged images (multi-stage dockerfiles) for multiStageImage in dockerfile['image']['multiStageImages']: if DockerfileUtility.check_if_base_image_needs_pull(multiStageImage, configuration): image_list.append(multiStageImage) # filter only unique image names image_list = set(image_list) # pull images for image in set(image_list): if not pull_image(image): return False return True
def task_run(docker_client, dockerfile, configuration, task): """ Build one Dockerfile """ pull_parent_image = DockerfileUtility.check_if_base_image_needs_pull(dockerfile, configuration) if configuration.get('dryRun'): print ' from: %s (pull: %s)' % (dockerfile['image']['from'], ('yes' if pull_parent_image else 'no')) print ' path: %s' % dockerfile['path'] print ' dep: %s' % (DockerBuildTaskLoader.human_task_name_list(task.task_dep) if task.task_dep else 'none') return True # Pull base image (FROM: xxx) first if pull_parent_image: print ' -> Pull base image %s ' % dockerfile['image']['from'] pull_image_name = DockerfileUtility.image_basename(dockerfile['image']['from']) pull_image_tag = DockerfileUtility.extract_image_name_tag(dockerfile['image']['from']) pull_status = False for retry_count in range(0, configuration.get('retry')): pull_status = docker_client.pull_image( name=pull_image_name, tag=pull_image_tag, ) if pull_status: break elif retry_count < (configuration.get('retry') - 1): print ' failed, retrying... (try %s)' % (retry_count+1) else: print ' failed, giving up' if not pull_status: return False ## Build image print ' -> Building image %s ' % dockerfile['image']['fullname'] build_status = False for retry_count in range(0, configuration.get('retry')): build_status = docker_client.build_dockerfile( path=dockerfile['path'], name=dockerfile['image']['fullname'], nocache=configuration.get('dockerBuild.noCache'), ) if build_status: break elif retry_count < (configuration.get('retry')-1): print ' failed, retrying... (try %s)' % (retry_count+1) else: print ' failed, giving up' return build_status
def task_run(docker_client, dockerfile, configuration, task): """ Build one Dockerfile """ pull_parent_image = DockerfileUtility.check_if_base_image_needs_pull( dockerfile, configuration) if configuration.get('dryRun'): print ' from: %s (pull: %s)' % (dockerfile['image']['from'], ('yes' if pull_parent_image else 'no')) print ' path: %s' % dockerfile['path'] print ' dep: %s' % ( DockerBuildTaskLoader.human_task_name_list(task.task_dep) if task.task_dep else 'none') return True # Pull base image (FROM: xxx) first if pull_parent_image: print ' -> Pull base image %s ' % dockerfile['image']['from'] pull_image_name = DockerfileUtility.image_basename( dockerfile['image']['from']) pull_image_tag = DockerfileUtility.extract_image_name_tag( dockerfile['image']['from']) pull_status = False for retry_count in range(0, configuration.get('retry')): pull_status = docker_client.pull_image( name=pull_image_name, tag=pull_image_tag, ) if pull_status: break elif retry_count < (configuration.get('retry') - 1): print ' failed, retrying... (try %s)' % (retry_count + 1) else: print ' failed, giving up' if not pull_status: return False ## Build image print ' -> Building image %s ' % dockerfile['image']['fullname'] build_status = False for retry_count in range(0, configuration.get('retry')): build_status = docker_client.build_dockerfile( path=dockerfile['path'], name=dockerfile['image']['fullname'], nocache=configuration.get('dockerBuild.noCache'), ) if build_status: break elif retry_count < (configuration.get('retry') - 1): print ' failed, retrying... (try %s)' % (retry_count + 1) else: print ' failed, giving up' return build_status