Change the deployers to use dotnet
This commit is contained in:
parent
41baf6feed
commit
e7eb076a39
|
|
@ -35,10 +35,14 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
throw new DirectoryNotFoundException(string.Format("Application path {0} does not exist.", applicationPath));
|
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;
|
ApplicationPath = applicationPath;
|
||||||
ServerType = serverType;
|
ServerType = serverType;
|
||||||
RuntimeFlavor = runtimeFlavor;
|
RuntimeFlavor = runtimeFlavor;
|
||||||
RuntimeArchitecture = runtimeArchitecture;
|
|
||||||
EnvironmentVariables.Add(new KeyValuePair<string, string>("ASPNET_DETAILEDERRORS", "true"));
|
EnvironmentVariables.Add(new KeyValuePair<string, string>("ASPNET_DETAILEDERRORS", "true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
|
|
||||||
public RuntimeFlavor RuntimeFlavor { get; }
|
public RuntimeFlavor RuntimeFlavor { get; }
|
||||||
|
|
||||||
public RuntimeArchitecture RuntimeArchitecture { get; }
|
public RuntimeArchitecture RuntimeArchitecture { get; } = RuntimeArchitecture.x64;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Suggested base url for the deployed application. The final deployed url could be
|
/// 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; }
|
public string PublishedApplicationRootPath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Passes the --no-source option when publishing.
|
|
||||||
/// </summary>
|
|
||||||
public bool PublishWithNoSource { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Environment variables to be set before starting the host.
|
/// Environment variables to be set before starting the host.
|
||||||
/// Not applicable for IIS Scenarios.
|
/// Not applicable for IIS Scenarios.
|
||||||
|
|
@ -88,19 +87,15 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<DeploymentParameters> UserAdditionalCleanup { get; set; }
|
public Action<DeploymentParameters> UserAdditionalCleanup { get; set; }
|
||||||
|
|
||||||
// Which command in the test project to run.
|
|
||||||
public string Command { get; set; }
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format(
|
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,
|
ServerType,
|
||||||
RuntimeFlavor,
|
RuntimeFlavor,
|
||||||
RuntimeArchitecture,
|
RuntimeArchitecture,
|
||||||
ApplicationBaseUriHint,
|
ApplicationBaseUriHint,
|
||||||
PublishApplicationBeforeDeployment,
|
PublishApplicationBeforeDeployment);
|
||||||
PublishWithNoSource);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,6 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
public enum RuntimeFlavor
|
public enum RuntimeFlavor
|
||||||
{
|
{
|
||||||
Clr,
|
Clr,
|
||||||
CoreClr,
|
CoreClr
|
||||||
Mono
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,95 +17,48 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ApplicationDeployer : IApplicationDeployer
|
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();
|
private readonly Stopwatch _stopwatch = new Stopwatch();
|
||||||
|
|
||||||
public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger)
|
public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger)
|
||||||
{
|
{
|
||||||
DeploymentParameters = deploymentParameters;
|
DeploymentParameters = deploymentParameters;
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
DnuCommandName = TestPlatformHelper.IsWindows ? "dnu.cmd" : "dnu";
|
|
||||||
DnxCommandName = TestPlatformHelper.IsWindows ? "dnx.exe" : "dnx";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DeploymentParameters DeploymentParameters { get; }
|
protected DeploymentParameters DeploymentParameters { get; }
|
||||||
|
|
||||||
protected ILogger Logger { get; }
|
protected ILogger Logger { get; }
|
||||||
|
|
||||||
protected string DnuCommandName { get; }
|
protected string TargetFrameworkName { get; private set; }
|
||||||
|
|
||||||
protected string DnxCommandName { get; }
|
|
||||||
|
|
||||||
protected string TargetRuntimeName { get; private set; }
|
|
||||||
|
|
||||||
protected string TargetRuntimeBinPath { get; private set; }
|
|
||||||
|
|
||||||
protected string ToolingRuntimeBinPath { get; private set; }
|
|
||||||
|
|
||||||
public abstract DeploymentResult Deploy();
|
public abstract DeploymentResult Deploy();
|
||||||
|
|
||||||
protected void PickRuntime()
|
protected void PickRuntime()
|
||||||
{
|
{
|
||||||
var currentRuntimeBinPath = PlatformServices.Default.Runtime.RuntimePath;
|
TargetFrameworkName = DeploymentParameters.RuntimeFlavor == RuntimeFlavor.Clr ? "dnx451" : "dnxcore50";
|
||||||
Logger.LogInformation($"Current runtime path is : {currentRuntimeBinPath}");
|
|
||||||
|
|
||||||
var currentRuntimeFullName = new DirectoryInfo(currentRuntimeBinPath).Parent.Name;
|
Logger.LogInformation($"Pick target framework {TargetFrameworkName}");
|
||||||
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<string, string>("PATH", newPath));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DnuPublish(string publishRoot = null)
|
protected void DotnetPublish(string publishRoot = null)
|
||||||
{
|
{
|
||||||
DeploymentParameters.PublishedApplicationRootPath = publishRoot ?? Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
DeploymentParameters.PublishedApplicationRootPath = publishRoot ?? Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||||
|
|
||||||
var noSource = DeploymentParameters.PublishWithNoSource ? "--no-source" : string.Empty;
|
var parameters = $"publish {DeploymentParameters.ApplicationPath}"
|
||||||
var command = DeploymentParameters.Command ?? "web";
|
+ $" -o {DeploymentParameters.PublishedApplicationRootPath}"
|
||||||
var parameters = $"publish {DeploymentParameters.ApplicationPath} -o {DeploymentParameters.PublishedApplicationRootPath}"
|
+ $" --framework {TargetFrameworkName}";
|
||||||
+ $" --runtime {TargetRuntimeName} {noSource} --iis-command {command}";
|
|
||||||
|
|
||||||
var dnuPath = Path.Combine(ToolingRuntimeBinPath, DnuCommandName);
|
Logger.LogInformation($"Executing command {DotnetCommandName} {parameters}");
|
||||||
Logger.LogInformation($"Executing command {dnuPath} {parameters}");
|
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = dnuPath,
|
FileName = DotnetCommandName,
|
||||||
Arguments = parameters,
|
Arguments = parameters,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
|
|
@ -130,9 +83,9 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
(DeploymentParameters.ServerType == ServerType.IISExpress ||
|
(DeploymentParameters.ServerType == ServerType.IISExpress ||
|
||||||
DeploymentParameters.ServerType == ServerType.IIS) ?
|
DeploymentParameters.ServerType == ServerType.IIS) ?
|
||||||
Path.Combine(DeploymentParameters.PublishedApplicationRootPath, "wwwroot") :
|
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()
|
protected void CleanPublishedOutput()
|
||||||
|
|
@ -181,14 +134,6 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
|
|
||||||
SetEnvironmentVariable(environment, "ASPNET_ENV", DeploymentParameters.EnvironmentName);
|
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)
|
foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables)
|
||||||
{
|
{
|
||||||
SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value);
|
SetEnvironmentVariable(environment, environmentVariable.Key, environmentVariable.Value);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
PickRuntime();
|
PickRuntime();
|
||||||
|
|
||||||
// Publish to IIS root\application folder.
|
// Publish to IIS root\application folder.
|
||||||
DnuPublish(publishRoot: _application.WebSiteRootFolder);
|
DotnetPublish(publishRoot: _application.WebSiteRootFolder);
|
||||||
|
|
||||||
// Drop a json file instead of setting environment variable.
|
// Drop a json file instead of setting environment variable.
|
||||||
SetAspEnvironmentWithJson();
|
SetAspEnvironmentWithJson();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
DeploymentParameters.PublishApplicationBeforeDeployment = true;
|
DeploymentParameters.PublishApplicationBeforeDeployment = true;
|
||||||
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
||||||
{
|
{
|
||||||
DnuPublish();
|
DotnetPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint);
|
var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
|
|
||||||
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
if (DeploymentParameters.PublishApplicationBeforeDeployment)
|
||||||
{
|
{
|
||||||
DnuPublish();
|
DotnetPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint);
|
var uri = TestUriHelper.BuildTestUri(DeploymentParameters.ApplicationBaseUriHint);
|
||||||
|
|
@ -49,23 +49,27 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
|
|
||||||
private CancellationToken StartSelfHost(Uri uri)
|
private CancellationToken StartSelfHost(Uri uri)
|
||||||
{
|
{
|
||||||
var commandName = DeploymentParameters.Command;
|
string executableName;
|
||||||
if (string.IsNullOrEmpty(commandName))
|
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);
|
executableArgs += $" --server.urls {uri} "
|
||||||
var dnxArgs = $"-p \"{DeploymentParameters.ApplicationPath}\" {commandName} " +
|
+ $" --server {(DeploymentParameters.ServerType == ServerType.WebListener ? "Microsoft.AspNetCore.Server.WebListener" : "Microsoft.AspNetCore.Server.Kestrel")}";
|
||||||
$"--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
|
var startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = dnxPath,
|
FileName = executableName,
|
||||||
Arguments = dnxArgs,
|
Arguments = executableArgs,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue