Skip to content

Instantly share code, notes, and snippets.

@anthonychu
Last active November 7, 2017 08:15
Show Gist options
  • Save anthonychu/1375b3a633a9b6db4289ba2772bdffa8 to your computer and use it in GitHub Desktop.
Save anthonychu/1375b3a633a9b6db4289ba2772bdffa8 to your computer and use it in GitHub Desktop.
FROM microsoft/aspnet
WORKDIR /inetpub/wwwroot
COPY . .
ENTRYPOINT ["powershell.exe", ".\\Startup.ps1"]
param (
[string]$webConfig = ".\Web.config.test"
)
$doc = (Get-Content $webConfig) -as [Xml];
$appSettingPrefix = "APPSETTING_";
$connectionStringPrefix = "CONNSTR_";
Get-ChildItem env:* | ForEach-Object {
if ($_.Key.StartsWith($appSettingPrefix)) {
$key = $_.Key.Substring($appSettingPrefix.Length);
$appSetting = $doc.configuration.appSettings.add | Where-Object {$_.key -eq $key};
if ($appSetting) {
$appSetting.value = $_.Value;
Write-Host "Replaced appSetting" $_.Key $_.Value;
}
}
if ($_.Key.StartsWith($connectionStringPrefix)) {
$key = $_.Key.Substring($connectionStringPrefix.Length);
$connStr = $doc.configuration.connectionStrings.add | Where-Object {$_.name -eq $key};
if ($connStr) {
$connStr.connectionString = $_.Value;
Write-Host "Replaced connectionString" $_.Key $_.Value;
}
}
}
$doc.Save($webConfig);
.\Set-WebConfigSettings.ps1 -webConfig .\Web.config
C:\ServiceMonitor.exe w3svc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment