def pull_images(self, registry, username, password, only_internal=True): """ This pulls all images that are mentioned in artifact. Args: registry (str): url of exposed OpenShift Docker registry username (str): username for for OpenShift Docker registry password (str): password for OpenShift Docker registry only_internal (bool): if True only images that are in internal OpenShift Docker registry, otherwise pulls all images (default is True) """ logger.debug("Pulling images (only_internal: {}, registry:{}," " login:{}:{})".format(only_internal, registry, username, password)) ec, stdout, stderr = utils.run_cmd([ 'docker', 'login', '-u', username, '-p', password, '-e', "{}@{}".format(username, registry), registry ]) for image_info in self.images: if image_info["internal"]: image_info["image"] = utils.replace_registry_host( image_info["image"], registry) else: if only_internal: # we are exporting only internal images, skip this continue image = image_info["image"] logger.info("Pulling image {}".format(image)) ec, stdout, stderr = utils.run_cmd(['docker', 'pull', image])
def push_images(self, registry, username, password, only_internal=True): """ This pushes all images that are mentioned in artifact. Args: registry (str): url of registry username (str): username for docker registry. If None (don't autheticate to registry) password (str): password for docker registry only_internal (bool): if True only images that are in internal OpenShift Docker registry, otherwise pulls all images (default is True) """ logger.debug("pushing images to registry only_internal: {}, " "registry:{}, login:{}:{}".format(only_internal, registry, username, password)) if username and password: ec, stdout, stderr = utils.run_cmd(['docker', 'login', '-u', username, '-p', password, '-e', "{}@{}".format(username, registry), registry]) for image_info in self.images: if only_internal and not image_info["internal"]: # skip this image continue image = image_info["image"] # new name of image (only replace registry part) name_new_registry = utils.replace_registry_host(image, registry) (new_name, new_name_tag, new_name_digest) = utils.parse_image_name( name_new_registry) if new_name_digest: # if this is image with define digest, use digest as tag # docker cannot push image without tag, and if images # is pulled with digest it doesn't have tag specified # if this is going to be used as tag, it cannot contain ':' tag = new_name_digest.replace(":", "") else: tag = new_name_tag new_full_name = "{}:{}".format(new_name, tag) image_info["image"] = new_full_name logger.info("Tagging image {} as {}".format(image, new_full_name)) ec, stdout, stderr = utils.run_cmd(['docker', 'tag', '-f', image, new_full_name]) logger.info("Pushing image {}".format(new_full_name)) ec, stdout, stderr = utils.run_cmd(['docker', 'push', new_full_name])
def push_images(self, registry, username, password, only_internal=True): """ This pushes all images that are mentioned in artifact. Args: registry (str): url of registry username (str): username for docker registry. If None (don't autheticate to registry) password (str): password for docker registry only_internal (bool): if True only images that are in internal OpenShift Docker registry, otherwise pulls all images (default is True) """ logger.debug("pushing images to registry only_internal: {}, " "registry:{}, login:{}:{}".format(only_internal, registry, username, password)) if username and password: ec, stdout, stderr = utils.run_cmd([ 'docker', 'login', '-u', username, '-p', password, '-e', "{}@{}".format(username, registry), registry ]) for image_info in self.images: if only_internal and not image_info["internal"]: # skip this image continue image = image_info["image"] # new name of image (only replace registry part) name_new_registry = utils.replace_registry_host(image, registry) (new_name, new_name_tag, new_name_digest) = utils.parse_image_name(name_new_registry) if new_name_digest: # if this is image with define digest, use digest as tag # docker cannot push image without tag, and if images # is pulled with digest it doesn't have tag specified # if this is going to be used as tag, it cannot contain ':' tag = new_name_digest.replace(":", "") else: tag = new_name_tag new_full_name = "{}:{}".format(new_name, tag) image_info["image"] = new_full_name logger.info("Tagging image {} as {}".format(image, new_full_name)) ec, stdout, stderr = utils.run_cmd( ['docker', 'tag', '-f', image, new_full_name]) logger.info("Pushing image {}".format(new_full_name)) ec, stdout, stderr = utils.run_cmd( ['docker', 'push', new_full_name])
def pull_images(self, registry, username, password, only_internal=True): """ This pulls all images that are mentioned in artifact. Args: registry (str): url of exposed OpenShift Docker registry username (str): username for for OpenShift Docker registry password (str): password for OpenShift Docker registry only_internal (bool): if True only images that are in internal OpenShift Docker registry, otherwise pulls all images (default is True) """ logger.debug("Pulling images (only_internal: {}, registry:{}," " login:{}:{})".format(only_internal, registry, username, password)) ec, stdout, stderr = utils.run_cmd(['docker', 'login', '-u', username, '-p', password, '-e', "{}@{}".format(username, registry), registry]) for image_info in self.images: if image_info["internal"]: image_info["image"] = utils.replace_registry_host( image_info["image"], registry) else: if only_internal: # we are exporting only internal images, skip this continue image = image_info["image"] logger.info("Pulling image {}".format(image)) ec, stdout, stderr = utils.run_cmd(['docker', 'pull', image])
def _call_oc(self, args): """ Runs a oc command with its arguments and returns the results. Args: args (list): arguments for oc command Returns: ec: The exit code from the command stdout: stdout from the command stderr: stderr from the command """ cmd = [self.oc] if self.oc_config: cmd.extend(["--config", self.oc_config]) if self.namespace: cmd.extend(["--namespace", self.namespace]) cmd.extend(args) ec, stdout, stderr = utils.run_cmd(cmd) return (ec, stdout, stderr)