generated from dotnet/new-repo
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ContainerEnvironmentVariables (#181)
- Loading branch information
1 parent
548091b
commit 9aca15f
Showing
11 changed files
with
255 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,91 @@ public void ParseContainerProperties_EndToEnd() | |
Assert.IsTrue(cni.Execute()); | ||
newProjectDir.Delete(true); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a console app that outputs the environment variable added to the image. | ||
/// </summary> | ||
[TestMethod] | ||
public void Tasks_EndToEnd_With_EnvironmentVariable_Validation() | ||
{ | ||
DirectoryInfo newProjectDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), nameof(Tasks_EndToEnd_With_EnvironmentVariable_Validation))); | ||
|
||
if (newProjectDir.Exists) | ||
{ | ||
newProjectDir.Delete(recursive: true); | ||
} | ||
|
||
newProjectDir.Create(); | ||
|
||
ProcessStartInfo info = new ProcessStartInfo | ||
{ | ||
WorkingDirectory = newProjectDir.FullName, | ||
FileName = "dotnet", | ||
Arguments = "new console -f net7.0", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true | ||
}; | ||
|
||
Process dotnetNew = Process.Start(info); | ||
Assert.IsNotNull(dotnetNew); | ||
dotnetNew.WaitForExit(); | ||
Assert.AreEqual(0, dotnetNew.ExitCode, dotnetNew.StandardOutput.ReadToEnd()); | ||
|
||
File.WriteAllText(Path.Combine(newProjectDir.FullName, "Program.cs"), $"Console.Write(Environment.GetEnvironmentVariable(\"GoodEnvVar\"));"); | ||
|
||
info.Arguments = "build --configuration release /p:runtimeidentifier=linux-x64"; | ||
|
||
Process dotnetBuildRelease = Process.Start(info); | ||
Assert.IsNotNull(dotnetBuildRelease); | ||
dotnetBuildRelease.WaitForExit(); | ||
dotnetBuildRelease.Kill(); | ||
Assert.AreEqual(0, dotnetBuildRelease.ExitCode); | ||
|
||
ParseContainerProperties pcp = new ParseContainerProperties(); | ||
pcp.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0"; | ||
pcp.ContainerRegistry = ""; | ||
pcp.ContainerImageName = "dotnet/envvarvalidation"; | ||
pcp.ContainerImageTag = "latest"; | ||
|
||
Dictionary<string, string> dict = new Dictionary<string, string>(); | ||
dict.Add("Value", "Foo"); | ||
|
||
pcp.ContainerEnvironmentVariables = new[] { new TaskItem("[email protected]", dict), new TaskItem("GoodEnvVar", dict) }; | ||
|
||
Assert.IsTrue(pcp.Execute()); | ||
Assert.AreEqual("mcr.microsoft.com", pcp.ParsedContainerRegistry); | ||
Assert.AreEqual("dotnet/runtime", pcp.ParsedContainerImage); | ||
Assert.AreEqual("6.0", pcp.ParsedContainerTag); | ||
Assert.AreEqual(1, pcp.NewContainerEnvironmentVariables.Length); | ||
Assert.AreEqual("Foo", pcp.NewContainerEnvironmentVariables[0].GetMetadata("Value")); | ||
|
||
Assert.AreEqual("dotnet/envvarvalidation", pcp.NewContainerImageName); | ||
Assert.AreEqual("latest", pcp.NewContainerTags[0]); | ||
|
||
CreateNewImage cni = new CreateNewImage(); | ||
cni.BaseRegistry = pcp.ParsedContainerRegistry; | ||
cni.BaseImageName = pcp.ParsedContainerImage; | ||
cni.BaseImageTag = pcp.ParsedContainerTag; | ||
cni.ImageName = pcp.NewContainerImageName; | ||
cni.OutputRegistry = pcp.NewContainerRegistry; | ||
cni.PublishDirectory = Path.Combine(newProjectDir.FullName, "bin", "release", "net7.0", "linux-x64"); | ||
cni.WorkingDirectory = "/app"; | ||
cni.Entrypoint = new TaskItem[] { new("/app/Tasks_EndToEnd_With_EnvironmentVariable_Validation") }; | ||
cni.ImageTags = pcp.NewContainerTags; | ||
cni.ContainerEnvironmentVariables = pcp.NewContainerEnvironmentVariables; | ||
|
||
Assert.IsTrue(cni.Execute()); | ||
|
||
ProcessStartInfo runInfo = new("docker", $"run --rm {pcp.NewContainerImageName}:latest") | ||
{ | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
}; | ||
|
||
Process run = Process.Start(runInfo); | ||
Assert.IsNotNull(run); | ||
run.WaitForExit(); | ||
Assert.AreEqual(0, run.ExitCode); | ||
Assert.AreEqual("Foo", run.StandardOutput.ReadToEnd()); | ||
} | ||
} |
Oops, something went wrong.