Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added new configuration value features #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 57 additions & 27 deletions AppRolla.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1401,42 +1401,70 @@ Set-DeploymentTask init {
$xml.Load($configPath)

# appSettings section
foreach($appSettings in $xml.selectnodes("//*[local-name() = 'appSettings']"))
{
foreach($setting in $appSettings.ChildNodes)
{
if($setting.key)
{
$value = $variables["appSettings.$($setting.key)"]
if($value -ne $null)
{
Write-Log "Updating <appSettings> entry `"$($setting.key)`" to `"$value`""
$setting.value = $value
}
}
if ($variables.ContainsKey("appSettings")) {
$appSettingsNode = $xml.SelectSingleNode("configuration/appSettings")
if ($appSettingsNode -eq $null) {
$appSettingsNode = $xml.CreateElement('appSettings')
$xml.SelectSingleNode("configuration").AppendChild($appSettingsNode)
}
foreach ($appSettingKey in $variables["appSettings"].keys) {
$settingNode = $appSettingsNode.SelectSingleNode("add[@key='$appSettingKey']")
if ($settingNode -eq $null) {
$settingNode = $xml.CreateElement("add")
$settingNode.SetAttribute('key', $appSettingKey)
$appSettingsNode.AppendChild($settingNode)
}
$value = $variables["appSettings"][$appSettingKey]
$settingNode.SetAttribute('value', $value)
Write-Log "Updating <appSettings> entry `"$appSettingKey`" to `"$value`""
}
}

# connectionStrings
foreach($connectionStrings in $xml.selectnodes("//*[local-name() = 'connectionStrings']"))
{
foreach($entry in $connectionStrings.ChildNodes)
{
if($entry.name)
{
$connectionString = $variables["connectionStrings.$($entry.name)"]
if($connectionString -ne $null)
{
Write-Log "Updating <connectionStrings> entry `"$($entry.name)`" to `"$connectionString`""
$entry.connectionString = $connectionString
if ($variables.ContainsKey("connectionStrings")) {
$connectionStringsNode = $xml.SelectSingleNode("configuration/connectionStrings")
if ($connectionStringsNode -eq $null) {
$connectionStringsNode = $xml.CreateElement('connectionStrings')
$xml.SelectSingleNode("configuration").AppendChild($connectionStringsNode)
}

foreach ($connectionStringName in $variables["connectionStrings"].keys) {
$connectionStringNode = $connectionStringsNode.SelectSingleNode("add[@name='$connectionStringName']")
if ($connectionStringNode -eq $null) {
$connectionStringNode = $xml.CreateElement("add")
$connectionStringNode.SetAttribute('name', $connectionStringName)
$connectionStringsNode.AppendChild($connectionStringNode)
}
$value = $variables["connectionStrings"][$connectionStringName]
$connectionStringNode.SetAttribute('connectionString', $value)
Write-Log "Updating <connectionStrings> entry `"$connectionStringName`" to `"$value`""
}
}

if ($variables.ContainsKey("xmlpoke")) {
foreach ($xpath in $variables["xmlpoke"].keys) {
$value = $variables["xmlpoke"][$xpath]
$node = $xml.SelectSingleNode($xpath)
if ($node) {
$node.Value = $value
Write-Log "XmlPoke setting `"$xpath`" to `"$value`""
} else {
$index = $xpath.LastIndexOf('/');
$nodePath = $xpath.Substring(0, $index);
$attrName = $xpath.Substring($index + 2);
$node = $xml.SelectSingleNode($nodePath)
if ($node) {
$node.SetAttribute($attrName, $value)
} else {
Write-Log "XmlPoke setting `"$xpath`" not found"
}
}
}
}

$xml.Save($configPath)
}

function Test-RoleApplicableToServer
{
param (
Expand Down Expand Up @@ -1683,6 +1711,7 @@ Set-DeploymentTask deploy-website {
{
Write-Log "Updating web.config in $appConfigPath"
Update-ApplicationConfig -configPath $webConfigPath -variables $role.Configuration
Update-ApplicationConfig -configPath $webConfigPath -variables $context.Environment.Configuration
}

$appPoolName = $role.WebsiteName
Expand Down Expand Up @@ -1804,6 +1833,7 @@ Set-DeploymentTask deploy-service {
{
Write-Log "Updating service configuration in $appConfigPath"
Update-ApplicationConfig -configPath $appConfigPath -variables $role.Configuration
Update-ApplicationConfig -configPath $appConfigPath -variables $context.Environment.Configuration
}

# check if the service already exists
Expand Down Expand Up @@ -2620,4 +2650,4 @@ Export-ModuleMember -Function `
New-Environment, Get-Environment, Set-Environment, Add-EnvironmentServer, `
New-AzureEnvironment, Set-AzureEnvironment, `
Set-DeploymentTask, `
Invoke-DeploymentTask, New-Deployment, Remove-Deployment, Restore-Deployment, Restart-Deployment, Stop-Deployment, Start-Deployment
Invoke-DeploymentTask, New-Deployment, Remove-Deployment, Restore-Deployment, Restart-Deployment, Stop-Deployment, Start-Deployment
2 changes: 1 addition & 1 deletion Tests/playground.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Add-WebSiteRole MyApp MyWebsite -DeploymentGroup web `
Add-ServiceRole MyApp MyService -DeploymentGroup app `
-PackageUrl (Get-AppVeyorPackageUrl $applicationName $applicationVersion "HelloAppVeyor.Service") `
-Configuration @{
"ConnectionString.Default" = "server=locahost;"
"connectionStrings" = @{ "Default" = "server=locahost;" }
}

# add Staging environment
Expand Down
28 changes: 23 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,36 @@ Add-EnvironmentServer Dev localhost

##### How to update application configuration files?

AppRolla can update configuration settings in `appSettings` and `connectionString` sections on web.config and app.config files while deploying web applications and Windows services.
AppRolla can update configuration settings in the `appSettings` and `connectionStrings` sections of the web.config and app.config files while deploying web applications and Windows services. AppRolla can also poke XML values into the config files using XPath expressions.

Specify configuration settings in the format `appSettings.<key>` or `connectionString.<name>` to update keys in corresponding sections while adding a role:
Specify configuration settings to be automatically applied using the `appSettings`, `connectionStrings`, and `xmlpoke` config keys. You can specify config values at the role and environment level of your configuration:

```posh
Add-WebsiteRole MyApp MyWebsite ... -Configuration {
"appSettings.SiteUrl" = "http://www.mysite.com"
"appSettings" = @{
"SiteUrl" = "http://dev.mysite.com"
"SomeValue" = "true"
}
"connectionStrings" = @{ "Default" = "server=locahost; ..." }
"xmlpoke" = @{
"configuration/system.web/compilation/@debug" = "true"
}
}

Add-ServiceRole MyApp MyWebsite ... -Configuration {
"connectionString.Default" = "server=locahost; ..."
}

New-Environment Production -Configuration @{
"appSettings" = @{
"SiteUrl" = "http://www.mysite.com"
"SomeValue" = "false"
}
"connectionStrings" = @{ "Default" = "server=locahost; ..." }
"xmlpoke" = @{
"configuration/system.web/compilation/@debug" = "false"
}
}
```

#### Rollback deployment
Expand Down Expand Up @@ -606,8 +624,8 @@ To define configuration variables on role level use `-Configuration` parameter w
```posh
Add-WebsiteRole MyApp MyWebsite ... -Configuration @{
"variable1" = "value1"
"appSettings.setting1" = "value2"
"connectionStrings.Name" = "connection string details"
"appSettings" = @{ "setting1" = "value2" }
"connectionStrings" = @{ "connection string details" }
...
}
```
Expand Down