def pull_image(self, image, remote_image_obj, **kwargs): assert(isinstance(remote_image_obj, Image)) debug = kwargs.get('debug', False) if image.startswith("dockertar:"): path = image.replace("dockertar:", "", 1) with open(path, 'rb') as f: self.d.load_image(data=f) return 0 fq_name = remote_image_obj.fq_name local_image = self.has_image(image) if local_image is not None: if self.already_has_image(local_image, remote_image_obj): raise util.ImageAlreadyExists(image) registry, _, _, tag, _ = util.Decompose(fq_name).all image = "docker-daemon:{}".format(fq_name) if not image.endswith(tag): image += ":{}".format(tag) if '@sha256:' in image: image = image.replace("@sha256:", ":") insecure = True if util.is_insecure_registry(self.d.info()['RegistryConfig'], util.strip_port(registry)) else False trust = Trust() trust.discover_sigstore(fq_name) util.write_out("Pulling {} ...".format(fq_name)) util.skopeo_copy("docker://{}".format(fq_name), image, debug=debug, insecure=insecure, policy_filename=trust.policy_filename) return 0
def pull_image(self, image, remote_image_obj, **kwargs): """ Pulls an image to the backend :param image: :param pull_args: :return: """ debug = kwargs.get('debug', False) fq_name = remote_image_obj.fq_name registry, _, _, tag, _ = util.Decompose(fq_name).all if not image.endswith(tag): image += ":{}".format(tag) if '@sha256:' in image: image = image.replace("@sha256:", ":") insecure = False registries_config = util.load_registries_from_yaml() if "insecure_registries" in registries_config: if registry in registries_config['insecure_registries']: insecure = True source = "docker://{}".format(image) dest = "containers-storage:{}".format(image) trust = Trust() trust.discover_sigstore(fq_name) util.write_out("Pulling {} ...".format(fq_name)) util.skopeo_copy(source, dest, debug=debug, insecure=insecure, policy_filename=trust.policy_filename) return 0
class TestAtomicUtil(unittest.TestCase): IMAGE = 'docker.io/library/busybox:latest' I_REGISTRY, I_REPO, I_IMAGE, I_TAG, _ = util.Decompose(IMAGE).all def test_find_image_on_registry(self): fq = 'docker.io/library/busybox:latest' for img in [ 'docker.io/library/busybox:latest', 'docker.io/library/busybox', 'docker.io/busybox', 'busybox' ]: registry, repo, image, tag, _ = util.Decompose(img).all ri = discovery.RegistryInspect(registry=registry, repo=repo, image=image, tag=tag) self.assertEqual(ri.find_image_on_registry(), fq) def test_inspect(self): ri = discovery.RegistryInspect(registry=self.I_REGISTRY, repo=self.I_REPO, image=self.I_IMAGE, tag=self.I_TAG) inspect_info = ri.inspect() self.assertEqual( inspect_info['Name'], "{}/{}/{}".format(self.I_REGISTRY, self.I_REPO, self.I_IMAGE)) self.assertEqual(inspect_info['Tag'], self.I_TAG)
def tag_image(self, _src, _dest): registry, repo, image, tag, _ = util.Decompose(_dest).all result = registry if repo: result += "/{}".format(repo) result += "/{}".format(image) if result.startswith("/"): result = result[1:] return self.d.tag(_src, result, tag=tag)
def _inspect_image_by_hash(self, image): input_digest = util.Decompose(image).digest all_images = self.get_images(get_all=True) for _image in all_images: if not _image.repotags: continue for repo_digest in _image.repotags: if no_shaw(input_digest) in repo_digest: return self.d.inspect_image(_image.id) return None
def update(self, name, force=False): img_obj = self.inspect_image(name) if force: self.delete_containers_by_image(img_obj) registry = util.Decompose(img_obj.fq_name).registry return util.skopeo_copy( "docker://{}".format(name), "docker-daemon:{}".format(img_obj.fq_name), util.is_insecure_registry(self.d.info()['RegistryConfig'], util.strip_port(registry)))
def test_find_image_on_registry(self): fq = 'docker.io/library/busybox:latest' for img in [ 'docker.io/library/busybox:latest', 'docker.io/library/busybox', 'docker.io/busybox', 'busybox' ]: registry, repo, image, tag, _ = util.Decompose(img).all ri = discovery.RegistryInspect(registry=registry, repo=repo, image=image, tag=tag) self.assertEqual(ri.find_image_on_registry(), fq)
def test_decompose(self): images = [('docker.io/library/busybox', ('docker.io', 'library','busybox', 'latest', '')), ('docker.io/library/foobar/busybox', ('docker.io', 'library/foobar', 'busybox', 'latest', '')), ('docker.io/library/foobar/busybox:2.1', ('docker.io', 'library/foobar', 'busybox', '2.1', '')), ('docker.io/busybox:2.1', ('docker.io', 'library', 'busybox', '2.1', '')), ('docker.io/busybox', ('docker.io', 'library', 'busybox', 'latest', '')), ('busybox', ('', '', 'busybox', 'latest', '')), ('busybox:2.1', ('', '', 'busybox', '2.1', '')), ('library/busybox', ('', 'library', 'busybox', 'latest', '')), ('library/busybox:2.1', ('', 'library', 'busybox', '2.1', '')), ('registry.access.redhat.com/rhel7:latest', ('registry.access.redhat.com', '', 'rhel7', 'latest', '')), ('registry.access.redhat.com/rhel7', ('registry.access.redhat.com', '', 'rhel7', 'latest', '')), ('fedora@sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e', ('', '', 'fedora', '', 'sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e')), ('docker.io/library/fedora@sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e', ('docker.io', 'library', 'fedora', '', 'sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e')), ('docker.io/fedora@sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e', ('docker.io', 'library', 'fedora', '', 'sha256:64a02df6aac27d1200c2572fe4b9949f1970d05f74d367ce4af994ba5dc3669e')) ] for image in images: self.assertEqual(util.Decompose(image[0]).all, image[1])