Skip to content

Commit

Permalink
fix: deployment script, decouple debugging and deployment settings (#…
Browse files Browse the repository at this point in the history
…2153)

* Fix deployment script.
Use appsettings.Deployment.json for local debug, use appsettings.Production.json for azure deployment.

* update production name to deployment

* fix typo

* use nightly build package

* remove version

* update to 3.1

Co-authored-by: Qi Kang <qika@microsoft.com>
Co-authored-by: Lu Han <32191031+luhan2017@users.noreply.github.com>
Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
4 people authored Mar 6, 2020
1 parent 4da36a2 commit a05a5fc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion BotProject/Templates/CSharp/BotProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.8.0-preview-200227-109209" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.8.0-preview-200227-109209" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.8.0-preview-200227-109209" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.8.0-preview-95744" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.8.0-preview-200227-109209" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66">
<PrivateAssets>all</PrivateAssets>
Expand Down
21 changes: 17 additions & 4 deletions BotProject/Templates/CSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,25 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, builder) =>
{
builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"ComposerDialogs/settings/appsettings.json", optional: true, reloadOnChange: true)
.UseLuisConfigAdaptor()
.UseLuisSettings();
var env = hostingContext.HostingEnvironment;

builder.AddJsonFile($"ComposerDialogs/settings/appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsetting.json", optional: true, reloadOnChange: true)
.UseLuisConfigAdaptor()
.UseLuisSettings();

if (env.IsDevelopment())
{
// Local Debug
builder.AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true);
}
else
{
//Azure Deploy
builder.AddJsonFile("appsettings.deployment.json", optional: true, reloadOnChange: true);
}

if (!env.IsDevelopment())
{
builder.AddUserSecrets<Startup>();
}
Expand Down
22 changes: 10 additions & 12 deletions BotProject/Templates/CSharp/Scripts/create.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ else {
New-Item -Path $logFile | Out-Null
}

if (-not (Test-Path (Join-Path $projDir 'appsettings.json')))
if (-not (Test-Path (Join-Path $projDir 'appsettings.deployment.json')))
{
Write-Host "! Could not find an 'appsettings.json' file in the current directory." -ForegroundColor DarkRed
Write-Host "! Could not find an 'appsettings.deployment.json' file in the current directory." -ForegroundColor DarkRed
Write-Host "+ Please re-run this script from your project directory." -ForegroundColor Magenta
Break
}
Expand Down Expand Up @@ -152,24 +152,22 @@ if ($outputs)
$outputMap = @{}
$outputs.PSObject.Properties | Foreach-Object { $outputMap[$_.Name] = $_.Value }

# Update appsettings.json
Write-Host "> Updating appsettings.json ..."
if (Test-Path $(Join-Path $projDir appsettings.json)) {
$settings = Get-Content $(Join-Path $projDir appsettings.json) | ConvertFrom-Json
# Update appsettings.deployment.json
Write-Host "> Updating appsettings.deployment.json ..."
if (Test-Path $(Join-Path $projDir appsettings.deployment.json)) {
$settings = Get-Content $(Join-Path $projDir appsettings.deployment.json) | ConvertFrom-Json
}
else {
$settings = New-Object PSObject
}

$settings | Add-Member -Type NoteProperty -Force -Name 'microsoftAppId' -Value $appId

dotnet user-secrets init --project $projDir
dotnet user-secrets set "MicrosoftAppPassword" $appPassword --project $projDir
$settings | Add-Member -Type NoteProperty -Force -Name 'MicrosoftAppId' -Value $appId
$settings | Add-Member -Type NoteProperty -Force -Name 'MicrosoftAppPassword' -Value $appPassword

$settings | Add-Member -Type NoteProperty -Force -Name 'bot' -Value "ComposerDialogs"

foreach ($key in $outputMap.Keys) { $settings | Add-Member -Type NoteProperty -Force -Name $key -Value $outputMap[$key].value }
$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $projDir appsettings.json)
$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $projDir appsettings.deployment.json)

Write-Host "> Done."
Write-Host "- App Id: $appId"
Expand Down Expand Up @@ -210,4 +208,4 @@ else

Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
Break
}
}
46 changes: 16 additions & 30 deletions BotProject/Templates/CSharp/Scripts/deploy.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Param(
Param(
[string] $name,
[string] $environment,
[string] $luisAuthoringKey,
Expand Down Expand Up @@ -56,7 +56,7 @@ if (Test-Path $zipPath) {
dotnet user-secrets init

# Perform dotnet publish step ahead of zipping up
$publishFolder = $(Join-Path $projFolder 'bin\Release\netcoreapp2.2')
$publishFolder = $(Join-Path $projFolder 'bin\Release\netcoreapp3.1')
dotnet publish -c release -o $publishFolder -v q > $logFile


Expand All @@ -73,26 +73,8 @@ else {
Copy-Item -Path $localBotPath -Recurse -Destination $publishFolder -Container -Force
}

# Merge from custom config files
$customConfigFiles = Get-ChildItem -Path $remoteBotPath -Include "appsettings.json" -Recurse -Force
if ($customConfigFiles) {
if (Test-Path $(Join-Path $publishFolder appsettings.json)) {
$settings = Get-Content $(Join-Path $publishFolder appsettings.json) | ConvertFrom-Json
}
else {
$settings = New-Object PSObject
}

$customConfig = @{ }
$customSetting = Get-Content $customConfigFiles.FullName | ConvertFrom-Json
$customSetting.PSObject.Properties | Foreach-Object { $customConfig[$_.Name] = $_.Value }
foreach ($key in $customConfig.Keys) { $settings | Add-Member -Type NoteProperty -Force -Name $key -Value $customConfig[$key] }

$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $publishFolder appsettings.json)
}

# Try to get luis config from appsettings
$settings = Get-Content $(Join-Path $projFolder appsettings.json) | ConvertFrom-Json
$settings = Get-Content $(Join-Path $projFolder appsettings.deployment.json) | ConvertFrom-Json
$luisSettings = $settings.luis

if (-not $luisAuthoringKey) {
Expand Down Expand Up @@ -131,13 +113,17 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {

$luconfigjson | ConvertTo-Json -Depth 100 | Out-File $(Join-Path $remoteBotPath luconfig.json)

# Execute lubuild command
if (Get-Command lubuild -errorAction SilentlyContinue) {
lubuild --authoringKey $luisAuthoringKey
# Execute bf luis:build command
if (Get-Command bf -errorAction SilentlyContinue) {
$customizedSettings = Get-Content $(Join-Path $remoteBotPath settings appsettings.json) | ConvertFrom-Json
$customizedEnv = $customizedSettings.luis.environment
bf luis:build --in .\ --botName $name --authoringKey $luisAuthoringKey --dialog --out .\generated --suffix $customizedEnv -f
}
else {
Write-Host "lubuild does not exist, use the following command to install lubuild:"
Write-Host "npm install -g https://botbuilder.myget.org/F/botbuilder-declarative/npm/lubuild/-/1.0.3-preview.tgz"
Write-Host "bf luis:build does not exist, use the following command to install:"
Write-Host "1. npm config set registry https://botbuilder.myget.org/F/botframework-cli/npm/"
Write-Host "2. npm install -g @microsoft/botframework-cli"
Write-Host "3. npm config set registry http://registry.npmjs.org"
Break
}

Expand All @@ -152,8 +138,8 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {
Set-Location -Path $projFolder

# change setting file in publish folder
if (Test-Path $(Join-Path $publishFolder appsettings.json)) {
$settings = Get-Content $(Join-Path $publishFolder appsettings.json) | ConvertFrom-Json
if (Test-Path $(Join-Path $publishFolder appsettings.deployment.json)) {
$settings = Get-Content $(Join-Path $publishFolder appsettings.deployment.json) | ConvertFrom-Json
}
else {
$settings = New-Object PSObject
Expand All @@ -180,7 +166,7 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {

$settings | Add-Member -Type NoteProperty -Force -Name 'luis' -Value $luisConfig

$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $publishFolder appsettings.json)
$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $publishFolder appsettings.deployment.json)

$tokenResponse = (az account get-access-token) | ConvertFrom-Json
$token = $tokenResponse.accessToken
Expand Down Expand Up @@ -251,4 +237,4 @@ if ($?) {
else {
Write-Host "! Could not deploy automatically to Azure. Review the log for more information." -ForegroundColor DarkRed
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
}
}
3 changes: 3 additions & 0 deletions BotProject/Templates/CSharp/appsettings.Deployment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
8 changes: 1 addition & 7 deletions BotProject/Templates/CSharp/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export class CSharpBotConnector implements IBotConnector {
`bin/Debug/${envSettings.runtimeFrameworkVersion}/BotProject.dll`,
`--urls`,
this.endpoint,
`--environment`,
`development`,
...this.getConnectorConfig(config),
],
{
Expand Down

0 comments on commit a05a5fc

Please sign in to comment.