Skip to content

Commit 67cdc6c

Browse files
Single definition for task inputs/outputs (#244)
Define the inputs and outputs of the two task implementations in a single file, pulled into both classes. Fixes #171.
1 parent 738731f commit 67cdc6c

File tree

4 files changed

+128
-225
lines changed

4 files changed

+128
-225
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
3+
using Microsoft.Build.Framework;
4+
5+
namespace Microsoft.NET.Build.Containers.Tasks;
6+
7+
partial class CreateNewImage
8+
{
9+
/// <summary>
10+
/// The path to the folder containing `containerize.dll`.
11+
/// </summary>
12+
/// <remarks>
13+
/// Used only for the ToolTask implementation of this task.
14+
/// </remarks>
15+
public string ContainerizeDirectory { get; set; }
16+
17+
/// <summary>
18+
/// The base registry to pull from.
19+
/// Ex: mcr.microsoft.com
20+
/// </summary>
21+
[Required]
22+
public string BaseRegistry { get; set; }
23+
24+
/// <summary>
25+
/// The base image to pull.
26+
/// Ex: dotnet/runtime
27+
/// </summary>
28+
[Required]
29+
public string BaseImageName { get; set; }
30+
31+
/// <summary>
32+
/// The base image tag.
33+
/// Ex: 6.0
34+
/// </summary>
35+
[Required]
36+
public string BaseImageTag { get; set; }
37+
38+
/// <summary>
39+
/// The registry to push to.
40+
/// </summary>
41+
public string OutputRegistry { get; set; }
42+
43+
/// <summary>
44+
/// The name of the output image that will be pushed to the registry.
45+
/// </summary>
46+
[Required]
47+
public string ImageName { get; set; }
48+
49+
/// <summary>
50+
/// The tag to associate with the new image.
51+
/// </summary>
52+
public string[] ImageTags { get; set; }
53+
54+
/// <summary>
55+
/// The directory for the build outputs to be published.
56+
/// Constructed from "$(MSBuildProjectDirectory)\$(PublishDir)"
57+
/// </summary>
58+
[Required]
59+
public string PublishDirectory { get; set; }
60+
61+
/// <summary>
62+
/// The working directory of the container.
63+
/// </summary>
64+
[Required]
65+
public string WorkingDirectory { get; set; }
66+
67+
/// <summary>
68+
/// The entrypoint application of the container.
69+
/// </summary>
70+
[Required]
71+
public ITaskItem[] Entrypoint { get; set; }
72+
73+
/// <summary>
74+
/// Arguments to pass alongside Entrypoint.
75+
/// </summary>
76+
public ITaskItem[] EntrypointArgs { get; set; }
77+
78+
/// <summary>
79+
/// Ports that the application declares that it will use.
80+
/// Note that this means nothing to container hosts, by default -
81+
/// it's mostly documentation.
82+
/// </summary>
83+
public ITaskItem[] ExposedPorts { get; set; }
84+
85+
/// <summary>
86+
/// Labels that the image configuration will include in metadata
87+
/// </summary>
88+
public ITaskItem[] Labels { get; set; }
89+
90+
/// <summary>
91+
/// Container environment variables to set.
92+
/// </summary>
93+
public ITaskItem[] ContainerEnvironmentVariables { get; set; }
94+
95+
[Output]
96+
public string GeneratedContainerManifest { get; set; }
97+
98+
[Output]
99+
public string GeneratedContainerConfiguration { get; set; }
100+
101+
public CreateNewImage()
102+
{
103+
ContainerizeDirectory = "";
104+
ToolExe = "";
105+
ToolPath = "";
106+
BaseRegistry = "";
107+
BaseImageName = "";
108+
BaseImageTag = "";
109+
OutputRegistry = "";
110+
ImageName = "";
111+
ImageTags = Array.Empty<string>();
112+
PublishDirectory = "";
113+
WorkingDirectory = "";
114+
Entrypoint = Array.Empty<ITaskItem>();
115+
EntrypointArgs = Array.Empty<ITaskItem>();
116+
Labels = Array.Empty<ITaskItem>();
117+
ExposedPorts = Array.Empty<ITaskItem>();
118+
ContainerEnvironmentVariables = Array.Empty<ITaskItem>();
119+
GeneratedContainerConfiguration = "";
120+
GeneratedContainerManifest = "";
121+
}
122+
}

Microsoft.NET.Build.Containers/CreateNewImage.cs

Lines changed: 3 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,134 +2,22 @@
22

33
namespace Microsoft.NET.Build.Containers.Tasks;
44

5-
public class CreateNewImage : Microsoft.Build.Utilities.Task
5+
public partial class CreateNewImage : Microsoft.Build.Utilities.Task
66
{
7-
8-
/// <summary>
9-
/// Unused. This exists so we can call a single task invocation in PublishContainer.
10-
/// </summary>
11-
public string ContainerizeDirectory { get; set; }
12-
137
/// <summary>
14-
/// Unused. See above.
8+
/// Unused. For interface parity with the ToolTask implementation of the task.
159
/// </summary>
1610
public string ToolExe { get; set; }
1711

1812
/// <summary>
19-
/// Unused. See above.
13+
/// Unused. For interface parity with the ToolTask implementation of the task.
2014
/// </summary>
2115
public string ToolPath { get; set; }
2216

23-
/// <summary>
24-
/// The base registry to pull from.
25-
/// Ex: mcr.microsoft.com
26-
/// </summary>
27-
[Required]
28-
public string BaseRegistry { get; set; }
29-
30-
/// <summary>
31-
/// The base image to pull.
32-
/// Ex: dotnet/runtime
33-
/// </summary>
34-
[Required]
35-
public string BaseImageName { get; set; }
36-
37-
/// <summary>
38-
/// The base image tag.
39-
/// Ex: 6.0
40-
/// </summary>
41-
[Required]
42-
public string BaseImageTag { get; set; }
43-
44-
/// <summary>
45-
/// The registry to push to.
46-
/// </summary>
47-
public string OutputRegistry { get; set; }
48-
49-
/// <summary>
50-
/// The name of the output image that will be pushed to the registry.
51-
/// </summary>
52-
[Required]
53-
public string ImageName { get; set; }
54-
55-
/// <summary>
56-
/// The tag to associate with the new image.
57-
/// </summary>
58-
public string[] ImageTags { get; set; }
59-
60-
/// <summary>
61-
/// The directory for the build outputs to be published.
62-
/// Constructed from "$(MSBuildProjectDirectory)\$(PublishDir)"
63-
/// </summary>
64-
[Required]
65-
public string PublishDirectory { get; set; }
66-
67-
/// <summary>
68-
/// The working directory of the container.
69-
/// </summary>
70-
[Required]
71-
public string WorkingDirectory { get; set; }
72-
73-
/// <summary>
74-
/// The entrypoint application of the container.
75-
/// </summary>
76-
[Required]
77-
public ITaskItem[] Entrypoint { get; set; }
78-
79-
/// <summary>
80-
/// Arguments to pass alongside Entrypoint.
81-
/// </summary>
82-
public ITaskItem[] EntrypointArgs { get; set; }
83-
84-
/// <summary>
85-
/// Ports that the application declares that it will use.
86-
/// Note that this means nothing to container hosts, by default -
87-
/// it's mostly documentation.
88-
/// </summary>
89-
public ITaskItem[] ExposedPorts { get; set; }
90-
91-
/// <summary>
92-
/// Labels that the image configuration will include in metadata
93-
/// </summary>
94-
public ITaskItem[] Labels { get; set; }
95-
96-
/// <summary>
97-
/// Container environment variables to set.
98-
/// </summary>
99-
public ITaskItem[] ContainerEnvironmentVariables { get; set; }
100-
101-
[Output]
102-
public string GeneratedContainerManifest { get; set; }
103-
104-
[Output]
105-
public string GeneratedContainerConfiguration { get; set; }
106-
10717
private bool IsDockerPush { get => String.IsNullOrEmpty(OutputRegistry); }
10818

10919
private bool IsDockerPull { get => String.IsNullOrEmpty(BaseRegistry); }
11020

111-
public CreateNewImage()
112-
{
113-
ContainerizeDirectory = "";
114-
ToolExe = "";
115-
ToolPath = "";
116-
BaseRegistry = "";
117-
BaseImageName = "";
118-
BaseImageTag = "";
119-
OutputRegistry = "";
120-
ImageName = "";
121-
ImageTags = Array.Empty<string>();
122-
PublishDirectory = "";
123-
WorkingDirectory = "";
124-
Entrypoint = Array.Empty<ITaskItem>();
125-
EntrypointArgs = Array.Empty<ITaskItem>();
126-
Labels = Array.Empty<ITaskItem>();
127-
ExposedPorts = Array.Empty<ITaskItem>();
128-
ContainerEnvironmentVariables = Array.Empty<ITaskItem>();
129-
GeneratedContainerConfiguration = "";
130-
GeneratedContainerManifest = "";
131-
}
132-
13321
private void SetPorts(Image image, ITaskItem[] exposedPorts)
13422
{
13523
foreach (var port in exposedPorts)

Microsoft.NET.Build.Containers/CreateNewImageToolTask.cs

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -10,95 +10,8 @@ namespace Microsoft.NET.Build.Containers.Tasks;
1010
/// <summary>
1111
/// This task will shell out to the net7.0-targeted application for VS scenarios.
1212
/// </summary>
13-
public class CreateNewImage : ToolTask
13+
public partial class CreateNewImage : ToolTask
1414
{
15-
/// <summary>
16-
/// The path to the folder containing `containerize.dll`.
17-
/// </summary>
18-
[Required]
19-
public string ContainerizeDirectory { get; set; }
20-
21-
[Required]
22-
public string BaseRegistry { get; set; }
23-
24-
/// <summary>
25-
/// The base image to pull.
26-
/// Ex: dotnet/runtime
27-
/// </summary>
28-
[Required]
29-
public string BaseImageName { get; set; }
30-
31-
/// <summary>
32-
/// The base image tag.
33-
/// Ex: 6.0
34-
/// </summary>
35-
[Required]
36-
public string BaseImageTag { get; set; }
37-
38-
/// <summary>
39-
/// The registry to push to.
40-
/// </summary>
41-
[Required]
42-
public string OutputRegistry { get; set; }
43-
44-
/// <summary>
45-
/// The name of the output image that will be pushed to the registry.
46-
/// </summary>
47-
[Required]
48-
public string ImageName { get; set; }
49-
50-
/// <summary>
51-
/// The tag to associate with the new image.
52-
/// </summary>
53-
public ITaskItem[] ImageTags { get; set; }
54-
55-
/// <summary>
56-
/// The directory for the build outputs to be published.
57-
/// Constructed from "$(MSBuildProjectDirectory)\$(PublishDir)"
58-
/// </summary>
59-
[Required]
60-
public string PublishDirectory { get; set; }
61-
62-
/// <summary>
63-
/// The working directory of the container.
64-
/// </summary>
65-
[Required]
66-
public string WorkingDirectory { get; set; }
67-
68-
/// <summary>
69-
/// The entrypoint application of the container.
70-
/// </summary>
71-
[Required]
72-
public ITaskItem[] Entrypoint { get; set; }
73-
74-
/// <summary>
75-
/// Arguments to pass alongside Entrypoint.
76-
/// </summary>
77-
public ITaskItem[] EntrypointArgs { get; set; }
78-
79-
/// <summary>
80-
/// Labels that the image configuration will include in metadata
81-
/// </summary>
82-
public ITaskItem[] Labels { get; set; }
83-
84-
/// <summary>
85-
/// Ports that the application declares that it will use.
86-
/// Note that this means nothing to container hosts, by default -
87-
/// it's mostly documentation.
88-
/// </summary>
89-
public ITaskItem[] ExposedPorts { get; set; }
90-
91-
/// <summary>
92-
/// Container environment variables to set.
93-
/// </summary>
94-
public ITaskItem[] ContainerEnvironmentVariables { get; set; }
95-
96-
[Output]
97-
public string GeneratedContainerManifest { get; set; }
98-
99-
[Output]
100-
public string GeneratedContainerConfiguration { get; set; }
101-
10215
// Unused, ToolExe is set via targets and overrides this.
10316
protected override string ToolName => "dotnet";
10417

@@ -118,27 +31,6 @@ private string DotNetPath
11831
}
11932
}
12033

121-
public CreateNewImage()
122-
{
123-
ContainerizeDirectory = "";
124-
BaseRegistry = "";
125-
BaseImageName = "";
126-
BaseImageTag = "";
127-
OutputRegistry = "";
128-
ImageName = "";
129-
ImageTags = Array.Empty<ITaskItem>();
130-
PublishDirectory = "";
131-
WorkingDirectory = "";
132-
Entrypoint = Array.Empty<ITaskItem>();
133-
EntrypointArgs = Array.Empty<ITaskItem>();
134-
Labels = Array.Empty<ITaskItem>();
135-
ExposedPorts = Array.Empty<ITaskItem>();
136-
ContainerEnvironmentVariables = Array.Empty<ITaskItem>();
137-
extractionInfo = (false, string.Empty, string.Empty);
138-
GeneratedContainerConfiguration = "";
139-
GeneratedContainerManifest = "";
140-
}
141-
14234
protected override string GenerateFullPathToTool() => Quote(Path.Combine(DotNetPath, ToolExe));
14335

14436
/// <summary>
@@ -188,7 +80,7 @@ protected override string GenerateCommandLineCommands()
18880
" --workingdirectory " + WorkingDirectory +
18981
(Entrypoint.Length > 0 ? " --entrypoint " + String.Join(" ", Entrypoint.Select((i) => i.ItemSpec)) : "") +
19082
(Labels.Length > 0 ? " --labels " + String.Join(" ", Labels.Select((i) => i.ItemSpec + "=" + Quote(i.GetMetadata("Value")))) : "") +
191-
(ImageTags.Length > 0 ? " --imagetags " + String.Join(" ", ImageTags.Select((i) => Quote(i.ItemSpec))) : "") +
83+
(ImageTags.Length > 0 ? " --imagetags " + String.Join(" ", ImageTags.Select((i) => Quote(i))) : "") +
19284
(EntrypointArgs.Length > 0 ? " --entrypointargs " + String.Join(" ", EntrypointArgs.Select((i) => i.ItemSpec)) : "") +
19385
(ExposedPorts.Length > 0 ? " --ports " + String.Join(" ", ExposedPorts.Select((i) => i.ItemSpec + "/" + i.GetMetadata("Type"))) : "") +
19486
(ContainerEnvironmentVariables.Length > 0 ? " --environmentvariables " + String.Join(" ", ContainerEnvironmentVariables.Select((i) => i.ItemSpec + "=" + Quote(i.GetMetadata("Value")))) : "");

0 commit comments

Comments
 (0)