Skip to content

Commit c4d0cd7

Browse files
authored
[automated] Merge branch 'release/8.0.4xx' => 'release/9.0.1xx' (#44658)
2 parents c96b65d + 64c9452 commit c4d0cd7

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

src/Containers/Microsoft.NET.Build.Containers/BuiltImage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ internal readonly struct BuiltImage
3333
/// </summary>
3434
internal required ManifestV2 Manifest { get; init; }
3535

36+
/// <summary>
37+
/// Gets manifest mediaType.
38+
/// </summary>
39+
internal required string ManifestMediaType { get; init; }
40+
3641
/// <summary>
3742
/// Gets layers descriptors.
3843
/// </summary>

src/Containers/Microsoft.NET.Build.Containers/ImageBuilder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal sealed class ImageBuilder
1919

2020
// the mutable internal manifest that we're building by modifying the base and applying customizations
2121
private readonly ManifestV2 _manifest;
22+
private readonly string _manifestMediaType;
2223
private readonly ImageConfig _baseImageConfig;
2324
private readonly ILogger _logger;
2425

@@ -33,12 +34,13 @@ internal sealed class ImageBuilder
3334
/// <summary>
3435
/// MediaType of the output manifest.
3536
/// </summary>
36-
public string ManifestMediaType => _manifest.MediaType; // output the same media type as the base image manifest.
37+
public string ManifestMediaType => _manifestMediaType; // output the same media type as the base image manifest.
3738

38-
internal ImageBuilder(ManifestV2 manifest, ImageConfig baseImageConfig, ILogger logger)
39+
internal ImageBuilder(ManifestV2 manifest, string manifestMediaType, ImageConfig baseImageConfig, ILogger logger)
3940
{
4041
_baseImageManifest = manifest;
4142
_manifest = new ManifestV2() { SchemaVersion = manifest.SchemaVersion, Config = manifest.Config, Layers = new(manifest.Layers), MediaType = manifest.MediaType };
43+
_manifestMediaType = manifestMediaType;
4244
_baseImageConfig = baseImageConfig;
4345
_logger = logger;
4446
}
@@ -83,6 +85,7 @@ internal BuiltImage Build()
8385
ImageSha = imageSha,
8486
ImageSize = imageSize,
8587
Manifest = newManifest,
88+
ManifestMediaType = ManifestMediaType
8689
};
8790
}
8891

src/Containers/Microsoft.NET.Build.Containers/ManifestV2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ManifestV2
3030
/// When used, this field MUST contain the media type application/vnd.oci.image.manifest.v1+json. This field usage differs from the descriptor use of mediaType.
3131
/// </summary>
3232
[JsonPropertyName("mediaType")]
33-
public required string MediaType { get; init; }
33+
public string? MediaType { get; init; }
3434

3535
/// <summary>
3636
/// This REQUIRED property references a configuration object for a container, by digest.

src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net9.0/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Microsoft.NET.Build.Containers.ManifestV2.KnownDigest.set -> void
9090
Microsoft.NET.Build.Containers.ManifestV2.Layers.get -> System.Collections.Generic.List<Microsoft.NET.Build.Containers.ManifestLayer>!
9191
Microsoft.NET.Build.Containers.ManifestV2.Layers.init -> void
9292
Microsoft.NET.Build.Containers.ManifestV2.ManifestV2() -> void
93-
Microsoft.NET.Build.Containers.ManifestV2.MediaType.get -> string!
93+
Microsoft.NET.Build.Containers.ManifestV2.MediaType.get -> string?
9494
Microsoft.NET.Build.Containers.ManifestV2.MediaType.init -> void
9595
Microsoft.NET.Build.Containers.ManifestV2.SchemaVersion.get -> int
9696
Microsoft.NET.Build.Containers.ManifestV2.SchemaVersion.init -> void

src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultManifestOperations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public async Task<HttpResponseMessage> GetAsync(string repositoryName, string re
3838
};
3939
}
4040

41-
public async Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, CancellationToken cancellationToken)
41+
public async Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, string mediaType, CancellationToken cancellationToken)
4242
{
4343
string jsonString = JsonSerializer.SerializeToNode(manifest)?.ToJsonString() ?? "";
4444
HttpContent manifestUploadContent = new StringContent(jsonString);
45-
manifestUploadContent.Headers.ContentType = new MediaTypeHeaderValue(manifest.MediaType);
45+
manifestUploadContent.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
4646

4747
HttpResponseMessage putResponse = await _client.PutAsync(new Uri(_baseUri, $"/v2/{repositoryName}/manifests/{reference}"), manifestUploadContent, cancellationToken).ConfigureAwait(false);
4848

src/Containers/Microsoft.NET.Build.Containers/Registry/IManifestOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ internal interface IManifestOperations
1414
{
1515
public Task<HttpResponseMessage> GetAsync(string repositoryName, string reference, CancellationToken cancellationToken);
1616

17-
public Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, CancellationToken cancellationToken);
17+
public Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, string mediaType, CancellationToken cancellationToken);
1818
}

src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public async Task<ImageBuilder> GetImageManifestAsync(string repositoryName, str
183183
SchemaTypes.DockerManifestV2 or SchemaTypes.OciManifestV1 => await ReadSingleImageAsync(
184184
repositoryName,
185185
await ReadManifest().ConfigureAwait(false),
186+
initialManifestResponse.Content.Headers.ContentType.MediaType,
186187
cancellationToken).ConfigureAwait(false),
187188
SchemaTypes.DockerManifestListV2 => await PickBestImageFromManifestListAsync(
188189
repositoryName,
@@ -231,7 +232,7 @@ async Task<ManifestV2> ReadManifest()
231232
};
232233
}
233234

234-
private async Task<ImageBuilder> ReadSingleImageAsync(string repositoryName, ManifestV2 manifest, CancellationToken cancellationToken)
235+
private async Task<ImageBuilder> ReadSingleImageAsync(string repositoryName, ManifestV2 manifest, string manifestMediaType, CancellationToken cancellationToken)
235236
{
236237
cancellationToken.ThrowIfCancellationRequested();
237238
ManifestConfig config = manifest.Config;
@@ -240,7 +241,8 @@ private async Task<ImageBuilder> ReadSingleImageAsync(string repositoryName, Man
240241
JsonNode configDoc = await _registryAPI.Blob.GetJsonAsync(repositoryName, configSha, cancellationToken).ConfigureAwait(false);
241242

242243
cancellationToken.ThrowIfCancellationRequested();
243-
return new ImageBuilder(manifest, new ImageConfig(configDoc), _logger);
244+
// ManifestV2.MediaType can be null, so we also provide manifest mediaType from http response
245+
return new ImageBuilder(manifest, manifest.MediaType ?? manifestMediaType, new ImageConfig(configDoc), _logger);
244246
}
245247

246248

@@ -350,6 +352,7 @@ private async Task<ImageBuilder> PickBestImageFromManifestsAsync(
350352
return await ReadSingleImageAsync(
351353
repositoryName,
352354
manifest,
355+
matchingManifest.mediaType,
353356
cancellationToken).ConfigureAwait(false);
354357
}
355358
else
@@ -562,15 +565,15 @@ private async Task PushAsync(BuiltImage builtImage, SourceImageReference source,
562565
foreach (string tag in destination.Tags)
563566
{
564567
_logger.LogInformation(Strings.Registry_TagUploadStarted, tag, RegistryName);
565-
await _registryAPI.Manifest.PutAsync(destination.Repository, tag, builtImage.Manifest, cancellationToken).ConfigureAwait(false);
568+
await _registryAPI.Manifest.PutAsync(destination.Repository, tag, builtImage.Manifest, builtImage.ManifestMediaType, cancellationToken).ConfigureAwait(false);
566569
_logger.LogInformation(Strings.Registry_TagUploaded, tag, RegistryName);
567570
}
568571
}
569572
else
570573
{
571574
string manifestDigest = builtImage.Manifest.GetDigest();
572575
_logger.LogInformation(Strings.Registry_ManifestUploadStarted, RegistryName, manifestDigest);
573-
await _registryAPI.Manifest.PutAsync(destination.Repository, manifestDigest, builtImage.Manifest, cancellationToken).ConfigureAwait(false);
576+
await _registryAPI.Manifest.PutAsync(destination.Repository, manifestDigest, builtImage.Manifest, builtImage.ManifestMediaType, cancellationToken).ConfigureAwait(false);
574577
_logger.LogInformation(Strings.Registry_ManifestUploaded, RegistryName);
575578
}
576579
}

test/Microsoft.NET.Build.Containers.UnitTests/ImageBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,6 @@ private ImageBuilder FromBaseImageConfig(string baseImageConfig, [CallerMemberNa
703703
Layers = new List<ManifestLayer>(),
704704
KnownDigest = StaticKnownDigestValue
705705
};
706-
return new ImageBuilder(manifest, new ImageConfig(baseImageConfig), _loggerFactory.CreateLogger(testName));
706+
return new ImageBuilder(manifest, manifest.MediaType, new ImageConfig(baseImageConfig), _loggerFactory.CreateLogger(testName));
707707
}
708708
}

0 commit comments

Comments
 (0)