Table of Contents

Push an artifact to a remote repository

// This example demonstrates how to push an artifact to a remote repository.

// Create a HttpClient instance to be used for making HTTP requests.
var httpClient = new HttpClient();
var mockCredentialProvider = new Mock<ICredentialProvider>();
var repo = new Repository(new RepositoryOptions()
{
    Reference = Reference.Parse("localhost:5000/test"),
    Client = new Client(httpClient, mockCredentialProvider.Object),
});

var layersBytes = new List<byte[]>
{
    new byte[] { 0x04, 0x05, 0x06 }, // Example layer data
};
var layers = new List<Descriptor>
{
    Descriptor.Create(
        layersBytes[0],
        MediaType.ImageLayer
    )
};

// Push layers to the repository
for (int i = 0; i < layers.Count; i++)
{
    await repo.PushAsync(layers[i], new MemoryStream(layersBytes[i]));
}

// Create a PackManifestOptions instance to specify the manifest configuration.
var options = new PackManifestOptions
{
    Layers = layers
};
var artifactType = "doc/example";
// Pack the artifact with the specified type and push it to the repository.
var pushedDescriptor = await Packer.PackManifestAsync(
    repo,
    Packer.ManifestVersion.Version1_1,
    artifactType,
    options);

var tag = "tag";
// Tag the pushed artifact.
await repo.TagAsync(pushedDescriptor, tag);