Skip to content

Commit 6b147e1

Browse files
Surayya Huseyn ZadaSurayya Huseyn Zada
authored andcommitted
add support for multi tagoci tarball
1 parent 88c613a commit 6b147e1

File tree

16 files changed

+37
-119
lines changed

16 files changed

+37
-119
lines changed

src/Containers/Microsoft.NET.Build.Containers/LocalDaemons/DockerCli.cs

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ await writeStreamFunc(image, sourceReference, destinationReference, loadProcess.
122122
}
123123

124124
public async Task LoadAsync(BuiltImage image, SourceImageReference sourceReference, DestinationImageReference destinationReference, CancellationToken cancellationToken)
125+
// For loading to the local registry, we use the Docker format. Two reasons: one - compatibility with previous behavior before oci formatted publishing was available, two - Podman cannot load multi tag oci image tarball.
125126
=> await LoadAsync(image, sourceReference, destinationReference, WriteDockerImageToStreamAsync, cancellationToken);
126127

127128
public async Task LoadAsync(BuiltImage[] images, SourceImageReference sourceReference, DestinationImageReference destinationReference, CancellationToken cancellationToken)
@@ -406,11 +407,6 @@ public static async Task WriteMultiArchOciImageToStreamAsync(
406407
{
407408
cancellationToken.ThrowIfCancellationRequested();
408409

409-
if (destinationReference.Tags.Length > 1)
410-
{
411-
throw new ArgumentException(Resource.FormatString(nameof(Strings.OciImageMultipleTagsNotSupported)));
412-
}
413-
414410
using TarWriter writer = new(imageStream, TarEntryFormat.Pax, leaveOpen: true);
415411

416412
foreach (var image in images)
@@ -435,11 +431,6 @@ private static async Task WriteOciImageToStreamAsync(
435431
{
436432
cancellationToken.ThrowIfCancellationRequested();
437433

438-
if (destinationReference.Tags.Length > 1)
439-
{
440-
throw new ArgumentException(Resource.FormatString(nameof(Strings.OciImageMultipleTagsNotSupported)));
441-
}
442-
443434
using TarWriter writer = new(imageStream, TarEntryFormat.Pax, leaveOpen: true);
444435

445436
await WriteOciImageToBlobs(writer, image, sourceReference, cancellationToken)
@@ -511,8 +502,6 @@ private static async Task WriteIndexJsonForMultiArchOciImage(
511502
// 1. create manifest list for the blobs
512503
cancellationToken.ThrowIfCancellationRequested();
513504

514-
string tag = destinationReference.Tags[0];
515-
516505
var manifests = new PlatformSpecificOciManifest[images.Length];
517506
for (int i = 0; i < images.Length; i++)
518507
{
@@ -554,24 +543,28 @@ private static async Task WriteIndexJsonForMultiArchOciImage(
554543
// 2. create index json that points to manifest list in the blobs
555544
cancellationToken.ThrowIfCancellationRequested();
556545

546+
var manifestsIndexJson = new PlatformSpecificOciManifest[destinationReference.Tags.Length];
547+
for (int i = 0; i < destinationReference.Tags.Length; i++)
548+
{
549+
var tag = destinationReference.Tags[i];
550+
manifestsIndexJson[i] = new PlatformSpecificOciManifest
551+
{
552+
mediaType = SchemaTypes.OciImageIndexV1,
553+
size = manifestListJson.Length,
554+
digest = manifestListDigest,
555+
annotations = new Dictionary<string, string>
556+
{
557+
{ "io.containerd.image.name", $"{destinationReference.Repository}:{tag}" },
558+
{ "org.opencontainers.image.ref.name", tag }
559+
}
560+
};
561+
}
562+
557563
var index = new ImageIndexV1
558564
{
559565
schemaVersion = 2,
560566
mediaType = SchemaTypes.OciImageIndexV1,
561-
manifests =
562-
[
563-
new PlatformSpecificOciManifest
564-
{
565-
mediaType = SchemaTypes.OciImageIndexV1,
566-
size = manifestListJson.Length,
567-
digest = manifestListDigest,
568-
annotations = new Dictionary<string, string>
569-
{
570-
{ "io.containerd.image.name", $"{destinationReference.Repository}:{tag}" },
571-
{ "org.opencontainers.image.ref.name", tag }
572-
},
573-
}
574-
]
567+
manifests = manifestsIndexJson
575568
};
576569

577570
using (MemoryStream indexStream = new(Encoding.UTF8.GetBytes(JsonSerializer.SerializeToNode(index, options)!.ToJsonString())))
@@ -592,26 +585,28 @@ private static async Task WriteIndexJsonForOciImage(
592585
{
593586
cancellationToken.ThrowIfCancellationRequested();
594587

595-
string tag = destinationReference.Tags[0];
588+
var manifests = new PlatformSpecificOciManifest[destinationReference.Tags.Length];
589+
for (int i = 0; i < destinationReference.Tags.Length; i++)
590+
{
591+
var tag = destinationReference.Tags[i];
592+
manifests[i] = new PlatformSpecificOciManifest
593+
{
594+
mediaType = SchemaTypes.OciManifestV1,
595+
size = image.Manifest.Length,
596+
digest = image.ManifestDigest,
597+
annotations = new Dictionary<string, string>
598+
{
599+
{ "io.containerd.image.name", $"{destinationReference.Repository}:{tag}" },
600+
{ "org.opencontainers.image.ref.name", tag }
601+
}
602+
};
603+
}
596604

597605
var index = new ImageIndexV1
598606
{
599607
schemaVersion = 2,
600608
mediaType = SchemaTypes.OciImageIndexV1,
601-
manifests =
602-
[
603-
new PlatformSpecificOciManifest
604-
{
605-
mediaType = SchemaTypes.OciManifestV1,
606-
size = image.Manifest.Length,
607-
digest = image.ManifestDigest,
608-
annotations = new Dictionary<string, string>
609-
{
610-
{ "io.containerd.image.name", $"{destinationReference.Repository}:{tag}" },
611-
{ "org.opencontainers.image.ref.name", tag }
612-
}
613-
}
614-
]
609+
manifests = manifests
615610
};
616611

617612
var options = new JsonSerializerOptions

src/Containers/Microsoft.NET.Build.Containers/Resources/Strings.Designer.cs

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/Strings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@
244244
<value>CONTAINER2004: Unable to download layer with descriptor '{0}' from registry '{1}' because it does not exist.</value>
245245
<comment>{StrBegin="CONTAINER2004: "}</comment>
246246
</data>
247-
<data name="OciImageMultipleTagsNotSupported" xml:space="preserve">
248-
<value>Unable to create tarball for oci image with multiple tags.</value>
249-
</data>
250247
<data name="UnsupportedMediaTypeForTarball" xml:space="preserve">
251248
<value>Unable to create tarball for mediaType '{0}'.</value>
252249
</data>

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.cs.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.de.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.es.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.fr.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.it.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.ja.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Containers/Microsoft.NET.Build.Containers/Resources/xlf/Strings.ko.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)