Beispiel #1
0
    def validate_layer(self, layer):
        """
        Validates a docker image by mounting the image on a rootfs and validate that
        rootfs against the manifests that were created. Note that it won't be validated
        layer by layer.
        :param:
        :return: None
        """
        inspect = self._inspect_image(image=layer)
        if inspect is None:
            return None

        iid = inspect['RepoTags'][0]
        manifestname = os.path.join(util.ATOMIC_VAR_LIB, "gomtree-manifests/%s.mtree" % iid)
        if not os.path.exists(manifestname):
            return
        tmpdir = tempfile.mkdtemp()
        try:
            from Atomic.mount import Mount
            m = Mount()
            m.args = []
            m.image = iid
            m.storage = "docker"
            m.mountpoint = tmpdir
            m.mount()
            try:
                r = util.validate_manifest(manifestname, img_rootfs=tmpdir, keywords="type,uid,gid,mode,size,sha256digest")
                if r.return_code != 0:
                    util.write_err(r.stdout)
            finally:
                m.unmount()
        finally:
            shutil.rmtree(tmpdir)
Beispiel #2
0
    def update_all_images(self, be, debug):
        images = be.get_images()
        images_by_name = {}
        for i in images:
            if i.repotags is None:
                continue

            img_name = i.repotags[0]
            d = Decompose(img_name)
            if d.registry == "":
                write_err(
                    "Image {} not fully qualified: skipping".format(img_name))
                continue

            images_by_name[img_name] = i
            could_not_pull = {}
            pulled = {}

            write_out("Checking image {}...".format(img_name))
            try:
                be.update(img_name, debug=debug, force=False, image_object=i)
                pulled[img_name] = True
            except:  # pylint: disable=bare-except
                could_not_pull[img_name] = True

        def get_status(img_name, pre_id, post_id):
            COLOR_RED = 31
            COLOR_GREEN = 32

            if img_name in could_not_pull.keys():
                return "Could not pull", COLOR_RED

            if pre_id != post_id:
                return "Updated now", COLOR_GREEN

            return "Updated", COLOR_GREEN

        def colored(line, color):
            if sys.stdout.isatty():
                return "\x1b[1;%dm%s\x1b[0m" % (color, line)
            else:
                return line

        cols = "{0:50} {1:32} {2:32} {3:15}"

        write_out("\nSUMMARY\n")
        write_out(
            cols.format("Image", "Image ID before update",
                        "Image ID after update", "Status"))
        for k, v in images_by_name.items():
            new_image = be.inspect_image(k)
            status, color = get_status(k, v.id, new_image.id)
            colored_status = colored(status[:15], color)
            write_out(
                cols.format(k[:50], v.id[:32], new_image.id[:32],
                            colored_status))