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",
|
||||
"defaultValue": true
|
||||
},
|
||||
"shouldDeployAuthoringResource": {
|
||||
"type": "bool",
|
||||
"defaultValue": true
|
||||
},
|
||||
"cosmosDbName": {
|
||||
"type": "string",
|
||||
"defaultValue": "[resourceGroup().name]"
|
||||
|
@ -39,6 +43,10 @@
|
|||
"description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
|
||||
}
|
||||
},
|
||||
"luisAuthoringKey": {
|
||||
"type": "string",
|
||||
"defaultValue": ""
|
||||
},
|
||||
"newAppServicePlanName": {
|
||||
"type": "string",
|
||||
"defaultValue": "[resourceGroup().name]",
|
||||
|
@ -251,7 +259,8 @@
|
|||
"kind": "LUIS.Authoring",
|
||||
"sku": {
|
||||
"name": "[parameters('luisServiceAuthoringSku')]"
|
||||
}
|
||||
},
|
||||
"condition": "[parameters('shouldDeployAuthoringResource')]"
|
||||
},
|
||||
{
|
||||
"comments": "Cognitive service endpoint key for all LUIS apps.",
|
||||
|
@ -292,7 +301,7 @@
|
|||
"type": "object",
|
||||
"value": {
|
||||
"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')]"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ Param(
|
|||
[string] $appId,
|
||||
[string] $appPassword,
|
||||
[string] $environment,
|
||||
[string] $luisAuthoringKey,
|
||||
[string] $projDir = $(Get-Location),
|
||||
[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"
|
||||
$servicePlanName = "$name-$environment"
|
||||
|
||||
|
@ -86,7 +94,7 @@ Write-Host "> Validating Azure deployment ..."
|
|||
$validation = az group deployment validate `
|
||||
--resource-group $resourcegroup `
|
||||
--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
|
||||
|
||||
if ($validation) {
|
||||
|
@ -99,7 +107,7 @@ if ($validation) {
|
|||
--name $timestamp `
|
||||
--resource-group $resourceGroup `
|
||||
--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
|
||||
}
|
||||
else {
|
||||
|
@ -107,6 +115,13 @@ if ($validation) {
|
|||
Write-Host "! Error: $($validation.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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +139,15 @@ if ($outputs)
|
|||
# Log and convert to JSON
|
||||
$outputs >> $logFile
|
||||
$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
|
||||
$outputMap = @{}
|
||||
$outputs.PSObject.Properties | Foreach-Object { $outputMap[$_.Name] = $_.Value }
|
||||
|
|
|
@ -15,6 +15,12 @@ if ($PSVersionTable.PSVersion.Major -lt 6) {
|
|||
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
|
||||
if (-not $name) {
|
||||
$name = Read-Host "? Bot Web App Name"
|
||||
|
@ -135,6 +141,14 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {
|
|||
Break
|
||||
}
|
||||
|
||||
if ($?) {
|
||||
Write-Host "lubuild succeeded"
|
||||
}
|
||||
else {
|
||||
Write-Host "lubuild failed, please verify your luis models."
|
||||
Break
|
||||
}
|
||||
|
||||
Set-Location -Path $projFolder
|
||||
|
||||
# change setting file in publish folder
|
||||
|
@ -171,6 +185,11 @@ if ($luisAuthoringKey -and $luisAuthoringRegion) {
|
|||
$tokenResponse = (az account get-access-token) | ConvertFrom-Json
|
||||
$token = $tokenResponse.accessToken
|
||||
|
||||
if (-not $token) {
|
||||
Write-Host "! Could not get valid Azure access token"
|
||||
Break
|
||||
}
|
||||
|
||||
Write-Host "Getting Luis accounts..."
|
||||
$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
|
||||
|
|
Загрузка…
Ссылка в новой задаче