public async Task WriteToAsync(Stream @out) { TarStreamBuilder tarStreamBuilder = new TarStreamBuilder(); DockerLoadManifestEntryTemplate manifestTemplate = new DockerLoadManifestEntryTemplate(); // Adds all the layers to the tarball and manifest. foreach (ILayer layer in image.GetLayers()) { string layerName = layer.GetBlobDescriptor().GetDigest().GetHash() + LAYER_FILE_EXTENSION; tarStreamBuilder.AddBlobEntry( layer.GetBlob(), layer.GetBlobDescriptor().GetSize(), layerName); manifestTemplate.AddLayerFile(layerName); } // Adds the container configuration to the tarball. ContainerConfigurationTemplate containerConfiguration = new ImageToJsonTranslator(image).GetContainerConfiguration(); tarStreamBuilder.AddByteEntry( JsonTemplateMapper.ToByteArray(containerConfiguration), CONTAINER_CONFIGURATION_JSON_FILE_NAME); // Adds the manifest to tarball. manifestTemplate.SetRepoTags(imageReference.ToStringWithTag()); tarStreamBuilder.AddByteEntry( JsonTemplateMapper.ToByteArray(new List <DockerLoadManifestEntryTemplate> { manifestTemplate }), MANIFEST_JSON_FILE_NAME); await tarStreamBuilder.WriteAsTarArchiveToAsync(@out).ConfigureAwait(false); }
/** * Gets the directory corresponding to the given image reference. * * @param imageReference the image reference * @return a path in the form of {@code * (fib-cache)/images/registry[!port]/repository!(tag|digest-type!digest)} */ public SystemPath GetImageDirectory(IImageReference imageReference) { imageReference = imageReference ?? throw new ArgumentNullException(nameof(imageReference)); // Replace ':' and '@' with '!' to avoid directory-naming restrictions string replacedReference = imageReference.ToStringWithTag().Replace(':', '!').Replace('@', '!'); // Split image reference on '/' to build directory structure IEnumerable <string> directories = Splitter.On('/').Split(replacedReference); SystemPath destination = GetImagesDirectory(); foreach (string dir in directories) { destination = destination.Resolve(dir); } return(destination); }