Exemple #1
0
def expand_from_images(dfobj):
    '''Replace all parent_image values with their full image@digest_type:digest
    value. Update the structure dictionary with the same information.
    dfobj: the Dockerfile object created using get_dockerfile_obj'''
    # update parent_images
    images = parse_from_image(dfobj)
    for i, img in enumerate(images):
        # don't re-pull digest if already available
        if not img['digest_type'] and not img['digest']:
            if not img['tag']:
                img['tag'] = 'latest'
            image = container.get_image(img['name'] + tag_separator +
                                        img['tag'])
            if image is not None:
                dfobj.parent_images[i] = container.get_image_digest(image)
            else:
                logger.error("Error pinning digest to '%s'. Image not found.",
                             dfobj.parent_images[i])
    # update structure
    counter = 0
    for i, command_dict in enumerate(dfobj.structure):
        if command_dict['instruction'] == 'FROM':
            # Pull digest in order of parent_images
            dfobj.structure[i]['content'] = command_dict['instruction'] + \
                ' ' + dfobj.parent_images[counter] + '\n'
            dfobj.structure[i]['value'] = dfobj.parent_images[counter]
            counter = counter + 1
Exemple #2
0
    def __init__(self, repotag=None):
        '''Initialize using repotag'''
        super().__init__(repotag)
        self.__repotags = []
        self.__history = None
        if self.repotag is None:
            raise NameError("Image object initialized with no repotag")

        # parse the repotag
        repo_dict = general.parse_image_string(self._repotag)
        self._name = repo_dict.get('name')
        self._tag = repo_dict.get('tag')
        self.set_checksum(
            repo_dict.get('digest_type'), repo_dict.get('digest'))
        if not self.checksum and general.check_tar(repotag) is False:
            # if there is no checksum, get the digest type
            docker_image = container.check_image(self._repotag)
            # this object could be representing an image built from
            # a Dockerfile, so it may not have a digest
            # so check for that condition
            if docker_image.attrs['RepoDigests']:
                image_name_digest = container.get_image_digest(docker_image)
                repo_dict = general.parse_image_string(image_name_digest)
                self.set_checksum(
                    repo_dict.get('digest_type'), repo_dict.get('digest'))