def create_bundle(output, tag_to_config, tag_to_manifest, diffid_to_blobsum, blobsum_to_unzipped, blobsum_to_zipped, blobsum_to_legacy): """Creates a Docker image from a list of layers. Args: output: the name of the docker image file to create. layers: the layers (tar files) to join to the image. tag_to_layer: a map from docker_name.Tag to the layer id it references. layer_to_tags: a map from the name of the layer tarball as it appears in our archives to the list of tags applied to it. """ with tarfile.open(output, 'w') as tar: def add_file(filename, contents): info = tarfile.TarInfo(filename) info.size = len(contents) tar.addfile(tarinfo=info, fileobj=cStringIO.StringIO(contents)) tag_to_image = {} for (tag, config) in six.iteritems(tag_to_config): manifest = None if tag in tag_to_manifest: manifest = tag_to_manifest[tag] tag_to_image[tag] = FromParts( config, manifest, diffid_to_blobsum, blobsum_to_unzipped, blobsum_to_zipped, blobsum_to_legacy) v2_2_save.multi_image_tarball(tag_to_image, tar)
def create_bundle(output, tag_to_config, diffid_to_blobsum, blobsum_to_unzipped, blobsum_to_zipped, blobsum_to_legacy): """Creates a Docker image from a list of layers. Args: output: the name of the docker image file to create. layers: the layers (tar files) to join to the image. tag_to_layer: a map from docker_name.Tag to the layer id it references. layer_to_tags: a map from the name of the layer tarball as it appears in our archives to the list of tags applied to it. """ with tarfile.open(output, 'w') as tar: def add_file(filename, contents): info = tarfile.TarInfo(filename) info.size = len(contents) tar.addfile(tarinfo=info, fileobj=cStringIO.StringIO(contents)) tag_to_image = {} for (tag, config) in six.iteritems(tag_to_config): tag_to_image[tag] = FromParts( config, diffid_to_blobsum, blobsum_to_unzipped, blobsum_to_zipped, blobsum_to_legacy) v2_2_save.multi_image_tarball(tag_to_image, tar)
def create_image(output, layers, tag_to_layer=None, layer_to_tags=None): """Creates a Docker image from a list of layers. Args: output: the name of the docker image file to create. layers: the layers (tar files) to join to the image. tag_to_layer: a map from docker_name.Tag to the layer id it references. layer_to_tags: a map from the name of the layer tarball as it appears in our archives to the list of tags applied to it. """ layer_to_tarball = {} for layer in layers: with tarfile.open(layer, 'r') as tarball: for path in tarball.getnames(): if os.path.basename(path) != 'layer.tar': continue layer_id = os.path.basename(os.path.dirname(path)) layer_to_tarball[layer_id] = layer with tarfile.open(output, 'w') as tar: def add_file(filename, contents): info = tarfile.TarInfo(filename) info.size = len(contents) tar.addfile(tarinfo=info, fileobj=cStringIO.StringIO(contents)) tag_to_image = {} tag_to_v1_image = {} for (tag, top) in tag_to_layer.iteritems(): v1_img = v1_image.FromShardedTarball( lambda layer_id: layer_to_tarball[layer_id], top) tag_to_v1_image[tag] = v1_img v2_2_img = ImageConfig( v2_compat.config_file([ json.loads(v1_img.json(layer_id)) for layer_id in reversed(v1_img.ancestry(v1_img.top())) ], [ 'sha256:' + hashlib.sha256( v1_img.uncompressed_layer(layer_id)).hexdigest() for layer_id in reversed(v1_img.ancestry(v1_img.top())) ])) tag_to_image[tag] = v2_2_img v2_2_save.multi_image_tarball(tag_to_image, tar, tag_to_v1_image)
def create_image(output, layers, tag_to_layer=None, layer_to_tags=None): """Creates a Docker image from a list of layers. Args: output: the name of the docker image file to create. layers: the layers (tar files) to join to the image. tag_to_layer: a map from docker_name.Tag to the layer id it references. layer_to_tags: a map from the name of the layer tarball as it appears in our archives to the list of tags applied to it. """ layer_to_tarball = {} for layer in layers: with tarfile.open(layer, 'r') as tarball: for path in tarball.getnames(): if os.path.basename(path) != 'layer.tar': continue layer_id = os.path.basename(os.path.dirname(path)) layer_to_tarball[layer_id] = layer with tarfile.open(output, 'w') as tar: def add_file(filename, contents): info = tarfile.TarInfo(filename) info.size = len(contents) tar.addfile(tarinfo=info, fileobj=cStringIO.StringIO(contents)) tag_to_image = {} tag_to_v1_image = {} for (tag, top) in tag_to_layer.iteritems(): v1_img = v1_image.FromShardedTarball( lambda layer_id: layer_to_tarball[layer_id], top) tag_to_v1_image[tag] = v1_img v2_2_img = ImageConfig(v2_compat.config_file([ json.loads(v1_img.json(layer_id)) for layer_id in reversed(v1_img.ancestry(v1_img.top())) ], [ 'sha256:' + hashlib.sha256( v1_img.uncompressed_layer(layer_id) ).hexdigest() for layer_id in reversed(v1_img.ancestry(v1_img.top())) ])) tag_to_image[tag] = v2_2_img v2_2_save.multi_image_tarball(tag_to_image, tar, tag_to_v1_image)