public async Task PushArtifactAsync(Configuration.RootConfiguration configuration, OciArtifactModuleReference moduleReference, StreamDescriptor config, params StreamDescriptor[] layers) { // TODO: How do we choose this? Does it ever change? var algorithmIdentifier = DescriptorFactory.AlgorithmIdentifierSha256; var blobClient = this.CreateBlobClient(configuration, moduleReference); config.ResetStream(); var configDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, config); config.ResetStream(); var configUploadResult = await blobClient.UploadBlobAsync(config.Stream); var layerDescriptors = new List <OciDescriptor>(layers.Length); foreach (var layer in layers) { layer.ResetStream(); var layerDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, layer); layerDescriptors.Add(layerDescriptor); layer.ResetStream(); var layerUploadResult = await blobClient.UploadBlobAsync(layer.Stream); } var manifest = new OciManifest(2, configDescriptor, layerDescriptors); using var manifestStream = new MemoryStream(); OciSerialization.Serialize(manifestStream, manifest); manifestStream.Position = 0; // BUG: the client closes the stream :( (is it still the case?) var manifestUploadResult = await blobClient.UploadManifestAsync(manifestStream, new UploadManifestOptions { Tag = moduleReference.Tag }); }
protected override void WriteModuleContent(OciArtifactModuleReference reference, OciArtifactResult result) { /* * this should be kept in sync with the IsModuleRestoreRequired() implementation */ // write main.bicep this.FileResolver.Write(this.GetModuleFileUri(reference, ModuleFileType.ModuleMain), result.ModuleStream); // write manifest // it's important to write the original stream here rather than serialize the manifest object // this way we guarantee the manifest hash will match this.FileResolver.Write(this.GetModuleFileUri(reference, ModuleFileType.Manifest), result.ManifestStream); // write metadata var metadata = new ModuleMetadata(result.ManifestDigest); using var metadataStream = new MemoryStream(); OciSerialization.Serialize(metadataStream, metadata); metadataStream.Position = 0; this.FileResolver.Write(this.GetModuleFileUri(reference, ModuleFileType.Metadata), metadataStream); }