Skip to content

Commit

Permalink
Refactor SourceImageReference
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil committed Dec 19, 2024
1 parent 5b03a85 commit bb98ae0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
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

0 comments on commit bb98ae0

Please sign in to comment.