Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using Digest for base image #44461

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor SourceImageReference
  • Loading branch information
BeyondEvil committed Dec 20, 2024
commit 0324adbe35eab2714b0b59bfaa24ad65c65c7112
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ internal static async Task<int> ContainerizeAsync(
{
try
{
string imageReference = !string.IsNullOrEmpty(baseImageDigest) ? baseImageDigest : baseImageTag;
var ridGraphPicker = new RidGraphManifestPicker(ridGraphPath);
imageBuilder = await registry.GetImageManifestAsync(
baseImageName,
imageReference,
sourceImageReference.Reference,
containerRuntimeIdentifier,
ridGraphPicker,
cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ namespace Microsoft.NET.Build.Containers;
/// <summary>
/// Represents a reference to a Docker image. A reference is made of a registry, a repository (aka the image name) and a tag or digest.
/// </summary>
internal readonly record struct SourceImageReference(Registry? Registry, string Repository, string Tag, string? Digest)
internal readonly record struct SourceImageReference(Registry? Registry, string Repository, string? Tag, string? Digest)
{
public override string ToString()
{
string sourceImageReference = RepositoryAndTag;
string sourceImageReference = Repository;

if (Registry is { } reg)
{
sourceImageReference = $"{reg.RegistryName}/{sourceImageReference}";
}

if (!string.IsNullOrEmpty(Tag))
{
sourceImageReference = $"{sourceImageReference}:{Tag}";
}

if (!string.IsNullOrEmpty(Digest))
{
sourceImageReference = $"{sourceImageReference}@{Digest}";
Expand All @@ -28,5 +33,6 @@ public override string ToString()
/// <summary>
/// Returns the repository and tag as a formatted string. Used in cases
/// </summary>
public readonly string RepositoryAndTag => $"{Repository}:{Tag}";
public string Reference
=> !string.IsNullOrEmpty(Digest) ? Digest : !string.IsNullOrEmpty(Tag) ? Tag : "latest";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ partial class CreateNewImage
/// The base image tag.
/// Ex: 6.0
/// </summary>
[Required]
public string BaseImageTag { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ internal async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
{
try
{
string imageReference = !string.IsNullOrEmpty(BaseImageDigest) ? BaseImageDigest : BaseImageTag;
var picker = new RidGraphManifestPicker(RuntimeIdentifierGraphPath);
imageBuilder = await registry.GetImageManifestAsync(
BaseImageName,
imageReference,
sourceImageReference.Reference,
ContainerRuntimeIdentifier,
picker,
cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public override bool Execute()

ParsedContainerRegistry = outputReg ?? "";
ParsedContainerImage = outputImage ?? "";
// If no Tag was provided, default to "latest"
ParsedContainerTag = outputTag ?? "latest";
ParsedContainerTag = outputTag ?? "";
ParsedContainerDigest = outputDigest ?? "";
NewContainerRegistry = ContainerRegistry;
NewContainerTags = validTags;
Expand Down