def package_image(argv): args = parse_args(argv) with open(args.subvolume_json) as infile: Format.make(args.format).package_full( SubvolumeOnDisk.from_json_file(infile, args.subvolumes_dir), output_path=args.output_path, )
def package_full(self, svod: SubvolumeOnDisk, output_path: str): # Future: rpm.common.create_ro, but it's kind of a big dep. # Luckily `image_package` will promptly mark this read-only. assert not os.path.exists(output_path) with open(output_path, 'wb') as outfile, Subvol( svod.subvolume_path(), already_exists=True, ).mark_readonly_and_write_sendstream_to_file(outfile): pass
def find_built_subvol(layer_output, path_in_repo=None): with open(os.path.join(layer_output, 'layer.json')) as infile: return Subvol( SubvolumeOnDisk.from_json_file( infile, subvolumes_dir(path_in_repo), ).subvolume_path(), already_exists=True, )
def package_full(self, svod: SubvolumeOnDisk, output_path: str): assert not os.path.exists(output_path) with open(output_path, 'wb') as outfile, subprocess.Popen( ['zstd', '--stdout'], stdin=subprocess.PIPE, stdout=outfile ) as zstd, Subvol( svod.subvolume_path(), already_exists=True, ).mark_readonly_and_write_sendstream_to_file(zstd.stdin): pass check_popen_returncode(zstd)
def package_full(self, svod: SubvolumeOnDisk, output_path: str): Subvol( svod.subvolume_path(), already_exists=True, ).mark_readonly_and_send_to_new_loopback(output_path) # Paranoia: images are read-only after being built os.chmod( output_path, stat.S_IMODE(os.stat(output_path).st_mode) & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH), )
def find_built_subvol( layer_output, *, path_in_repo=None, subvolumes_dir=None, ): # It's OK for both to be None (uses the current file to find repo), but # it's not OK to set both. assert (path_in_repo is None) or (subvolumes_dir is None) with open(Path(layer_output) / 'layer.json') as infile: return Subvol( SubvolumeOnDisk.from_json_file( infile, subvolumes_dir if subvolumes_dir else _get_subvolumes_dir(path_in_repo), ).subvolume_path(), already_exists=True, )
def get_subvolume_path(layer_json, subvolumes_dir): with open(layer_json) as infile: return SubvolumeOnDisk.from_json_file(infile, subvolumes_dir).subvolume_path()