def pull_arbitrary(collector, image, **kwargs): """Pull an arbitrary image""" image_index_of = lambda image: urlparse("https://{0}".format(image)).netloc if image.startswith("file://"): parsed = urlparse(image) filename = parsed.netloc + parsed.path if not os.path.exists(filename): raise HarpoonError("Provided file doesn't exist!", wanted=image) with open(filename) as fle: image_indexes = [(line.strip(), image_index_of(line.strip())) for line in fle] else: image_indexes = [(image, image_index_of(image))] authentication = collector.configuration.get("authentication", NotSpecified) for index, (image, image_index) in enumerate(image_indexes): image = { "image_name": image, "harpoon": collector.configuration["harpoon"], "commands": ["FROM scratch"], "image_index": image_index, "assume_role": NotSpecified, "authentication": authentication } meta = Meta(collector.configuration, []).at("images").at("__arbitrary_{0}__".format(index)) image = HarpoonSpec().image_spec.normalise(meta, image) Syncer().pull(image)
def pull(overview, configuration, images, image, **kwargs): """Pull an image""" if not image.image_index: raise BadOption( "The chosen image does not have a image_index configuration", wanted=image.name) Syncer().pull(image, ignore_missing=image.harpoon.ignore_missing)
def pull_all(collector, **kwargs): """Pull all the images""" images = collector.configuration["images"] for layer in Builder().layered(images, only_pushable=True): for image_name, image in layer: log.info("Pulling %s", image_name) Syncer().pull(image, ignore_missing=image.harpoon.ignore_missing)
def tag(collector, image, artifact, **kwargs): """Tag an image!""" if artifact in (None, "", NotSpecified): raise BadOption("Please specify a tag using the artifact option") if image.image_index in (None, "", NotSpecified): raise BadOption("Please specify an image with an image_index option") tag = image.image_name if image.tag is NotSpecified: tag = "{0}:latest".format(tag) images = image.harpoon.docker_context.images() current_tags = chain.from_iterable(image_conf["RepoTags"] for image_conf in images) if tag not in current_tags: raise BadOption( "Please build or pull the image down to your local cache before tagging it" ) for image_conf in images: if tag in image_conf["RepoTags"]: image_id = image_conf["Id"] break log.info("Tagging {0} ({1}) as {2}".format(image_id, image.image_name, artifact)) image.harpoon.docker_context.tag(image_id, repository=image.image_name, tag=artifact, force=True) image.tag = artifact Syncer().push(image)
def push(overview, configuration, images, image): """Push an image""" if not image.image_index: raise BadOption( "The chosen image does not have a image_index configuration", wanted=image.name) Builder().make_image(image, images) Syncer().push(image)
def push(collector, image, **kwargs): """Push an image""" if not image.image_index: raise BadOption( "The chosen image does not have a image_index configuration", wanted=image.name) Builder().make_image(image, collector.configuration["images"], pushing=True) Syncer().push(image)
def pull(collector, image, **kwargs): """Pull an image""" if not image.image_index: raise BadOption( "The chosen image does not have a image_index configuration", wanted=image.name) tag = kwargs["artifact"] if tag is NotSpecified: collector.configuration["harpoon"].tag if tag is not NotSpecified: image.tag = tag log.info("Pulling tag: %s", tag) Syncer().pull(image, ignore_missing=image.harpoon.ignore_missing)
def push(collector, image, **kwargs): """Push an image""" if not image.image_index: raise BadOption( "The chosen image does not have a image_index configuration", wanted=image.name) tag = kwargs["artifact"] if tag is NotSpecified: tag = collector.configuration["harpoon"].tag if tag is not NotSpecified: image.tag = tag Builder().make_image(image, collector.configuration["images"], pushing=True) Syncer().push(image)
def make_all(overview, configuration, images, **kwargs): """Creates all the images in layered order""" push = configuration["harpoon"].do_push only_pushable = configuration["harpoon"].only_pushable if push: only_pushable = True for layer in Builder().layered(images, only_pushable=only_pushable): for _, image in layer: Builder().make_image(image, images, ignore_deps=True, ignore_parent=True) print("Created image {0}".format(image.image_name)) if push and image.image_index: Syncer().push(image)
def make_all(collector, **kwargs): """Creates all the images in layered order""" configuration = collector.configuration push = configuration["harpoon"].do_push only_pushable = configuration["harpoon"].only_pushable if push: only_pushable = True tag = kwargs.get("artifact", NotSpecified) if tag is NotSpecified: tag = configuration["harpoon"].tag images = configuration["images"] for layer in Builder().layered(images, only_pushable=only_pushable): for _, image in layer: if tag is not NotSpecified: image.tag = tag Builder().make_image(image, images, ignore_deps=True, ignore_parent=True) print("Created image {0}".format(image.image_name)) if push and image.image_index: Syncer().push(image)