From e7eb076a39698904027eb1c51e24abd659bb509a Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Thu, 4 Feb 2016 11:35:58 -0800 Subject: [PATCH] Change the deployers to use dotnet --- .../Common/DeploymentParameters.cs | 21 ++--- ...Architecture.cs => RuntimeArchitecture.cs} | 0 .../{DotnetFlavor.cs => RuntimeFlavor.cs} | 3 +- .../Deployers/ApplicationDeployer.cs | 89 ++++--------------- .../Deployers/IISDeployer.cs | 2 +- .../Deployers/IISExpressDeployer.cs | 2 +- .../Deployers/SelfHostDeployer.cs | 26 +++--- 7 files changed, 43 insertions(+), 100 deletions(-) rename src/Microsoft.AspNetCore.Server.Testing/Common/{DotnetArchitecture.cs => RuntimeArchitecture.cs} (100%) rename src/Microsoft.AspNetCore.Server.Testing/Common/{DotnetFlavor.cs => RuntimeFlavor.cs} (90%) diff --git a/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs index 4c7386403f..0e56ed6f14 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs @@ -35,10 +35,14 @@ namespace Microsoft.AspNetCore.Server.Testing throw new DirectoryNotFoundException(string.Format("Application path {0} does not exist.", applicationPath)); } + if (runtimeArchitecture == RuntimeArchitecture.x86) + { + throw new NotSupportedException("32 bit compilation is not yet supported. Don't remove the tests, just disable them for now."); + } + ApplicationPath = applicationPath; ServerType = serverType; RuntimeFlavor = runtimeFlavor; - RuntimeArchitecture = runtimeArchitecture; EnvironmentVariables.Add(new KeyValuePair("ASPNET_DETAILEDERRORS", "true")); } @@ -46,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Testing public RuntimeFlavor RuntimeFlavor { get; } - public RuntimeArchitecture RuntimeArchitecture { get; } + public RuntimeArchitecture RuntimeArchitecture { get; } = RuntimeArchitecture.x64; /// /// Suggested base url for the deployed application. The final deployed url could be @@ -72,11 +76,6 @@ namespace Microsoft.AspNetCore.Server.Testing public string PublishedApplicationRootPath { get; set; } - /// - /// Passes the --no-source option when publishing. - /// - public bool PublishWithNoSource { get; set; } - /// /// Environment variables to be set before starting the host. /// Not applicable for IIS Scenarios. @@ -88,19 +87,15 @@ namespace Microsoft.AspNetCore.Server.Testing /// public Action UserAdditionalCleanup { get; set; } - // Which command in the test project to run. - public string Command { get; set; } - public override string ToString() { return string.Format( - "[Variation] :: ServerType={0}, Runtime={1}, Arch={2}, BaseUrlHint={3}, Publish={4}, NoSource={5}", + "[Variation] :: ServerType={0}, Runtime={1}, Arch={2}, BaseUrlHint={3}, Publish={4}", ServerType, RuntimeFlavor, RuntimeArchitecture, ApplicationBaseUriHint, - PublishApplicationBeforeDeployment, - PublishWithNoSource); + PublishApplicationBeforeDeployment); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Testing/Common/DotnetArchitecture.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/RuntimeArchitecture.cs similarity index 100% rename from src/Microsoft.AspNetCore.Server.Testing/Common/DotnetArchitecture.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/RuntimeArchitecture.cs diff --git a/src/Microsoft.AspNetCore.Server.Testing/Common/DotnetFlavor.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/RuntimeFlavor.cs similarity index 90% rename from src/Microsoft.AspNetCore.Server.Testing/Common/DotnetFlavor.cs rename to src/Microsoft.AspNetCore.Server.Testing/Common/RuntimeFlavor.cs index dec116a81a..f99e08665f 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Common/DotnetFlavor.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Common/RuntimeFlavor.cs @@ -6,7 +6,6 @@ namespace Microsoft.AspNetCore.Server.Testing public enum RuntimeFlavor { Clr, - CoreClr, - Mono + CoreClr } } diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs index 82f6f6fa00..30cbf5aea1 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs @@ -17,95 +17,48 @@ namespace Microsoft.AspNetCore.Server.Testing /// public abstract class ApplicationDeployer : IApplicationDeployer { + public static readonly string DotnetCommandName = "dotnet"; + + // This is the argument that separates the dotnet arguments for the args being passed to the + // app being run when running dotnet run + public static readonly string DotnetArgumentSeparator = "--"; + private readonly Stopwatch _stopwatch = new Stopwatch(); public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger) { DeploymentParameters = deploymentParameters; Logger = logger; - DnuCommandName = TestPlatformHelper.IsWindows ? "dnu.cmd" : "dnu"; - DnxCommandName = TestPlatformHelper.IsWindows ? "dnx.exe" : "dnx"; } protected DeploymentParameters DeploymentParameters { get; } protected ILogger Logger { get; } - protected string DnuCommandName { get; } - - protected string DnxCommandName { get; } - - protected string TargetRuntimeName { get; private set; } - - protected string TargetRuntimeBinPath { get; private set; } - - protected string ToolingRuntimeBinPath { get; private set; } + protected string TargetFrameworkName { get; private set; } public abstract DeploymentResult Deploy(); protected void PickRuntime() { - var currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath; - Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}"); + TargetFrameworkName = DeploymentParameters.RuntimeFlavor == RuntimeFlavor.Clr ? "dnx451" : "dnxcore50"; - var currentRuntimeFullName = new DirectoryInfo(currentRuntimeBinPath).Parent.Name; - var currentRuntimeVersionParts = currentRuntimeFullName.Split(new char[] { '.' }, 2); - if (currentRuntimeVersionParts.Length < 2) - { - throw new ArgumentNullException($"The current runtime bin path points to a runtime name doesn't indicate a version: {currentRuntimeBinPath}."); - } - var currentRuntimeVersion = currentRuntimeVersionParts[1]; - - var runtimeHome = new DirectoryInfo(currentRuntimeBinPath).Parent.Parent.FullName; - Logger.LogInformation($"Runtime home folder: {runtimeHome}"); - - if (DeploymentParameters.RuntimeFlavor == RuntimeFlavor.Mono) - { - // TODO: review on mono - TargetRuntimeName = $"dnx-mono.{currentRuntimeVersion}"; - TargetRuntimeBinPath = Path.Combine(runtimeHome, TargetRuntimeName, "bin"); - ToolingRuntimeBinPath = TargetRuntimeBinPath; - } - else - { - var flavor = DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr ? "coreclr" : "clr"; - var architecture = DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86 ? "x86" : "x64"; - - // tooling runtime will stick to coreclr so as to prevent long path issue during publishing - ToolingRuntimeBinPath = Path.Combine(runtimeHome, $"dnx-coreclr-{GetOSPrefix()}-{architecture}.{currentRuntimeVersion}", "bin"); - - TargetRuntimeName = $"dnx-{flavor}-{GetOSPrefix()}-{architecture}.{currentRuntimeVersion}"; - TargetRuntimeBinPath = Path.Combine(runtimeHome, TargetRuntimeName, "bin"); - } - - if (!Directory.Exists(ToolingRuntimeBinPath) || !Directory.Exists(TargetRuntimeBinPath)) - { - throw new Exception($"Requested runtime '{ToolingRuntimeBinPath}' or '{TargetRuntimeBinPath}; does not exist. Please make sure it is installed before running test."); - } - - Logger.LogInformation($"Pick target runtime {TargetRuntimeBinPath}"); - Logger.LogInformation($"Pick tooling runtime {ToolingRuntimeBinPath}"); - - // Work around win7 search path issues. - var newPath = TargetRuntimeBinPath + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH"); - DeploymentParameters.EnvironmentVariables.Add(new KeyValuePair("PATH", newPath)); + Logger.LogInformation($"Pick target framework {TargetFrameworkName}"); } - protected void DnuPublish(string publishRoot = null) + protected void DotnetPublish(string publishRoot = null) { DeploymentParameters.PublishedApplicationRootPath = publishRoot ?? Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty; - var command = DeploymentParameters.Command ?? "web"; - var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}" - + $" --runtime {TargetRuntimeName} {noSource} --iis-command {command}"; + var parameters = $"publish {DeploymentParameters.ApplicationPath}" + + $" -o {DeploymentParameters.PublishedApplicationRootPath}" + + $" --framework {TargetFrameworkName}"; - var dnuPath = Path.Combine(ToolingRuntimeBinPath, DnuCommandName); - Logger.LogInformation($"Executing command {dnuPath} {parameters}"); + Logger.LogInformation($"Executing command {DotnetCommandName} {parameters}"); var startInfo = new ProcessStartInfo { - FileName = dnuPath, + FileName = DotnetCommandName, Arguments = parameters, UseShellExecute = false, CreateNoWindow = true, @@ -130,9 +83,9 @@ namespace Microsoft.AspNetCore.Server.Testing (DeploymentParameters.ServerType == ServerType.IISExpress || DeploymentParameters.ServerType == ServerType.IIS) ? Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") : - Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "approot", "src", new DirectoryInfo(DeploymentParameters.ApplicationPath).Name); + DeploymentParameters.ApplicationPath; - Logger.LogInformation($"dnu publish finished with exit code : {hostProcess.ExitCode}"); + Logger.LogInformation($"{DotnetCommandName} publish finished with exit code : {hostProcess.ExitCode}"); } protected void CleanPublishedOutput() @@ -181,14 +134,6 @@ namespace Microsoft.AspNetCore.Server.Testing SetEnvironmentVariable(environment, "ASPNET_ENV", DeploymentParameters.EnvironmentName); - // Work around for https://github.com/aspnet/dnx/issues/1515 - if (DeploymentParameters.PublishWithNoSource) - { - SetEnvironmentVariable(environment, "DNX_PACKAGES", null); - } - - SetEnvironmentVariable(environment, "DNX_DEFAULT_LIB", null); - foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables) { SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value); diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs index ca1c498625..2e86cd8995 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISDeployer.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Testing PickRuntime(); // Publish to IIS root\application folder. - DnuPublish(publishRoot: _application.WebSiteRootFolder); + DotnetPublish(publishRoot: _application.WebSiteRootFolder); // Drop a json file instead of setting environment variable. SetAspEnvironmentWithJson(); diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs index 9cce8c8120..525f1c3a5c 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/IISExpressDeployer.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Testing DeploymentParameters.PublishApplicationBeforeDeployment = true; if (DeploymentParameters.PublishApplicationBeforeDeployment) { - DnuPublish(); + DotnetPublish(); } var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint); diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs index 2ae3f8e679..a803f09b65 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Testing if (DeploymentParameters.PublishApplicationBeforeDeployment) { - DnuPublish(); + DotnetPublish(); } var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint); @@ -49,23 +49,27 @@ namespace Microsoft.AspNetCore.Server.Testing private CancellationToken StartSelfHost(Uri uri) { - var commandName = DeploymentParameters.Command; - if (string.IsNullOrEmpty(commandName)) + string executableName; + string executableArgs = string.Empty; + if (DeploymentParameters.PublishApplicationBeforeDeployment) { - commandName = "run"; + executableName = Path.Combine(DeploymentParameters.PublishedApplicationRootPath, new DirectoryInfo(DeploymentParameters.ApplicationPath).Name + ".exe"); + } + else + { + executableName = DotnetCommandName; + executableArgs = $"run -p \"{DeploymentParameters.ApplicationPath}\" {DotnetArgumentSeparator}"; } - var dnxPath = Path.Combine(TargetRuntimeBinPath, DnxCommandName); - var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} " + - $"--server.urls {uri} " + - $"--server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNetCore.Server.WebListener" : "Microsoft.AspNetCore.Server.Kestrel")}"; + executableArgs += $" --server.urls {uri} " + + $" --server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNetCore.Server.WebListener" : "Microsoft.AspNetCore.Server.Kestrel")}"; - Logger.LogInformation($"Executing {dnxPath} {dnxArgs}"); + Logger.LogInformation($"Executing {DotnetCommandName} {executableArgs}"); var startInfo = new ProcessStartInfo { - FileName = dnxPath, - Arguments = dnxArgs, + FileName = executableName, + Arguments = executableArgs, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true,