Fixed RemoteWindowsDeployer to support IIS scenarios
This commit is contained in:
parent
cb27e74fc9
commit
772bd562c9
|
|
@ -9,6 +9,9 @@ param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$accountPassword,
|
[string]$accountPassword,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$deployedFolderPath,
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]$dotnetRuntimePath = "",
|
[string]$dotnetRuntimePath = "",
|
||||||
|
|
||||||
|
|
@ -43,14 +46,14 @@ if ($serverAction -eq "StartServer")
|
||||||
{
|
{
|
||||||
Write-Host "Starting the application on machine '$serverName'"
|
Write-Host "Starting the application on machine '$serverName'"
|
||||||
$startServerScriptPath = "$PSScriptRoot\StartServer.ps1"
|
$startServerScriptPath = "$PSScriptRoot\StartServer.ps1"
|
||||||
$remoteResult=Invoke-Command -Session $psSession -FilePath $startServerScriptPath -ArgumentList $dotnetRuntimePath, $executablePath, $executableParameters, $serverType, $serverName, $applicationBaseUrl, $environmentVariables
|
$remoteResult=Invoke-Command -Session $psSession -FilePath $startServerScriptPath -ArgumentList $deployedFolderPath, $dotnetRuntimePath, $executablePath, $executableParameters, $serverType, $serverName, $applicationBaseUrl, $environmentVariables
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host "Stopping the application on machine '$serverName'"
|
Write-Host "Stopping the application on machine '$serverName'"
|
||||||
$stopServerScriptPath = "$PSScriptRoot\StopServer.ps1"
|
$stopServerScriptPath = "$PSScriptRoot\StopServer.ps1"
|
||||||
$serverProcessName = [System.IO.Path]::GetFileNameWithoutExtension($executablePath)
|
$serverProcessName = [System.IO.Path]::GetFileNameWithoutExtension($executablePath)
|
||||||
$remoteResult=Invoke-Command -Session $psSession -FilePath $stopServerScriptPath -ArgumentList $serverProcessName, $serverType, $serverName
|
$remoteResult=Invoke-Command -Session $psSession -FilePath $stopServerScriptPath -ArgumentList $deployedFolderPath, $serverProcessName, $serverType, $serverName
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove-PSSession $psSession
|
Remove-PSSession $psSession
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
@ -82,6 +83,11 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
// Publish the app to a local temp folder on the machine where the test is running
|
// Publish the app to a local temp folder on the machine where the test is running
|
||||||
DotnetPublish();
|
DotnetPublish();
|
||||||
|
|
||||||
|
if (_deploymentParameters.ServerType == ServerType.IIS)
|
||||||
|
{
|
||||||
|
UpdateWebConfig();
|
||||||
|
}
|
||||||
|
|
||||||
var folderId = Guid.NewGuid().ToString();
|
var folderId = Guid.NewGuid().ToString();
|
||||||
_deployedFolderPathInFileShare = Path.Combine(_deploymentParameters.RemoteServerFileSharePath, folderId);
|
_deployedFolderPathInFileShare = Path.Combine(_deploymentParameters.RemoteServerFileSharePath, folderId);
|
||||||
|
|
||||||
|
|
@ -140,6 +146,42 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateWebConfig()
|
||||||
|
{
|
||||||
|
var webConfigFilePath = Path.Combine(_deploymentParameters.PublishedApplicationRootPath, "web.config");
|
||||||
|
var webConfig = XDocument.Load(webConfigFilePath);
|
||||||
|
var aspNetCoreSection = webConfig.Descendants("aspNetCore")
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
// if the dotnet runtime path is specified, update the published web.config file to have that path
|
||||||
|
if (!string.IsNullOrEmpty(_deploymentParameters.DotnetRuntimePath))
|
||||||
|
{
|
||||||
|
aspNetCoreSection.SetAttributeValue(
|
||||||
|
"processPath",
|
||||||
|
Path.Combine(_deploymentParameters.DotnetRuntimePath, "dotnet.exe"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var environmentVariablesSection = aspNetCoreSection.Elements("environmentVariables").FirstOrDefault();
|
||||||
|
if (environmentVariablesSection == null)
|
||||||
|
{
|
||||||
|
environmentVariablesSection = new XElement("environmentVariables");
|
||||||
|
aspNetCoreSection.Add(environmentVariablesSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var envVariablePair in _deploymentParameters.EnvironmentVariables)
|
||||||
|
{
|
||||||
|
var environmentVariable = new XElement("environmentVariable");
|
||||||
|
environmentVariable.SetAttributeValue("name", envVariablePair.Key);
|
||||||
|
environmentVariable.SetAttributeValue("value", envVariablePair.Value);
|
||||||
|
environmentVariablesSection.Add(environmentVariable);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fileStream = File.Open(webConfigFilePath, FileMode.Open))
|
||||||
|
{
|
||||||
|
webConfig.Save(fileStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RunScript(string serverAction)
|
private void RunScript(string serverAction)
|
||||||
{
|
{
|
||||||
var remotePSSessionHelperScript = _scripts.Value.RemotePSSessionHelper;
|
var remotePSSessionHelperScript = _scripts.Value.RemotePSSessionHelper;
|
||||||
|
|
@ -162,6 +204,7 @@ namespace Microsoft.AspNetCore.Server.Testing
|
||||||
parameterBuilder.Append($" -serverName {_deploymentParameters.ServerName}");
|
parameterBuilder.Append($" -serverName {_deploymentParameters.ServerName}");
|
||||||
parameterBuilder.Append($" -accountName {_deploymentParameters.ServerAccountName}");
|
parameterBuilder.Append($" -accountName {_deploymentParameters.ServerAccountName}");
|
||||||
parameterBuilder.Append($" -accountPassword {_deploymentParameters.ServerAccountPassword}");
|
parameterBuilder.Append($" -accountPassword {_deploymentParameters.ServerAccountPassword}");
|
||||||
|
parameterBuilder.Append($" -deployedFolderPath {_deployedFolderPathInFileShare}");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(_deploymentParameters.DotnetRuntimePath))
|
if (!string.IsNullOrEmpty(_deploymentParameters.DotnetRuntimePath))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$deployedFolderPath,
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]$dotnetRuntimePath,
|
[string]$dotnetRuntimePath,
|
||||||
|
|
||||||
|
|
@ -25,21 +28,6 @@ param(
|
||||||
|
|
||||||
Write-Host "Executing the start server script on machine '$serverName'"
|
Write-Host "Executing the start server script on machine '$serverName'"
|
||||||
|
|
||||||
IF (-Not [string]::IsNullOrWhitespace($environmentVariables))
|
|
||||||
{
|
|
||||||
Write-Host "Setting up environment variables"
|
|
||||||
foreach ($envVariablePair in $environmentVariables.Split(",")){
|
|
||||||
$pair=$envVariablePair.Split("=");
|
|
||||||
[Environment]::SetEnvironmentVariable($pair[0], $pair[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($executablePath -eq "dotnet.exe")
|
|
||||||
{
|
|
||||||
Write-Host "Setting the dotnet runtime path to the PATH environment variable"
|
|
||||||
[Environment]::SetEnvironmentVariable("PATH", "$dotnetRuntimePath")
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Copying shell32.dll as a temporary workaround for issue https://github.com/dotnet/cli/issues/2967"
|
Write-Host "Copying shell32.dll as a temporary workaround for issue https://github.com/dotnet/cli/issues/2967"
|
||||||
if ($executablePath -eq "dotnet.exe")
|
if ($executablePath -eq "dotnet.exe")
|
||||||
{
|
{
|
||||||
|
|
@ -47,30 +35,53 @@ if ($executablePath -eq "dotnet.exe")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$destinationDir = Split-Path $executablePath
|
Copy-Item C:\Windows\System32\forwarders\shell32.dll $deployedFolderPath
|
||||||
Copy-Item C:\Windows\System32\forwarders\shell32.dll $destinationDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$command = $executablePath + " " + $executableParameters + " --server.urls " + $applicationBaseUrl
|
|
||||||
if ($serverType -eq "IIS")
|
if ($serverType -eq "IIS")
|
||||||
{
|
{
|
||||||
throw [System.NotImplementedException] "IIS deployment scenarios not yet implemented."
|
$publishedDirName=Split-Path $deployedFolderPath -Leaf
|
||||||
|
Write-Host "Creating IIS website '$publishedDirName' for path '$deployedFolderPath'"
|
||||||
|
Import-Module IISAdministration
|
||||||
|
$port=([System.Uri]$applicationBaseUrl).Port
|
||||||
|
$bindingPort="*:" + $port + ":"
|
||||||
|
New-IISSite -Name $publishedDirName -BindingInformation $bindingPort -PhysicalPath $deployedFolderPath
|
||||||
}
|
}
|
||||||
elseif ($serverType -eq "Kestrel")
|
elseif (($serverType -eq "Kestrel") -or ($serverType -eq "WebListener"))
|
||||||
{
|
{
|
||||||
$command = $command + " --server Microsoft.AspNetCore.Server.Kestrel"
|
if (-Not [string]::IsNullOrWhitespace($environmentVariables))
|
||||||
Write-Host "Executing the command '$command'"
|
{
|
||||||
Invoke-Expression $command
|
Write-Host "Setting up environment variables"
|
||||||
}
|
foreach ($envVariablePair in $environmentVariables.Split(","))
|
||||||
elseif ($serverType -eq "WebListener")
|
{
|
||||||
{
|
$pair=$envVariablePair.Split("=");
|
||||||
$command = $command + " --server Microsoft.AspNetCore.Server.WebListener"
|
[Environment]::SetEnvironmentVariable($pair[0], $pair[1])
|
||||||
Write-Host "Executing the command '$command'"
|
}
|
||||||
Invoke-Expression $command
|
}
|
||||||
|
|
||||||
|
if ($executablePath -eq "dotnet.exe")
|
||||||
|
{
|
||||||
|
Write-Host "Setting the dotnet runtime path to the PATH environment variable"
|
||||||
|
[Environment]::SetEnvironmentVariable("PATH", "$dotnetRuntimePath")
|
||||||
|
}
|
||||||
|
|
||||||
|
$command = $executablePath + " " + $executableParameters + " --server.urls " + $applicationBaseUrl
|
||||||
|
if ($serverType -eq "Kestrel")
|
||||||
|
{
|
||||||
|
$command = $command + " --server Microsoft.AspNetCore.Server.Kestrel"
|
||||||
|
Write-Host "Executing the command '$command'"
|
||||||
|
Invoke-Expression $command
|
||||||
|
}
|
||||||
|
elseif ($serverType -eq "WebListener")
|
||||||
|
{
|
||||||
|
$command = $command + " --server Microsoft.AspNetCore.Server.WebListener"
|
||||||
|
Write-Host "Executing the command '$command'"
|
||||||
|
Invoke-Expression $command
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw [System.InvalidOperationException] "Server type '$serverType' is not supported."
|
throw [System.InvalidOperationException] "Server type '$serverType' is not supported."
|
||||||
}
|
}
|
||||||
|
|
||||||
# NOTE: Make sure this is the last statement in this script as its used to get the exit code of this script
|
# NOTE: Make sure this is the last statement in this script as its used to get the exit code of this script
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$deployedFolderPath,
|
||||||
|
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$serverProcessName,
|
[string]$serverProcessName,
|
||||||
|
|
||||||
|
|
@ -37,22 +40,28 @@ Write-Host "Executing the stop server script on machine '$serverName'"
|
||||||
|
|
||||||
if ($serverType -eq "IIS")
|
if ($serverType -eq "IIS")
|
||||||
{
|
{
|
||||||
throw [System.NotImplementedException] "IIS deployment scenarios not yet implemented."
|
$publishedDirName=Split-Path $deployedFolderPath -Leaf
|
||||||
|
Write-Host "Stopping the IIS website '$publishedDirName'"
|
||||||
|
Import-Module IISAdministration
|
||||||
|
Stop-IISSite -Name $publishedDirName -Confirm:$false
|
||||||
|
Remove-IISSite -Name $publishedDirName -Confirm:$false
|
||||||
|
net stop w3svc
|
||||||
|
net start w3svc
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host "Stopping the process '$serverProcessName'"
|
Write-Host "Stopping the process '$serverProcessName'"
|
||||||
$serverProcess=Get-Process -Name "$serverProcessName"
|
$serverProcess=Get-Process -Name "$serverProcessName"
|
||||||
|
|
||||||
if (DoesCommandExist("taskkill"))
|
if (DoesCommandExist("taskkill"))
|
||||||
{
|
{
|
||||||
# Kill the parent and child processes
|
# Kill the parent and child processes
|
||||||
& taskkill /pid $serverProcess.Id /t /f
|
& taskkill /pid $serverProcess.Id /t /f
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stop-Process -Id $serverProcess.Id
|
Stop-Process -Id $serverProcess.Id -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# NOTE: Make sure this is the last statement in this script as its used to get the exit code of this script
|
# NOTE: Make sure this is the last statement in this script as its used to get the exit code of this script
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,9 @@
|
||||||
"System.Net.Http": "",
|
"System.Net.Http": "",
|
||||||
"System.Runtime": {
|
"System.Runtime": {
|
||||||
"type": "build"
|
"type": "build"
|
||||||
}
|
},
|
||||||
|
"System.Xml": "",
|
||||||
|
"System.Xml.Linq": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"netstandard1.3": {
|
"netstandard1.3": {
|
||||||
|
|
@ -56,7 +58,8 @@
|
||||||
"System.Runtime.Extensions": "4.1.0-*",
|
"System.Runtime.Extensions": "4.1.0-*",
|
||||||
"System.Text.RegularExpressions": "4.1.0-*",
|
"System.Text.RegularExpressions": "4.1.0-*",
|
||||||
"System.Threading": "4.0.11-*",
|
"System.Threading": "4.0.11-*",
|
||||||
"System.Threading.Thread": "4.0.0-*"
|
"System.Threading.Thread": "4.0.0-*",
|
||||||
|
"System.Xml.XDocument": "4.0.11-*"
|
||||||
},
|
},
|
||||||
"imports": [
|
"imports": [
|
||||||
"portable-net45+win8"
|
"portable-net45+win8"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue