Skip to content

Commit

Permalink
Flow through generated container image names to callers (#40638)
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel authored May 20, 2024
1 parent d4e0341 commit 0a0c18b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ public static DestinationImageReference CreateFromSettings(
return destinationImageReference;
}

public string[] FullyQualifiedImageNames()
{
switch (Kind)
{
case DestinationImageReferenceKind.RemoteRegistry:
return GenerateRegistryNames(RemoteRegistry!, Repository!, Tags);
case DestinationImageReferenceKind.LocalRegistry:
return GenerateLocalNames(Repository!, Tags);
default:
return Array.Empty<string>();
}

string[] GenerateRegistryNames(Registry registry, string repository, string[] tags)
{
return tags.Select(tag => $"{registry}:{repository}:{tag}").ToArray();
}

string[] GenerateLocalNames(string repository, string[] tags)
{
return tags.Select(tag => $"{repository}:{tag}").ToArray();
}
}

public override string ToString()
{
string tagList = string.Join(", ", Tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateLabels.get -> bool
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateLabels.set -> void
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateDigestLabel.get -> bool
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateDigestLabel.set -> void
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GeneratedContainerNames.get -> Microsoft.Build.Framework.ITaskItem![]!
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GeneratedContainerNames.set -> void
override Microsoft.NET.Build.Containers.Tasks.CreateNewImage.ToolName.get -> string!
override Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateCommandLineCommands() -> string!
override Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateFullPathToTool() -> string!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateLabels.get -> bool
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateLabels.set -> void
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateDigestLabel.get -> bool
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GenerateDigestLabel.set -> void
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GeneratedContainerNames.get -> Microsoft.Build.Framework.ITaskItem![]!
Microsoft.NET.Build.Containers.Tasks.CreateNewImage.GeneratedContainerNames.set -> void
Microsoft.NET.Build.Containers.Tasks.ParseContainerProperties
Microsoft.NET.Build.Containers.Tasks.ParseContainerProperties.ContainerEnvironmentVariables.get -> Microsoft.Build.Framework.ITaskItem![]!
Microsoft.NET.Build.Containers.Tasks.ParseContainerProperties.ContainerEnvironmentVariables.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ partial class CreateNewImage
[Output]
public string GeneratedArchiveOutputPath { get; set; }

[Output]
public ITaskItem[] GeneratedContainerNames { get; set; }

public CreateNewImage()
{
ContainerizeDirectory = "";
Expand Down Expand Up @@ -205,6 +208,7 @@ public CreateNewImage()
GeneratedContainerManifest = "";
GeneratedContainerDigest = "";
GeneratedArchiveOutputPath = "";
GeneratedContainerNames = Array.Empty<ITaskItem>();

GenerateLabels = false;
GenerateDigestLabel = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ internal async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
GeneratedContainerConfiguration = builtImage.Config;
GeneratedContainerDigest = builtImage.Manifest.GetDigest();
GeneratedArchiveOutputPath = ArchiveOutputPath;
GeneratedContainerNames = destinationImageReference.FullyQualifiedImageNames().Select(name => new Microsoft.Build.Utilities.TaskItem(name)).ToArray();

switch (destinationImageReference.Kind)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
<Output TaskParameter="GeneratedContainerConfiguration" PropertyName="GeneratedContainerConfiguration" />
<Output TaskParameter="GeneratedContainerDigest" PropertyName="GeneratedContainerDigest" />
<Output TaskParameter="GeneratedArchiveOutputPath" PropertyName="GeneratedArchiveOutputPath" />
<Output TaskParameter="GeneratedContainerNames" ItemName="GeneratedContainerName" />
</CreateNewImage>
</Target>
</Project>

0 comments on commit 0a0c18b

Please sign in to comment.