Skip to content

Commit

Permalink
[automated] Merge branch 'release/8.0.4xx' => 'release/9.0.1xx' (#44658)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiYanni authored Nov 7, 2024
2 parents c96b65d + 64c9452 commit c4d0cd7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/Containers/Microsoft.NET.Build.Containers/BuiltImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ internal readonly struct BuiltImage
/// </summary>
internal required ManifestV2 Manifest { get; init; }

/// <summary>
/// Gets manifest mediaType.
/// </summary>
internal required string ManifestMediaType { get; init; }

/// <summary>
/// Gets layers descriptors.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions src/Containers/Microsoft.NET.Build.Containers/ImageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal sealed class ImageBuilder

// the mutable internal manifest that we're building by modifying the base and applying customizations
private readonly ManifestV2 _manifest;
private readonly string _manifestMediaType;
private readonly ImageConfig _baseImageConfig;
private readonly ILogger _logger;

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

internal ImageBuilder(ManifestV2 manifest, ImageConfig baseImageConfig, ILogger logger)
internal ImageBuilder(ManifestV2 manifest, string manifestMediaType, ImageConfig baseImageConfig, ILogger logger)
{
_baseImageManifest = manifest;
_manifest = new ManifestV2() { SchemaVersion = manifest.SchemaVersion, Config = manifest.Config, Layers = new(manifest.Layers), MediaType = manifest.MediaType };
_manifestMediaType = manifestMediaType;
_baseImageConfig = baseImageConfig;
_logger = logger;
}
Expand Down Expand Up @@ -83,6 +85,7 @@ internal BuiltImage Build()
ImageSha = imageSha,
ImageSize = imageSize,
Manifest = newManifest,
ManifestMediaType = ManifestMediaType
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ManifestV2
/// 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.
/// </summary>
[JsonPropertyName("mediaType")]
public required string MediaType { get; init; }
public string? MediaType { get; init; }

/// <summary>
/// This REQUIRED property references a configuration object for a container, by digest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Microsoft.NET.Build.Containers.ManifestV2.KnownDigest.set -> void
Microsoft.NET.Build.Containers.ManifestV2.Layers.get -> System.Collections.Generic.List<Microsoft.NET.Build.Containers.ManifestLayer>!
Microsoft.NET.Build.Containers.ManifestV2.Layers.init -> void
Microsoft.NET.Build.Containers.ManifestV2.ManifestV2() -> void
Microsoft.NET.Build.Containers.ManifestV2.MediaType.get -> string!
Microsoft.NET.Build.Containers.ManifestV2.MediaType.get -> string?
Microsoft.NET.Build.Containers.ManifestV2.MediaType.init -> void
Microsoft.NET.Build.Containers.ManifestV2.SchemaVersion.get -> int
Microsoft.NET.Build.Containers.ManifestV2.SchemaVersion.init -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public async Task<HttpResponseMessage> GetAsync(string repositoryName, string re
};
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ internal interface IManifestOperations
{
public Task<HttpResponseMessage> GetAsync(string repositoryName, string reference, CancellationToken cancellationToken);

public Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, CancellationToken cancellationToken);
public Task PutAsync(string repositoryName, string reference, ManifestV2 manifest, string mediaType, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public async Task<ImageBuilder> GetImageManifestAsync(string repositoryName, str
SchemaTypes.DockerManifestV2 or SchemaTypes.OciManifestV1 => await ReadSingleImageAsync(
repositoryName,
await ReadManifest().ConfigureAwait(false),
initialManifestResponse.Content.Headers.ContentType.MediaType,
cancellationToken).ConfigureAwait(false),
SchemaTypes.DockerManifestListV2 => await PickBestImageFromManifestListAsync(
repositoryName,
Expand Down Expand Up @@ -231,7 +232,7 @@ async Task<ManifestV2> ReadManifest()
};
}

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

cancellationToken.ThrowIfCancellationRequested();
return new ImageBuilder(manifest, new ImageConfig(configDoc), _logger);
// ManifestV2.MediaType can be null, so we also provide manifest mediaType from http response
return new ImageBuilder(manifest, manifest.MediaType ?? manifestMediaType, new ImageConfig(configDoc), _logger);
}


Expand Down Expand Up @@ -350,6 +352,7 @@ private async Task<ImageBuilder> PickBestImageFromManifestsAsync(
return await ReadSingleImageAsync(
repositoryName,
manifest,
matchingManifest.mediaType,
cancellationToken).ConfigureAwait(false);
}
else
Expand Down Expand Up @@ -562,15 +565,15 @@ private async Task PushAsync(BuiltImage builtImage, SourceImageReference source,
foreach (string tag in destination.Tags)
{
_logger.LogInformation(Strings.Registry_TagUploadStarted, tag, RegistryName);
await _registryAPI.Manifest.PutAsync(destination.Repository, tag, builtImage.Manifest, cancellationToken).ConfigureAwait(false);
await _registryAPI.Manifest.PutAsync(destination.Repository, tag, builtImage.Manifest, builtImage.ManifestMediaType, cancellationToken).ConfigureAwait(false);
_logger.LogInformation(Strings.Registry_TagUploaded, tag, RegistryName);
}
}
else
{
string manifestDigest = builtImage.Manifest.GetDigest();
_logger.LogInformation(Strings.Registry_ManifestUploadStarted, RegistryName, manifestDigest);
await _registryAPI.Manifest.PutAsync(destination.Repository, manifestDigest, builtImage.Manifest, cancellationToken).ConfigureAwait(false);
await _registryAPI.Manifest.PutAsync(destination.Repository, manifestDigest, builtImage.Manifest, builtImage.ManifestMediaType, cancellationToken).ConfigureAwait(false);
_logger.LogInformation(Strings.Registry_ManifestUploaded, RegistryName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,6 @@ private ImageBuilder FromBaseImageConfig(string baseImageConfig, [CallerMemberNa
Layers = new List<ManifestLayer>(),
KnownDigest = StaticKnownDigestValue
};
return new ImageBuilder(manifest, new ImageConfig(baseImageConfig), _loggerFactory.CreateLogger(testName));
return new ImageBuilder(manifest, manifest.MediaType, new ImageConfig(baseImageConfig), _loggerFactory.CreateLogger(testName));
}
}

0 comments on commit c4d0cd7

Please sign in to comment.