def pull(cli): ch.dependencies_check() # Where does it go? dlcache = cli.storage + "/dlcache" if (cli.image_dir is not None): unpack_dir = cli.image_dir image_subdir = "" else: unpack_dir = cli.storage + "/img" image_subdir = None # infer from image ref # Set things up. ref = ch.Image_Ref(cli.image_ref) if (cli.parse_only): print(ref.as_verbose_str) sys.exit(0) image = ch.Image(ref, dlcache, unpack_dir, image_subdir) ch.INFO("pulling image: %s" % image.ref) if (cli.image_dir is not None): ch.INFO("destination: %s" % image.unpack_path) else: ch.DEBUG("destination: %s" % image.unpack_path) ch.DEBUG("use cache: %s" % (not cli.no_cache)) ch.DEBUG("download cache: %s" % image.download_cache) ch.DEBUG("manifest: %s" % image.manifest_path) # Pull! image.pull_to_unpacked(use_cache=(not cli.no_cache), last_layer=cli.last_layer) # Done. ch.INFO("done")
def execute_(self): # Complain about unsupported stuff. if (self.options.pop("platform", False)): self.unsupported_yet_fatal("--platform", 778) # Any remaining options are invalid. self.options_assert_empty() # Update image globals. global image_i image_i += 1 global image_alias image_alias = self.alias if (image_i == image_ct - 1): # Last image; use tag unchanged. tag = cli.tag elif (image_i > image_ct - 1): # Too many images! ch.FATAL("expected %d stages but found at least %d" % (image_ct, image_i + 1)) else: # Not last image; append stage index to tag. tag = "%s/_stage%d" % (cli.tag, image_i) image = ch.Image(ch.Image_Ref(tag)) images[image_i] = image if (self.alias is not None): images[self.alias] = image ch.VERBOSE("image path: %s" % image.unpack_path) # Other error checking. if (str(image.ref) == str(self.base_ref)): ch.FATAL("output image ref same as FROM: %s" % self.base_ref) # Initialize image. self.base_image = ch.Image(self.base_ref) if (os.path.isdir(self.base_image.unpack_path)): ch.VERBOSE("base image found: %s" % self.base_image.unpack_path) else: ch.VERBOSE("base image not found, pulling") # a young hen, especially one less than one year old. pullet = pull.Image_Puller(self.base_image, not cli.no_cache) pullet.pull_to_unpacked() pullet.done() image.copy_unpacked(self.base_image) image.metadata_load() env.reset() # Find fakeroot configuration, if any. global fakeroot_config fakeroot_config = fakeroot.detect(image.unpack_path, cli.force, cli.no_force_detect)
def execute_(self): # Complain about unsupported stuff. if (self.options.pop("platform", False)): self.unsupported_yet_fatal("--platform", 778) # Any remaining options are invalid. self.options_assert_empty() # Update image globals. global image_i image_i += 1 global image_alias image_alias = self.alias if (image_i == image_ct - 1): # Last image; use tag unchanged. tag = cli.tag elif (image_i > image_ct - 1): # Too many images! ch.FATAL("expected %d stages but found at least %d" % (image_ct, image_i + 1)) else: # Not last image; append stage index to tag. tag = "%s/_stage%d" % (cli.tag, image_i) image = ch.Image(ch.Image_Ref(tag), cli.storage + "/dlcache", cli.storage + "/img") images[image_i] = image if (self.alias is not None): images[self.alias] = image ch.DEBUG("image path: %s" % image.unpack_path) # Other error checking. if (str(image.ref) == str(self.base_ref)): ch.FATAL("output image ref same as FROM: %s" % self.base_ref) # Initialize image. self.base_image = ch.Image(self.base_ref, image.download_cache, image.unpack_dir) if (not os.path.isdir(self.base_image.unpack_path)): ch.DEBUG("image not found, pulling: %s" % self.base_image.unpack_path) self.base_image.pull_to_unpacked(fixup=True) image.copy_unpacked(self.base_image) env.reset() # Inject fakeroot preparatory stuff if needed. if (not cli.no_fakeroot): fakeroot.inject_first(image.unpack_path, env.env_build)
def import_(cli): if (not os.path.exists(cli.path)): ch.FATAL("can't copy: not found: %s" % cli.path) dst = ch.Image(ch.Image_Ref(cli.image_ref)) ch.INFO("importing: %s" % cli.path) ch.INFO("destination: %s" % dst) if (os.path.isdir(cli.path)): dst.copy_unpacked(cli.path) else: # tarball, hopefully dst.unpack([cli.path]) # initialize metadata if needed dst.metadata_load() dst.metadata_save() ch.done_notify()
def list_(cli): ch.dependencies_check() imgdir = ch.storage.unpack_base if (cli.image_ref is None): # list all images if (not os.path.isdir(ch.storage.root)): ch.INFO("does not exist: %s" % ch.storage.root) return if (not ch.storage.valid_p()): ch.INFO("not a storage directory: %s" % ch.storage.root) return imgs = ch.ossafe(os.listdir, "can't list directory: %s" % ch.storage.root, imgdir) for img in sorted(imgs): print(ch.Image_Ref(img)) else: # list specified image img = ch.Image(ch.Image_Ref(cli.image_ref)) print("details of image: %s" % img.ref) # present locally? if (not img.unpack_exist_p): stored = "no" else: img.metadata_load() stored = "yes (%s)" % img.metadata["arch"] print("in local storage: %s" % stored) # present remotely? print("full remote ref: %s" % img.ref.canonical) pullet = pull.Image_Puller(img, not cli.no_cache) pullet.fatman_load() if (pullet.architectures is not None): remote = "yes" arch_aware = "yes" arch_avail = " ".join(sorted(pullet.architectures.keys())) else: pullet.manifest_load(True) if (pullet.layer_hashes is not None): remote = "yes" arch_aware = "no" arch_avail = "unknown" else: remote = "no" arch_aware = "n/a" arch_avail = "n/a" pullet.done() print("available remotely: %s" % remote) print("remote arch-aware: %s" % arch_aware) print("host architecture: %s" % ch.arch_host) print("archs available: %s" % arch_avail)
def main(cli): # Set things up. ref = ch.Image_Ref(cli.image_ref) if (cli.parse_only): print(ref.as_verbose_str) sys.exit(0) image = ch.Image(ref, cli.image_dir) ch.INFO("pulling image: %s" % ref) ch.INFO("requesting arch: %s" % ch.arch) if (cli.image_dir is not None): ch.INFO("destination: %s" % image.unpack_path) else: ch.VERBOSE("destination: %s" % image.unpack_path) pullet = Image_Puller(image, not cli.no_cache) pullet.pull_to_unpacked(cli.last_layer) pullet.done() ch.done_notify()
def main(cli): ch.dependencies_check() # Set things up. ref = ch.Image_Ref(cli.image_ref) if (cli.parse_only): ch.INFO(ref.as_verbose_str) sys.exit(0) image = ch.Image(ref, cli.image_dir) ch.INFO("pulling image: %s" % ref) if (cli.image_dir is not None): ch.INFO( "destination: %s" % image.unpack_path) else: ch.VERBOSE("destination: %s" % image.unpack_path) ch.VERBOSE("use cache: %s" % (not cli.no_cache)) ch.VERBOSE("download cache: %s" % ch.storage.download_cache) pullet = Image_Puller(image) ch.VERBOSE("manifest: %s" % pullet.manifest_path) pullet.pull_to_unpacked(use_cache=(not cli.no_cache), last_layer=cli.last_layer) ch.done_notify()
def main(cli): src_ref = ch.Image_Ref(cli.source_ref) ch.INFO("pushing image: %s" % src_ref) image = ch.Image(src_ref, cli.image) # FIXME: validate it's an image using Megan's new function (PR #908) if (not os.path.isdir(image.unpack_path)): if (cli.image is not None): ch.FATAL("can't push: %s does not appear to be an image" % cli.image) else: ch.FATAL("can't push: no image %s" % src_ref) if (cli.image is not None): ch.INFO("image path: %s" % image.unpack_path) else: ch.VERBOSE("image path: %s" % image.unpack_path) if (cli.dest_ref is not None): dst_ref = ch.Image_Ref(cli.dest_ref) ch.INFO("destination: %s" % dst_ref) else: dst_ref = ch.Image_Ref(cli.source_ref) up = Image_Pusher(image, dst_ref) up.push() ch.done_notify()
def delete(cli): ch.dependencies_check() img_ref = ch.Image_Ref(cli.image_ref) img = ch.Image(img_ref) img.unpack_delete()
def delete(cli): img_ref = ch.Image_Ref(cli.image_ref) img = ch.Image(img_ref, cli.storage) img.unpack_delete()