From 0a0c18bc213cf229c9339b66a36c3b6cef4aef19 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Mon, 20 May 2024 13:42:31 -0500 Subject: [PATCH] Flow through generated container image names to callers (#40638) --- .../DestinationImageReference.cs | 23 +++++++++++++++++++ .../PublicAPI/net472/PublicAPI.Unshipped.txt | 2 ++ .../PublicAPI/net9.0/PublicAPI.Unshipped.txt | 2 ++ .../Tasks/CreateNewImage.Interface.cs | 4 ++++ .../Tasks/CreateNewImage.cs | 1 + .../Microsoft.NET.Build.Containers.targets | 1 + 6 files changed, 33 insertions(+) diff --git a/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs b/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs index 46eb30ebc338..dc9c99a9fb97 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/DestinationImageReference.cs @@ -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[] 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); diff --git a/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net472/PublicAPI.Unshipped.txt b/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net472/PublicAPI.Unshipped.txt index 0b82e88410db..949884cb12ce 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net472/PublicAPI.Unshipped.txt +++ b/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net472/PublicAPI.Unshipped.txt @@ -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! diff --git a/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net9.0/PublicAPI.Unshipped.txt b/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net9.0/PublicAPI.Unshipped.txt index 539990b90260..ef5a939ac5a4 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net9.0/PublicAPI.Unshipped.txt +++ b/src/Containers/Microsoft.NET.Build.Containers/PublicAPI/net9.0/PublicAPI.Unshipped.txt @@ -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 diff --git a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.Interface.cs b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.Interface.cs index 19cf905128a3..4f69658c66d2 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.Interface.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.Interface.cs @@ -173,6 +173,9 @@ partial class CreateNewImage [Output] public string GeneratedArchiveOutputPath { get; set; } + [Output] + public ITaskItem[] GeneratedContainerNames { get; set; } + public CreateNewImage() { ContainerizeDirectory = ""; @@ -205,6 +208,7 @@ public CreateNewImage() GeneratedContainerManifest = ""; GeneratedContainerDigest = ""; GeneratedArchiveOutputPath = ""; + GeneratedContainerNames = Array.Empty(); GenerateLabels = false; GenerateDigestLabel = false; diff --git a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs index 4b681a514d00..4ceb12525c7e 100644 --- a/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs +++ b/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs @@ -163,6 +163,7 @@ internal async Task 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) { diff --git a/src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets b/src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets index f4d8f2028cc4..0df9ee32e2de 100644 --- a/src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets +++ b/src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets @@ -270,6 +270,7 @@ +