public async Task TestPushAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); IBlob testLayerBlob = Blobs.From("crepecake"); // Known digest for 'crepecake' DescriptorDigest testLayerBlobDigest = DescriptorDigest.FromHash( "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); IBlob testContainerConfigurationBlob = Blobs.From("12345"); DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.FromHash( "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5"); // Creates a valid image manifest. V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate(); expectedManifestTemplate.AddLayer(9, testLayerBlobDigest); expectedManifestTemplate.SetContainerConfiguration(5, testContainerConfigurationBlobDigest); // Pushes the BLOBs. RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "testimage") .SetAllowInsecureRegistries(true) .NewRegistryClient(); Assert.IsFalse( await registryClient.PushBlobAsync(testLayerBlobDigest, testLayerBlob, null, _ => { }).ConfigureAwait(false)); Assert.IsFalse( await registryClient.PushBlobAsync( testContainerConfigurationBlobDigest, testContainerConfigurationBlob, null, _ => { }).ConfigureAwait(false)); // Pushes the manifest. DescriptorDigest imageDigest = await registryClient.PushManifestAsync(expectedManifestTemplate, "latest").ConfigureAwait(false); // Pulls the manifest. V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); Assert.AreEqual(1, manifestTemplate.Layers.Count); Assert.AreEqual(testLayerBlobDigest, manifestTemplate.Layers[0].Digest); Assert.IsNotNull(manifestTemplate.GetContainerConfiguration()); Assert.AreEqual( testContainerConfigurationBlobDigest, manifestTemplate.GetContainerConfiguration().Digest); // Pulls the manifest by digest. V22ManifestTemplate manifestTemplateByDigest = await registryClient.PullManifestAsync <V22ManifestTemplate>(imageDigest.ToString()).ConfigureAwait(false); Assert.AreEqual( await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false), await Digests.ComputeJsonDigestAsync(manifestTemplateByDigest).ConfigureAwait(false)); }
public void TestFromJson() { // Loads the JSON string. SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); // Deserializes into a manifest JSON object. V22ManifestTemplate manifestJson = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(jsonFile); Assert.AreEqual( DescriptorDigest.FromDigest( "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), manifestJson.GetContainerConfiguration().Digest); Assert.AreEqual(1000, manifestJson.GetContainerConfiguration().Size); Assert.AreEqual( DescriptorDigest.FromHash( "4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236"), manifestJson.Layers[0].Digest); Assert.AreEqual(1000_000, manifestJson.Layers[0].Size); }
public async Task TestWriteMetadata_v22Async() { SystemPath containerConfigurationJsonFile = Paths.Get( TestResources.GetResource("core/json/containerconfig.json").ToURI()); ContainerConfigurationTemplate containerConfigurationTemplate = JsonTemplateMapper.ReadJsonFromFile <ContainerConfigurationTemplate>( containerConfigurationJsonFile); SystemPath manifestJsonFile = Paths.Get(TestResources.GetResource("core/json/v22manifest.json").ToURI()); IBuildableManifestTemplate manifestTemplate = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(manifestJsonFile); ImageReference imageReference = ImageReference.Parse("image.reference/project/thing:tag"); await new CacheStorageWriter(cacheStorageFiles) .WriteMetadataAsync(imageReference, manifestTemplate, containerConfigurationTemplate).ConfigureAwait(false); SystemPath savedManifestPath = cacheRoot.Resolve("images/image.reference/project/thing!tag/manifest.json"); SystemPath savedConfigPath = cacheRoot.Resolve("images/image.reference/project/thing!tag/config.json"); Assert.IsTrue(Files.Exists(savedManifestPath)); Assert.IsTrue(Files.Exists(savedConfigPath)); V22ManifestTemplate savedManifest = JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(savedManifestPath); Assert.AreEqual( "8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad", savedManifest.GetContainerConfiguration().Digest.GetHash()); ContainerConfigurationTemplate savedContainerConfig = JsonTemplateMapper.ReadJsonFromFile <ContainerConfigurationTemplate>(savedConfigPath); Assert.AreEqual("wasm", savedContainerConfig.Architecture); }