Fix Deployment Script (Luis Authoring Account Error) (#1423)
* add error handling, error message for multi luis authoring services error * fix naming * fix error message * fix error message
This commit is contained in:
Родитель
4f07ba155d
Коммит
1dac705d93
|
@ -22,6 +22,10 @@
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": true
|
"defaultValue": true
|
||||||
},
|
},
|
||||||
|
"shouldDeployAuthoringResource": {
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": true
|
||||||
|
},
|
||||||
"cosmosDbName": {
|
"cosmosDbName": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"defaultValue": "[resourceGroup().name]"
|
"defaultValue": "[resourceGroup().name]"
|
||||||
|
@ -39,6 +43,10 @@
|
||||||
"description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
|
"description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"luisAuthoringKey": {
|
||||||
|
"type": "string",
|
||||||
|
"defaultValue": ""
|
||||||
|
},
|
||||||
"newAppServicePlanName": {
|
"newAppServicePlanName": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"defaultValue": "[resourceGroup().name]",
|
"defaultValue": "[resourceGroup().name]",
|
||||||
|
@ -251,7 +259,8 @@
|
||||||
"kind": "LUIS.Authoring",
|
"kind": "LUIS.Authoring",
|
||||||
"sku": {
|
"sku": {
|
||||||
"name": "[parameters('luisServiceAuthoringSku')]"
|
"name": "[parameters('luisServiceAuthoringSku')]"
|
||||||
}
|
},
|
||||||
|
"condition": "[parameters('shouldDeployAuthoringResource')]"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"comments": "Cognitive service endpoint key for all LUIS apps.",
|
"comments": "Cognitive service endpoint key for all LUIS apps.",
|
||||||
|
@ -292,7 +301,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"value": {
|
"value": {
|
||||||
"endpointKey": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', parameters('luisServiceName')),'2017-04-18').key1]",
|
"endpointKey": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', parameters('luisServiceName')),'2017-04-18').key1]",
|
||||||
"authoringKey": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('LuisAuthoringAccountName')),'2017-04-18').key1]",
|
"authoringKey": "[if(parameters('shouldDeployAuthoringResource'), listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('LuisAuthoringAccountName')),'2017-04-18').key1, parameters('luisAuthoringKey'))]",
|
||||||
"region": "[parameters('luisServiceLocation')]"
|
"region": "[parameters('luisServiceLocation')]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ Param(
|
||||||
[string] $appId,
|
[string] $appId,
|
||||||
[string] $appPassword,
|
[string] $appPassword,
|
||||||
[string] $environment,
|
[string] $environment,
|
||||||
|
[string] $luisAuthoringKey,
|
||||||
[string] $projDir = $(Get-Location),
|
[string] $projDir = $(Get-Location),
|
||||||
[string] $logFile = $(Join-Path $PSScriptRoot .. "create_log.txt")
|
[string] $logFile = $(Join-Path $PSScriptRoot .. "create_log.txt")
|
||||||
)
|
)
|
||||||
|
@ -71,6 +72,13 @@ if (-not $appId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shouldDeployAuthoringResource = $true
|
||||||
|
|
||||||
|
# Use pre-exsisting luis authoring key
|
||||||
|
if ($luisAuthoringKey) {
|
||||||
|
$shouldDeployAuthoringResource = $false
|
||||||
|
}
|
||||||
|
|
||||||
$resourceGroup = "$name-$environment"
|
$resourceGroup = "$name-$environment"
|
||||||
$servicePlanName = "$name-$environment"
|
$servicePlanName = "$name-$environment"
|
||||||
|
|
||||||
|
@ -86,7 +94,7 @@ Write-Host "> Validating Azure deployment ..."
|
||||||
$validation = az group deployment validate `
|
$validation = az group deployment validate `
|
||||||
--resource-group $resourcegroup `
|
--resource-group $resourcegroup `
|
||||||
--template-file "$(Join-Path $PSScriptRoot '..' 'DeploymentTemplates' 'template-with-preexisting-rg.json')" `
|
--template-file "$(Join-Path $PSScriptRoot '..' 'DeploymentTemplates' 'template-with-preexisting-rg.json')" `
|
||||||
--parameters appId=$appId appSecret="`"$($appPassword)`"" appServicePlanLocation=$location botId=$name `
|
--parameters appId=$appId appSecret="`"$($appPassword)`"" appServicePlanLocation=$location botId=$name shouldDeployAuthoringResource=$shouldDeployAuthoringResource luisAuthoringKey=$luisAuthoringKey `
|
||||||
--output json
|
--output json
|
||||||
|
|
||||||
if ($validation) {
|
if ($validation) {
|
||||||
|
@ -99,7 +107,7 @@ if ($validation) {
|
||||||
--name $timestamp `
|
--name $timestamp `
|
||||||
--resource-group $resourceGroup `
|
--resource-group $resourceGroup `
|
||||||
--template-file "$(Join-Path $PSScriptRoot '..' 'DeploymentTemplates' 'template-with-preexisting-rg.json')" `
|
--template-file "$(Join-Path $PSScriptRoot '..' 'DeploymentTemplates' 'template-with-preexisting-rg.json')" `
|
||||||
--parameters appId=$appId appSecret="`"$($appPassword)`"" appServicePlanLocation=$location botId=$name `
|
--parameters appId=$appId appSecret="`"$($appPassword)`"" appServicePlanLocation=$location botId=$name shouldDeployAuthoringResource=$shouldDeployAuthoringResource luisAuthoringKey=$luisAuthoringKey `
|
||||||
--output json
|
--output json
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -107,6 +115,13 @@ if ($validation) {
|
||||||
Write-Host "! Error: $($validation.error.message)" -ForegroundColor DarkRed
|
Write-Host "! Error: $($validation.error.message)" -ForegroundColor DarkRed
|
||||||
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
|
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
|
||||||
Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
|
Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
|
||||||
|
|
||||||
|
if ($validation.error.details -and $validation.error.details[0].code -eq "CanNotCreateMultipleFreeAccounts")
|
||||||
|
{
|
||||||
|
Write-Host "! The subscription is exceeding the maximum number of allowed LuisAuthoringAccounts. You already have a luis authoring resource created, please get your luis authoring key and retry with the following command:" -ForegroundColor DarkRed
|
||||||
|
Write-Host "pwsh ./Scripts/create.ps1 -name $name -environment $environment -location $location -appPassword $appPassword -luisAuthoringKey [YourLuisAuthoringKey]" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
Break
|
Break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,6 +139,15 @@ if ($outputs)
|
||||||
# Log and convert to JSON
|
# Log and convert to JSON
|
||||||
$outputs >> $logFile
|
$outputs >> $logFile
|
||||||
$outputs = $outputs | ConvertFrom-Json
|
$outputs = $outputs | ConvertFrom-Json
|
||||||
|
if ($outputs.properties.error) {
|
||||||
|
Write-Host "! Deployment failed. Review the log for more information." -ForegroundColor DarkRed
|
||||||
|
Write-Host "! Error: $($outputs.error.message)" -ForegroundColor DarkRed
|
||||||
|
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
|
||||||
|
Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
|
||||||
|
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
$outputs = $outputs.properties.outputs
|
$outputs = $outputs.properties.outputs
|
||||||
$outputMap = @{}
|
$outputMap = @{}
|
||||||
$outputs.PSObject.Properties | Foreach-Object { $outputMap[$_.Name] = $_.Value }
|
$outputs.PSObject.Properties | Foreach-Object { $outputMap[$_.Name] = $_.Value }
|
||||||
|
|
|
@ -15,6 +15,12 @@ if ($PSVersionTable.PSVersion.Major -lt 6) {
|
||||||
Break
|
Break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((dotnet --version) -lt 3) {
|
||||||
|
Write-Host "! dotnet core 3.0 is required, please refer following documents for help."
|
||||||
|
Write-Host "https://dotnet.microsoft.com/download/dotnet-core/3.0"
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
# Get mandatory parameters
|
# Get mandatory parameters
|
||||||
if (-not $name) {
|
if (-not $name) {
|
||||||
$name = Read-Host "? Bot Web App Name"
|
$name = Read-Host "? Bot Web App Name"
|
||||||
|
@ -135,6 +141,14 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {
|
||||||
Break
|
Break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($?) {
|
||||||
|
Write-Host "lubuild succeeded"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "lubuild failed, please verify your luis models."
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
Set-Location -Path $projFolder
|
Set-Location -Path $projFolder
|
||||||
|
|
||||||
# change setting file in publish folder
|
# change setting file in publish folder
|
||||||
|
@ -171,6 +185,11 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {
|
||||||
$tokenResponse = (az account get-access-token) | ConvertFrom-Json
|
$tokenResponse = (az account get-access-token) | ConvertFrom-Json
|
||||||
$token = $tokenResponse.accessToken
|
$token = $tokenResponse.accessToken
|
||||||
|
|
||||||
|
if (-not $token) {
|
||||||
|
Write-Host "! Could not get valid Azure access token"
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Getting Luis accounts..."
|
Write-Host "Getting Luis accounts..."
|
||||||
$luisAccountEndpoint = "$luisEndpoint/luis/api/v2.0/azureaccounts"
|
$luisAccountEndpoint = "$luisEndpoint/luis/api/v2.0/azureaccounts"
|
||||||
$luisAccounts = Invoke-WebRequest -Method GET -Uri $luisAccountEndpoint -Headers @{"Authorization" = "Bearer $token"; "Ocp-Apim-Subscription-Key" = $luisAuthoringKey } | ConvertFrom-Json
|
$luisAccounts = Invoke-WebRequest -Method GET -Uri $luisAccountEndpoint -Headers @{"Authorization" = "Bearer $token"; "Ocp-Apim-Subscription-Key" = $luisAuthoringKey } | ConvertFrom-Json
|
||||||
|
|
Загрузка…
Ссылка в новой задаче