Adding creating Azure specific configuration
This commit is contained in:
parent
674efca4de
commit
bed9432275
|
|
@ -1,11 +1,12 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// 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.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
}
|
}
|
||||||
|
|
||||||
var applicationName = Path.ChangeExtension(GetApplicationName(applicationBasePath), "exe");
|
var applicationName = Path.ChangeExtension(GetApplicationName(applicationBasePath), "exe");
|
||||||
var transformedConfig = WebConfigTransform.Transform(webConfigXml, applicationName);
|
var transformedConfig = WebConfigTransform.Transform(webConfigXml, applicationName, ConfigureForAzure());
|
||||||
|
|
||||||
using (var f = new FileStream(webConfigPath, FileMode.Create))
|
using (var f = new FileStream(webConfigPath, FileMode.Create))
|
||||||
{
|
{
|
||||||
|
|
@ -92,5 +93,13 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ConfigureForAzure()
|
||||||
|
{
|
||||||
|
var configureForAzureValue = Environment.GetEnvironmentVariable("DOTNET_CONFIGURE_AZURE");
|
||||||
|
return string.Equals(configureForAzureValue, "true", StringComparison.Ordinal) ||
|
||||||
|
string.Equals(configureForAzureValue, "1", StringComparison.Ordinal) ||
|
||||||
|
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
{
|
{
|
||||||
public static class WebConfigTransform
|
public static class WebConfigTransform
|
||||||
{
|
{
|
||||||
public static XDocument Transform(XDocument webConfig, string appName)
|
public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure)
|
||||||
{
|
{
|
||||||
const string HandlersElementName = "handlers";
|
const string HandlersElementName = "handlers";
|
||||||
const string httpPlatformElementName = "httpPlatform";
|
const string httpPlatformElementName = "httpPlatform";
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer");
|
var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer");
|
||||||
|
|
||||||
TransformHandlers(GetOrCreateChild(webServerSection, HandlersElementName));
|
TransformHandlers(GetOrCreateChild(webServerSection, HandlersElementName));
|
||||||
TransformHttpPlatform(GetOrCreateChild(webServerSection, httpPlatformElementName), appName);
|
TransformHttpPlatform(GetOrCreateChild(webServerSection, httpPlatformElementName), appName, configureForAzure);
|
||||||
|
|
||||||
// make sure that the httpPlatform element is after handlers element
|
// make sure that the httpPlatform element is after handlers element
|
||||||
var httpPlatformElement = webServerSection.Element(HandlersElementName)
|
var httpPlatformElement = webServerSection.Element(HandlersElementName)
|
||||||
|
|
@ -55,11 +55,14 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS
|
||||||
SetAttributeValueIfEmpty(platformHandlerElement, "resourceType", "Unspecified");
|
SetAttributeValueIfEmpty(platformHandlerElement, "resourceType", "Unspecified");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TransformHttpPlatform(XElement httpPlatformElement, string appName)
|
private static void TransformHttpPlatform(XElement httpPlatformElement, string appName, bool configureForAzure)
|
||||||
{
|
{
|
||||||
httpPlatformElement.SetAttributeValue("processPath", Path.Combine("..", appName));
|
var appPath = Path.Combine(configureForAzure ? @"%home%\site" : "..", appName);
|
||||||
|
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @"..\logs", "stdout.log");
|
||||||
|
|
||||||
|
httpPlatformElement.SetAttributeValue("processPath", appPath);
|
||||||
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogEnabled", "false");
|
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogEnabled", "false");
|
||||||
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogFile", @"..\logs\stdout.log");
|
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogFile", logPath);
|
||||||
SetAttributeValueIfEmpty(httpPlatformElement, "startupTimeLimit", "3600");
|
SetAttributeValueIfEmpty(httpPlatformElement, "startupTimeLimit", "3600");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,15 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebConfigTransform_creates_new_config_if_one_does_not_exist()
|
public void WebConfigTransform_creates_new_config_if_one_does_not_exist()
|
||||||
{
|
{
|
||||||
Assert.True(XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(null, "test.exe")));
|
Assert.True(XNode.DeepEquals(WebConfigTemplate,
|
||||||
|
WebConfigTransform.Transform(null, "test.exe", configureForAzure: false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebConfigTransform_creates_new_config_if_one_has_unexpected_format()
|
public void WebConfigTransform_creates_new_config_if_one_has_unexpected_format()
|
||||||
{
|
{
|
||||||
Assert.True(XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(XDocument.Parse("<unexpected />"), "test.exe")));
|
Assert.True(XNode.DeepEquals(WebConfigTemplate,
|
||||||
|
WebConfigTransform.Transform(XDocument.Parse("<unexpected />"), "test.exe", configureForAzure: false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -42,7 +44,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
input.Descendants(elementName).Remove();
|
input.Descendants(elementName).Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(input, "test.exe")));
|
Assert.True(XNode.DeepEquals(WebConfigTemplate,
|
||||||
|
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -59,7 +62,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
var input = new XDocument(WebConfigTemplate);
|
var input = new XDocument(WebConfigTemplate);
|
||||||
input.Descendants(elementName).Single().SetAttributeValue(attributeName, attributeValue);
|
input.Descendants(elementName).Single().SetAttributeValue(attributeName, attributeValue);
|
||||||
|
|
||||||
var output = WebConfigTransform.Transform(input, "test.exe");
|
var output = WebConfigTransform.Transform(input, "test.exe", configureForAzure: false);
|
||||||
Assert.Equal(attributeValue, (string)output.Descendants(elementName).Single().Attribute(attributeName));
|
Assert.Equal(attributeValue, (string)output.Descendants(elementName).Single().Attribute(attributeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +70,7 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
public void WebConfigTransform_overwrites_processPath()
|
public void WebConfigTransform_overwrites_processPath()
|
||||||
{
|
{
|
||||||
var newProcessPath =
|
var newProcessPath =
|
||||||
(string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe")
|
(string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe", configureForAzure: false)
|
||||||
.Descendants("httpPlatform").Single().Attribute("processPath");
|
.Descendants("httpPlatform").Single().Attribute("processPath");
|
||||||
|
|
||||||
Assert.Equal(@"..\app.exe", newProcessPath);
|
Assert.Equal(@"..\app.exe", newProcessPath);
|
||||||
|
|
@ -79,7 +82,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
var input = new XDocument(WebConfigTemplate);
|
var input = new XDocument(WebConfigTemplate);
|
||||||
input.Descendants("add").Single().SetAttributeValue("name", "httpplatformhandler");
|
input.Descendants("add").Single().SetAttributeValue("name", "httpplatformhandler");
|
||||||
|
|
||||||
Assert.True(XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(input, "test.exe")));
|
Assert.True(XNode.DeepEquals(WebConfigTemplate,
|
||||||
|
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -93,7 +97,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
input.Descendants("httpPlatform").Single().Add(envVarsElement);
|
input.Descendants("httpPlatform").Single().Add(envVarsElement);
|
||||||
|
|
||||||
Assert.True(XNode.DeepEquals(envVarsElement,
|
Assert.True(XNode.DeepEquals(envVarsElement,
|
||||||
WebConfigTransform.Transform(input, "app.exe").Descendants("httpPlatform").Elements().Single()));
|
WebConfigTransform.Transform(input, "app.exe", configureForAzure: false)
|
||||||
|
.Descendants("httpPlatform").Elements().Single()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -104,7 +109,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
"false",
|
"false",
|
||||||
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogEnabled").Single());
|
(string)WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)
|
||||||
|
.Descendants().Attributes("stdoutLogEnabled").Single());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -124,7 +130,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
@"..\logs\stdout.log",
|
@"..\logs\stdout.log",
|
||||||
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogFile").Single());
|
(string)WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)
|
||||||
|
.Descendants().Attributes("stdoutLogFile").Single());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -145,7 +152,20 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
"mylog.txt",
|
"mylog.txt",
|
||||||
(string)WebConfigTransform.Transform(input, "test.exe").Descendants().Attributes("stdoutLogFile").Single());
|
(string)WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)
|
||||||
|
.Descendants().Attributes("stdoutLogFile").Single());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WebConfigTransform_correctly_configures_for_Azure()
|
||||||
|
{
|
||||||
|
var input = new XDocument(WebConfigTemplate);
|
||||||
|
input.Descendants("httpPlatform").Attributes().Remove();
|
||||||
|
|
||||||
|
Assert.True(XNode.DeepEquals(
|
||||||
|
XDocument.Parse(@"<httpPlatform processPath=""%home%\site\test.exe"" stdoutLogEnabled=""false""
|
||||||
|
stdoutLogFile=""\\?\%home%\LogFiles\stdout.log"" startupTimeLimit=""3600""/>").Root,
|
||||||
|
WebConfigTransform.Transform(input, "test.exe", configureForAzure: true).Descendants("httpPlatform").Single()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool VerifyMissingElementCreated(params string[] elementNames)
|
private bool VerifyMissingElementCreated(params string[] elementNames)
|
||||||
|
|
@ -156,7 +176,8 @@ namespace Microsoft.AspNetCore.Tools.PublishIIS.Tests
|
||||||
input.Descendants(elementName).Remove();
|
input.Descendants(elementName).Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
return XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(input, "test.exe"));
|
return XNode.DeepEquals(WebConfigTemplate,
|
||||||
|
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue