예제 #1
0
        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);
        }
        public void TestToJson()
        {
            // Loads the expected JSON string.
            SystemPath jsonFile     = Paths.Get(TestResources.GetResource("core/json/loadmanifest.json").ToURI());
            string     expectedJson = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile));

            DockerLoadManifestEntryTemplate template = new DockerLoadManifestEntryTemplate();

            template.SetRepoTags(
                ImageReference.Of("testregistry", "testrepo", "testtag").ToStringWithTag());
            template.AddLayerFile("layer1.tar.gz");
            template.AddLayerFile("layer2.tar.gz");
            template.AddLayerFile("layer3.tar.gz");

            List <DockerLoadManifestEntryTemplate> loadManifest = new List <DockerLoadManifestEntryTemplate> {
                template
            };

            Assert.AreEqual(expectedJson, JsonTemplateMapper.ToUtf8String(loadManifest));
        }