diff --git a/Microsoft.NET.Build.Containers/CreateNewImage.cs b/Microsoft.NET.Build.Containers/CreateNewImage.cs index 718238b8..a343fda5 100644 --- a/Microsoft.NET.Build.Containers/CreateNewImage.cs +++ b/Microsoft.NET.Build.Containers/CreateNewImage.cs @@ -66,6 +66,11 @@ public class CreateNewImage : Microsoft.Build.Utilities.Task /// public ITaskItem[] EntrypointArgs { get; set; } + /// + /// Labels that the image configuration will include in metadata + /// + public ITaskItem[] Labels { get; set; } + public CreateNewImage() { BaseRegistry = ""; @@ -78,6 +83,7 @@ public CreateNewImage() WorkingDirectory = ""; Entrypoint = Array.Empty(); EntrypointArgs = Array.Empty(); + Labels = Array.Empty(); } @@ -112,6 +118,11 @@ public override bool Execute() image.WorkingDirectory = WorkingDirectory; image.SetEntrypoint(Entrypoint.Select(i => i.ItemSpec).ToArray(), EntrypointArgs.Select(i => i.ItemSpec).ToArray()); + foreach (var label in Labels) + { + image.Label(label.ItemSpec, label.GetMetadata("Value")); + } + if (OutputRegistry.StartsWith("docker://")) { try diff --git a/Microsoft.NET.Build.Containers/Image.cs b/Microsoft.NET.Build.Containers/Image.cs index 372c0ebc..03902abd 100644 --- a/Microsoft.NET.Build.Containers/Image.cs +++ b/Microsoft.NET.Build.Containers/Image.cs @@ -5,6 +5,8 @@ namespace Microsoft.NET.Build.Containers; +record Label(string name, string value); + public class Image { public JsonNode manifest; @@ -15,6 +17,8 @@ public class Image internal List newLayers = new(); + internal HashSet