Fix deployers
This commit is contained in:
parent
2a951aaeaa
commit
79a8a4e799
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"projects": ["src"]
|
"projects": ["src","c:/github/testing/src","/home/kiran/github/testing/src"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Testing
|
namespace Microsoft.AspNet.Server.Testing
|
||||||
|
|
@ -16,8 +18,14 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ApplicationDeployer : IApplicationDeployer
|
public abstract class ApplicationDeployer : IApplicationDeployer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Example: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin
|
||||||
|
/// </summary>
|
||||||
protected string ChosenRuntimePath { get; set; }
|
protected string ChosenRuntimePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Examples: dnx-coreclr-win-x64.1.0.0-rc1-15844, dnx-mono.1.0.0-rc1-15844
|
||||||
|
/// </summary>
|
||||||
protected string ChosenRuntimeName { get; set; }
|
protected string ChosenRuntimeName { get; set; }
|
||||||
|
|
||||||
protected DeploymentParameters DeploymentParameters { get; private set; }
|
protected DeploymentParameters DeploymentParameters { get; private set; }
|
||||||
|
|
@ -26,6 +34,59 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
|
|
||||||
protected Stopwatch StopWatch { get; private set; } = new Stopwatch();
|
protected Stopwatch StopWatch { get; private set; } = new Stopwatch();
|
||||||
|
|
||||||
|
protected string OSPrefix
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (TestPlatformHelper.IsLinux)
|
||||||
|
{
|
||||||
|
return "linux";
|
||||||
|
}
|
||||||
|
else if (TestPlatformHelper.IsMac)
|
||||||
|
{
|
||||||
|
return "darwin";
|
||||||
|
}
|
||||||
|
else if (TestPlatformHelper.IsWindows)
|
||||||
|
{
|
||||||
|
return "win";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unrecognized operating system");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string DnuCommandName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (TestPlatformHelper.IsWindows)
|
||||||
|
{
|
||||||
|
return "dnu.cmd";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "dnu";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string DnxCommandName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (TestPlatformHelper.IsWindows)
|
||||||
|
{
|
||||||
|
return "dnx.exe";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "dnx";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract DeploymentResult Deploy();
|
public abstract DeploymentResult Deploy();
|
||||||
|
|
||||||
public ApplicationDeployer(
|
public ApplicationDeployer(
|
||||||
|
|
@ -38,31 +99,44 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
|
|
||||||
protected string PopulateChosenRuntimeInformation()
|
protected string PopulateChosenRuntimeInformation()
|
||||||
{
|
{
|
||||||
var runtimePath = Process.GetCurrentProcess().MainModule.FileName;
|
// ex: runtimes/dnx-coreclr-win-x64.1.0.0-rc1-15844/bin
|
||||||
Logger.LogInformation(string.Empty);
|
var currentRuntimeBinPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
|
||||||
Logger.LogInformation($"Current runtime path is : {runtimePath}");
|
Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}");
|
||||||
|
|
||||||
var replaceStr = new StringBuilder().
|
var targetRuntimeName = new StringBuilder()
|
||||||
Append("dnx").
|
.Append("dnx")
|
||||||
Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr").
|
.Append((DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr) ? "-coreclr" : "-clr")
|
||||||
Append("-win").
|
.Append($"-{OSPrefix}")
|
||||||
Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64").
|
.Append((DeploymentParameters.RuntimeArchitecture == RuntimeArchitecture.x86) ? "-x86" : "-x64")
|
||||||
ToString();
|
.ToString();
|
||||||
|
|
||||||
runtimePath = Regex.Replace(runtimePath, "dnx-(clr|coreclr)-win-(x86|x64)", replaceStr, RegexOptions.IgnoreCase);
|
string targetRuntimeBinPath;
|
||||||
ChosenRuntimePath = Path.GetDirectoryName(runtimePath);
|
// Ex: When current runtime is Mono and the tests are being run for CoreClr
|
||||||
|
if (currentRuntimeBinPath.Contains("dnx-mono"))
|
||||||
var runtimeDirectoryInfo = new DirectoryInfo(ChosenRuntimePath);
|
|
||||||
if (!runtimeDirectoryInfo.Exists)
|
|
||||||
{
|
{
|
||||||
throw new Exception(
|
targetRuntimeBinPath = currentRuntimeBinPath.Replace("dnx-mono", targetRuntimeName);
|
||||||
string.Format("Requested runtime at location '{0}' does not exist. Please make sure it is installed before running test.",
|
}
|
||||||
runtimeDirectoryInfo.FullName));
|
else
|
||||||
|
{
|
||||||
|
targetRuntimeBinPath = Regex.Replace(
|
||||||
|
currentRuntimeBinPath,
|
||||||
|
"dnx-(clr|coreclr)-(win|linux|darwin)-(x86|x64)",
|
||||||
|
targetRuntimeName,
|
||||||
|
RegexOptions.IgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChosenRuntimeName = runtimeDirectoryInfo.Parent.Name;
|
var targetRuntimeBinDir = new DirectoryInfo(targetRuntimeBinPath);
|
||||||
Logger.LogInformation(string.Empty);
|
if (targetRuntimeBinDir == null || !targetRuntimeBinDir.Exists)
|
||||||
Logger.LogInformation($"Changing to use runtime : {ChosenRuntimeName}");
|
{
|
||||||
|
throw new Exception($"Requested runtime at location '{targetRuntimeBinPath}' does not exist.Please make sure it is installed before running test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ChosenRuntimePath = targetRuntimeBinDir.FullName;
|
||||||
|
ChosenRuntimeName = targetRuntimeBinDir.Parent.Name;
|
||||||
|
DeploymentParameters.DnxRuntime = ChosenRuntimeName;
|
||||||
|
|
||||||
|
Logger.LogInformation($"Chosen runtime path is {ChosenRuntimePath}");
|
||||||
|
|
||||||
return ChosenRuntimeName;
|
return ChosenRuntimeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +149,7 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}"
|
var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}"
|
||||||
+ $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}";
|
+ $" --runtime {DeploymentParameters.DnxRuntime} {noSource} --iis-command {command}";
|
||||||
|
|
||||||
var dnuPath = Path.Combine(ChosenRuntimePath, "dnu.cmd");
|
var dnuPath = Path.Combine(ChosenRuntimePath, DnuCommandName);
|
||||||
Logger.LogInformation($"Executing command {dnuPath} {parameters}");
|
Logger.LogInformation($"Executing command {dnuPath} {parameters}");
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -36,13 +37,20 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
throw new Exception("Runtime not detected on the machine.");
|
throw new Exception("Runtime not detected on the machine.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var runtimeBinDir = new DirectoryInfo(runtimeBin);
|
||||||
|
ChosenRuntimePath = runtimeBinDir.FullName;
|
||||||
|
ChosenRuntimeName = runtimeBinDir.Parent.Name;
|
||||||
|
DeploymentParameters.DnxRuntime = ChosenRuntimeName;
|
||||||
|
|
||||||
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
||||||
{
|
{
|
||||||
// We use full path to runtime to pack.
|
// We use full path to runtime to pack.
|
||||||
DeploymentParameters.DnxRuntime = new DirectoryInfo(runtimeBin).Parent.FullName;
|
|
||||||
DnuPublish();
|
DnuPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeploymentParameters.EnvironmentVariables
|
||||||
|
.Add(new KeyValuePair<string, string>("DNX_APPBASE", DeploymentParameters.ApplicationPath));
|
||||||
|
|
||||||
// Launch the host process.
|
// Launch the host process.
|
||||||
var hostExitToken = StartMonoHost();
|
var hostExitToken = StartMonoHost();
|
||||||
|
|
||||||
|
|
@ -62,29 +70,36 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
throw new InvalidOperationException("kestrel is the only valid ServerType for Mono");
|
throw new InvalidOperationException("kestrel is the only valid ServerType for Mono");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName);
|
||||||
var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}";
|
var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" kestrel --server.urls {DeploymentParameters.ApplicationBaseUriHint}";
|
||||||
|
Logger.LogInformation($"Executing command {dnxPath} {dnxArgs}");
|
||||||
Logger.LogInformation("Executing command: dnx {dnxArgs}", dnxArgs);
|
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "dnx",
|
FileName = dnxPath,
|
||||||
Arguments = dnxArgs,
|
Arguments = dnxArgs,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
// Trying a work around for https://github.com/aspnet/Hosting/issues/140.
|
||||||
RedirectStandardInput = true
|
RedirectStandardInput = true
|
||||||
};
|
};
|
||||||
|
|
||||||
_hostProcess = Process.Start(startInfo);
|
AddEnvironmentVariablesToProcess(startInfo);
|
||||||
|
|
||||||
|
_hostProcess = new Process() { StartInfo = startInfo };
|
||||||
|
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data ?? string.Empty); };
|
||||||
|
_hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data ?? string.Empty); };
|
||||||
_hostProcess.EnableRaisingEvents = true;
|
_hostProcess.EnableRaisingEvents = true;
|
||||||
var hostExitTokenSource = new CancellationTokenSource();
|
var hostExitTokenSource = new CancellationTokenSource();
|
||||||
_hostProcess.Exited += (sender, e) =>
|
_hostProcess.Exited += (sender, e) =>
|
||||||
{
|
{
|
||||||
Logger.LogError("Host process {processName} exited with code {exitCode}.", startInfo.FileName, _hostProcess.ExitCode);
|
|
||||||
TriggerHostShutdown(hostExitTokenSource);
|
TriggerHostShutdown(hostExitTokenSource);
|
||||||
};
|
};
|
||||||
|
_hostProcess.Start();
|
||||||
Logger.LogInformation("Started {0}. Process Id : {1}", _hostProcess.MainModule.FileName, _hostProcess.Id);
|
_hostProcess.BeginErrorReadLine();
|
||||||
|
_hostProcess.BeginOutputReadLine();
|
||||||
|
|
||||||
if (_hostProcess.HasExited)
|
if (_hostProcess.HasExited)
|
||||||
{
|
{
|
||||||
|
|
@ -92,6 +107,7 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
throw new Exception("Failed to start host");
|
throw new Exception("Failed to start host");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("Started {fileName}. Process Id : {processId}", startInfo.FileName, _hostProcess.Id);
|
||||||
return hostExitTokenSource.Token;
|
return hostExitTokenSource.Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Testing
|
namespace Microsoft.AspNet.Server.Testing
|
||||||
|
|
@ -50,11 +51,11 @@ namespace Microsoft.AspNet.Server.Testing
|
||||||
var commandName = DeploymentParameters.Command;
|
var commandName = DeploymentParameters.Command;
|
||||||
if (string.IsNullOrEmpty(commandName))
|
if (string.IsNullOrEmpty(commandName))
|
||||||
{
|
{
|
||||||
commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "web" : "kestrel";
|
commandName = DeploymentParameters.ServerType == ServerType.WebListener ? "weblistener" : "kestrel";
|
||||||
}
|
}
|
||||||
var dnxPath = Path.Combine(ChosenRuntimePath, "dnx.exe");
|
var dnxPath = Path.Combine(ChosenRuntimePath, DnxCommandName);
|
||||||
var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}";
|
var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} --server.urls {DeploymentParameters.ApplicationBaseUriHint}";
|
||||||
Logger.LogInformation("Executing {dnxexe} {dnxArgs}", dnxPath, dnxArgs);
|
Logger.LogInformation($"Executing {dnxPath} {dnxArgs}");
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,8 @@ namespace Microsoft.AspNet.Hosting
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
[InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")]
|
[InlineData(@"sub/sub2\sub3\", @"sub/sub2/sub3/")]
|
||||||
public void MapPath_Windows_Facts(string virtualPath, string expectedSuffix)
|
public void MapPath_Windows_Facts(string virtualPath, string expectedSuffix)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue