public void ContainerLimits(RuntimeImageDescriptor imageDescriptor) { // Container limits are only supported on 4.8 for Server 2019 and 2022. if (imageDescriptor.Version != "4.8" || (imageDescriptor.OsVariant != OsVersion.WSC_LTSC2019 && imageDescriptor.OsVariant != OsVersion.WSC_LTSC2022)) { _imageTestHelper.OutputHelper.WriteLine("Test skipped due to unsupported version."); return; } string appId = $"container-limits-{DateTime.Now.ToFileTime()}"; string workDir = Path.Combine( Directory.GetCurrentDirectory(), "projects", $"dotnetapp-{imageDescriptor.Version}"); string baseBuildImage = _imageTestHelper.GetImage("sdk", imageDescriptor.SdkVersion, imageDescriptor.OsVariant); string baseRuntimeImage = _imageTestHelper.GetImage("runtime", imageDescriptor.Version, imageDescriptor.OsVariant); List <string> appBuildArgs = new () { $"BASE_BUILD_IMAGE={baseBuildImage}", $"BASE_RUNTIME_IMAGE={baseRuntimeImage}" }; string runCommand = "getProcessorCount"; try { _imageTestHelper.DockerHelper.Build( tag: appId, dockerfile: Path.Combine(workDir, "Dockerfile"), contextDir: workDir, buildArgs: appBuildArgs.ToArray()); string output = _imageTestHelper.DockerHelper.Run(image: appId, name: appId, command: runCommand, optionalRunArgs: "--cpus 0.5"); Assert.Equal("1", output); string processorCount = "20"; output = _imageTestHelper.DockerHelper.Run(image: appId, name: appId, command: runCommand, optionalRunArgs: $"--cpus 0.5 -e COMPLUS_PROCESSOR_COUNT={processorCount}"); Assert.Equal(processorCount, output); } finally { _imageTestHelper.DockerHelper.DeleteContainer(appId); _imageTestHelper.DockerHelper.DeleteImage(appId); } }
public static void Validate( IEnumerable <EnvironmentVariableInfo> variables, string imageType, ImageDescriptor imageDescriptor, ImageTestHelper imageTestHelper) { const char delimiter = '|'; IEnumerable <string> echoParts; string invokeCommand; char delimiterEscape; if (DockerHelper.IsLinuxContainerModeEnabled) { echoParts = variables.Select(envVar => $"${envVar.Name}"); invokeCommand = $"/bin/sh -c"; delimiterEscape = '\\'; } else { echoParts = variables.Select(envVar => $"%{envVar.Name}%"); invokeCommand = $"CMD /S /C"; delimiterEscape = '^'; } string appId = $"envvar-{DateTime.Now.ToFileTime()}"; string combinedValues = imageTestHelper.DockerHelper.Run( image: imageTestHelper.GetImage(imageType, imageDescriptor.Version, imageDescriptor.OsVariant), name: appId, command: $"{invokeCommand} \"echo {String.Join($"{delimiterEscape}{delimiter}", echoParts)}\""); string[] values = combinedValues.Split(delimiter); Assert.Equal(variables.Count(), values.Count()); for (int i = 0; i < values.Count(); i++) { EnvironmentVariableInfo variable = variables.ElementAt(i); string actualValue; // Process unset variables in Windows if (!DockerHelper.IsLinuxContainerModeEnabled && string.Equals(values[i], $"%{variable.Name}%", StringComparison.Ordinal)) { actualValue = string.Empty; } else { actualValue = values[i]; } if (variable.AllowAnyValue) { Assert.NotEmpty(actualValue); } else { Assert.Equal(variable.ExpectedValue, actualValue); } } }
public void VerifyTargetingPacks(ImageDescriptor imageDescriptor) { Version[] allFrameworkVersions = new Version[] { new Version("4.0"), new Version("4.5"), new Version("4.5.1"), new Version("4.5.2"), new Version("4.6"), new Version("4.6.1"), new Version("4.6.2"), new Version("4.7"), new Version("4.7.1"), new Version("4.7.2"), new Version("4.8") }; string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"targetingpacks-{DateTime.Now.ToFileTime()}"; string command = @"cmd /c dir /B ""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework"""; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); IEnumerable<Version> actualVersions = output.Split(Environment.NewLine) .Select(name => new Version(name.Substring(1))); // Trim the first character (v4.0 => 4.0) Version buildVersion = new Version(imageDescriptor.Version); IEnumerable<Version> expectedVersions = allFrameworkVersions; if (imageDescriptor.Version != "3.5") { expectedVersions = allFrameworkVersions.Where(version => version <= buildVersion); } Assert.Equal(expectedVersions, actualVersions); }
public void VerifyGacUtil(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"gacutil-{DateTime.Now.ToFileTime()}"; string command = "gacutil"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); Assert.StartsWith("Microsoft (R) .NET Global Assembly Cache Utility", output); }
public void VerifyVsTest(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"vstest-{DateTime.Now.ToFileTime()}"; string command = "vstest.console.exe /?"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); Assert.StartsWith("Microsoft (R) Test Execution Command Line Tool", output); }
public void VerifyNuGetCli(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"nuget-{DateTime.Now.ToFileTime()}"; string command = "nuget help"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); Assert.StartsWith("NuGet Version:", output); }
public void VerifyDotNetCli(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"dotnetcli-{DateTime.Now.ToFileTime()}"; string command = "dotnet --version"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); // Just verify the output is parseable to a Version object (it will throw if it's not) Version.Parse(output); }
public void VerifyWebDeploy(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"webdeploy-{DateTime.Now.ToFileTime()}"; // Calling msdeploy's help command results in a -1 exit code. To prevent that from bubbling up and causing the // docker run call to fail, the call is batched with an echo command that will always run even if msdeploy // returns a non-zero exit code. This batch needs to be wrapped in space-separated quotes to work properly. string command = @"cmd /S /C "" ""C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"" -help & echo > nul """; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); Assert.StartsWith("Microsoft (R) Web Deployment Command Line Tool (MSDeploy.exe)", output); }
private void VerifyFxImages(RuntimeImageDescriptor imageDescriptor, string appDescriptor, string runCommand, bool includeRuntime) { string baseBuildImage = _imageTestHelper.GetImage("sdk", imageDescriptor.SdkVersion, imageDescriptor.OsVariant); List <string> appBuildArgs = new List <string> { $"BASE_BUILD_IMAGE={baseBuildImage}" }; if (includeRuntime) { string baseRuntimeImage = _imageTestHelper.GetImage("runtime", imageDescriptor.Version, imageDescriptor.OsVariant); appBuildArgs.Add($"BASE_RUNTIME_IMAGE={baseRuntimeImage}"); } _imageTestHelper.BuildAndTestImage( imageDescriptor: imageDescriptor, buildArgs: appBuildArgs, appDescriptor: appDescriptor, runCommand: runCommand, testUrl: "" ); }
public void VerifyImagesWithApps(ImageDescriptor imageDescriptor) { List<string> appBuildArgs = new List<string> { }; string baseWCFImage = imageTestHelper.GetImage("wcf", imageDescriptor.Version, imageDescriptor.OsVariant); appBuildArgs.Add($"BASE_WCF_IMAGE={baseWCFImage}"); imageTestHelper.BuildAndTestImage( imageDescriptor: imageDescriptor, buildArgs: appBuildArgs, appDescriptor: "wcf", runCommand: "", testUrl: "/Service1.svc" ); }
public void VerifyImagesWithApps(ImageDescriptor imageDescriptor) { List <string> appBuildArgs = new List <string> { }; string baseAspnetImage = ImageTestHelper.GetImage("aspnet", imageDescriptor.Version, imageDescriptor.OsVariant); appBuildArgs.Add($"BASE_ASPNET_IMAGE={baseAspnetImage}"); ImageTestHelper.BuildAndTestImage( imageDescriptor: imageDescriptor, buildArgs: appBuildArgs, appDescriptor: "aspnet", runCommand: "", testUrl: "/hello-world.aspx" ); }
public void VerifyClickOncePublishing(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); List <string> buildArgs = new List <string> { $"BASE_BUILD_IMAGE={baseBuildImage}", }; string command = $"cmd /s /c dir /b publish"; string output = ImageTestHelper.BuildAndTestImage(imageDescriptor, buildArgs, "clickonce", command, null); string[] outputLines = output.Split(Environment.NewLine); Assert.Equal(4, outputLines.Length); Assert.Equal("Application Files", outputLines[0]); Assert.Equal($"clickonce-{imageDescriptor.Version}.application", outputLines[1]); Assert.Equal($"clickonce-{imageDescriptor.Version}.exe", outputLines[2]); Assert.Equal($"setup.exe", outputLines[3]); }
public void VerifyVsWhereOperability(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"vswhere-{DateTime.Now.ToFileTime()}"; const string command = @"cmd /c ""C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"" -products * -latest -format json"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); JArray json = (JArray)JsonConvert.DeserializeObject(output); Assert.Single(json); Assert.Equal(@"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools", json[0]["installationPath"]); Version actualVsVersion = Version.Parse(json[0]["catalog"]["productDisplayVersion"].ToString()); Version expectedVsVersion = Config.GetManifestVsVersion(); Assert.Equal(expectedVsVersion.Major, actualVsVersion.Major); Assert.Equal(expectedVsVersion.Minor, actualVsVersion.Minor); }
public void VerifyVsWhereOperability(ImageDescriptor imageDescriptor) { string baseBuildImage = ImageTestHelper.GetImage("sdk", imageDescriptor.Version, imageDescriptor.OsVariant); string appId = $"vswhere-{DateTime.Now.ToFileTime()}"; const string securityProtocolCmd = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12"; const string vsWhereUrl = "https://github.com/Microsoft/vswhere/releases/download/2.8.4/vswhere.exe"; string downloadVsWhereCmd = $"Invoke-WebRequest -UseBasicParsing {vsWhereUrl} -OutFile vswhere.exe"; const string executeVsWhereCmd = @".\vswhere.exe -products * -latest -format json"; string command = $@"powershell {securityProtocolCmd}; {downloadVsWhereCmd}; {executeVsWhereCmd}"; string output = ImageTestHelper.DockerHelper.Run(image: baseBuildImage, name: appId, command: command); JArray json = (JArray)JsonConvert.DeserializeObject(output); Assert.Single(json); Assert.Equal(@"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools", json[0]["installationPath"]); Version actualVsVersion = Version.Parse(json[0]["catalog"]["productDisplayVersion"].ToString()); VsInfo vsInfo = Config.GetVsInfo(); Version expectedVsVersion = Version.Parse(vsInfo.VsVersion); Assert.Equal(expectedVsVersion.Major, actualVsVersion.Major); Assert.Equal(expectedVsVersion.Minor, actualVsVersion.Minor); }