From 4e11acbb737aeca4b3b4eeeb821f0ea291227dd2 Mon Sep 17 00:00:00 2001 From: stevengum <14935595+stevengum@users.noreply.github.com> Date: Thu, 20 Jun 2019 11:47:36 -0700 Subject: [PATCH 1/4] add initial functioning ARM template for flask core-bot --- .../exported_template.json | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json diff --git a/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json b/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json new file mode 100644 index 000000000..d47131150 --- /dev/null +++ b/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json @@ -0,0 +1,185 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "appId": { + "type": "string", + "metadata": { + "description": "Active Directory App ID, set as MicrosoftAppId in the Web App's Application Settings." + } + }, + "appSecret": { + "type": "string", + "metadata": { + "description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings." + } + }, + "newWebAppName": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"." + } + }, + "newAppServicePlanName": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "The name of the new App Service Plan." + } + }, + "newAppServicePlanSku": { + "type": "object", + "defaultValue": { + "name": "S1", + "tier": "Standard", + "size": "S1", + "family": "S", + "capacity": 1 + }, + "metadata": { + "description": "The SKU of the App Service Plan. Defaults to Standard values." + } + }, + "appServicePlanLocation": { + "type": "string", + "metadata": { + "description": "The location of the App Service Plan." + } + } + }, + "variables": { + "publishingUsername": "[concat('$', parameters('newWebAppName'))]", + "resourcesLocation": "[parameters('appServicePlanLocation')]" + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2016-09-01", + "name": "[parameters('newAppServicePlanName')]", + "location": "[variables('resourcesLocation')]", + "sku": "[parameters('newAppServicePlanSku')]", + "kind": "linux", + "properties": { + "name": "[parameters('newAppServicePlanName')]", + "perSiteScaling": false, + "reserved": true, + "targetWorkerCount": 0, + "targetWorkerSizeId": 0 + } + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2016-08-01", + "name": "[parameters('newWebAppName')]", + "location": "[variables('resourcesLocation')]", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', parameters('newAppServicePlanName'))]" + ], + "kind": "app,linux", + "properties": { + "enabled": true, + "hostNameSslStates": [ + { + "name": "[concat(parameters('newWebAppName'), '.azurewebsites.net')]", + "sslState": "Disabled", + "hostType": "Standard" + }, + { + "name": "[concat(parameters('newWebAppName'), '.scm.azurewebsites.net')]", + "sslState": "Disabled", + "hostType": "Repository" + } + ], + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('newAppServicePlanName'))]", + "reserved": true, + "scmSiteAlsoStopped": false, + "clientAffinityEnabled": false, + "clientCertEnabled": false, + "hostNamesDisabled": false, + "containerSize": 0, + "dailyMemoryTimeQuota": 0, + "httpsOnly": false, + "siteConfig": { + "appSettings": [ + { + "name": "MicrosoftAppId", + "value": "[parameters('appId')]" + }, + { + "name": "MicrosoftAppPassword", + "value": "[parameters('appSecret')]" + }, + { + "name": "SCM_DO_BUILD_DURING_DEPLOYMENT", + "value": "true" + } + ] + } + } + }, + { + "type": "Microsoft.Web/sites/config", + "apiVersion": "2016-08-01", + "name": "[concat(parameters('newWebAppName'), '/web')]", + "location": "West US", + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', parameters('newWebAppName'))]" + ], + "properties": { + "numberOfWorkers": 1, + "defaultDocuments": [ + "Default.htm", + "Default.html", + "Default.asp", + "index.htm", + "index.html", + "iisstart.htm", + "default.aspx", + "index.php", + "hostingstart.html" + ], + "netFrameworkVersion": "v4.0", + "phpVersion": "", + "pythonVersion": "", + "nodeVersion": "", + "linuxFxVersion": "PYTHON|3.7", + "requestTracingEnabled": false, + "remoteDebuggingEnabled": false, + "remoteDebuggingVersion": "VS2017", + "httpLoggingEnabled": true, + "logsDirectorySizeLimit": 35, + "detailedErrorLoggingEnabled": false, + "publishingUsername": "[variables('publishingUsername')]", + "scmType": "None", + "use32BitWorkerProcess": true, + "webSocketsEnabled": false, + "alwaysOn": false, + "appCommandLine": "gunicorn --bind=0.0.0.0 --timeout 600 main:app", + "managedPipelineMode": "Integrated", + "virtualApplications": [ + { + "virtualPath": "/", + "physicalPath": "site\\wwwroot", + "preloadEnabled": false, + "virtualDirectories": null + } + ], + "winAuthAdminState": 0, + "winAuthTenantState": 0, + "customAppPoolIdentityAdminState": false, + "customAppPoolIdentityTenantState": false, + "loadBalancing": "LeastRequests", + "routingRules": [], + "experiments": { + "rampUpRules": [] + }, + "autoHealEnabled": false, + "vnetName": "", + "minTlsVersion": "1.2", + "ftpsState": "AllAllowed", + "reservedInstanceCount": 0 + } + } + ] +} \ No newline at end of file From 796f4599a51efb8e55d5c9c30b1ef8e2bce177c9 Mon Sep 17 00:00:00 2001 From: stevengum <14935595+stevengum@users.noreply.github.com> Date: Sun, 23 Jun 2019 16:02:36 -0700 Subject: [PATCH 2/4] fix conflict in config.py --- samples/python-flask/13.core-bot/config.py | 13 +-- .../exported_template.json | 85 ++++++++++++++++--- 2 files changed, 78 insertions(+), 20 deletions(-) diff --git a/samples/python-flask/13.core-bot/config.py b/samples/python-flask/13.core-bot/config.py index 612a2d73d..6fc74978d 100644 --- a/samples/python-flask/13.core-bot/config.py +++ b/samples/python-flask/13.core-bot/config.py @@ -2,13 +2,14 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -""" Bot Configuration """ +import os + class DefaultConfig(object): """ Bot Configuration """ PORT = 3978 - APP_ID = "" - APP_PASSWORD = "" - LUIS_APP_ID = "" - LUIS_API_KEY = "" + APP_ID = os.environ.get("MicrosoftAppId", "") + APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "") + LUIS_APP_ID = os.environ.get("LuisAppId", "") + LUIS_API_KEY = os.environ.get("LuisAPIKey", "") # LUIS endpoint host name, ie "https://westus.api.cognitive.microsoft.com" - LUIS_API_HOST_NAME = "" + LUIS_API_HOST_NAME = os.environ.get("LuisAPIHostName", "") diff --git a/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json b/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json index d47131150..bff8c096d 100644 --- a/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json +++ b/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json @@ -14,11 +14,17 @@ "description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings." } }, - "newWebAppName": { + "botId": { "type": "string", - "defaultValue": "", "metadata": { - "description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"." + "description": "The globally unique and immutable bot ID. Also used to configure the displayName of the bot, which is mutable." + } + }, + "botSku": { + "defaultValue": "F0", + "type": "string", + "metadata": { + "description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1." } }, "newAppServicePlanName": { @@ -46,22 +52,43 @@ "metadata": { "description": "The location of the App Service Plan." } + }, + "existingAppServicePlan": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "Name of the existing App Service Plan used to create the Web App for the bot." + } + }, + "newWebAppName": { + "type": "string", + "defaultValue": "", + "metadata": { + "description": "The globally unique name of the Web App. Defaults to the value passed in for \"botId\"." + } } }, "variables": { + "defaultAppServicePlanName": "[if(empty(parameters('existingAppServicePlan')), 'createNewAppServicePlan', parameters('existingAppServicePlan'))]", + "useExistingAppServicePlan": "[not(equals(variables('defaultAppServicePlanName'), 'createNewAppServicePlan'))]", + "servicePlanName": "[if(variables('useExistingAppServicePlan'), parameters('existingAppServicePlan'), parameters('newAppServicePlanName'))]", "publishingUsername": "[concat('$', parameters('newWebAppName'))]", - "resourcesLocation": "[parameters('appServicePlanLocation')]" + "resourcesLocation": "[parameters('appServicePlanLocation')]", + "webAppName": "[if(empty(parameters('newWebAppName')), parameters('botId'), parameters('newWebAppName'))]", + "siteHost": "[concat(variables('webAppName'), '.azurewebsites.net')]", + "botEndpoint": "[concat('https://', variables('siteHost'), '/api/messages')]" }, "resources": [ { + "comments": "Create a new Linux App Service Plan if no existing App Service Plan name was passed in.", "type": "Microsoft.Web/serverfarms", "apiVersion": "2016-09-01", - "name": "[parameters('newAppServicePlanName')]", + "name": "[variables('servicePlanName')]", "location": "[variables('resourcesLocation')]", "sku": "[parameters('newAppServicePlanSku')]", "kind": "linux", "properties": { - "name": "[parameters('newAppServicePlanName')]", + "name": "[variables('servicePlanName')]", "perSiteScaling": false, "reserved": true, "targetWorkerCount": 0, @@ -69,12 +96,13 @@ } }, { + "comments": "Create a Web App using a Linux App Service Plan", "type": "Microsoft.Web/sites", "apiVersion": "2016-08-01", - "name": "[parameters('newWebAppName')]", + "name": "[variables('webAppName')]", "location": "[variables('resourcesLocation')]", "dependsOn": [ - "[resourceId('Microsoft.Web/serverfarms', parameters('newAppServicePlanName'))]" + "[resourceId('Microsoft.Web/serverfarms/', variables('servicePlanName'))]" ], "kind": "app,linux", "properties": { @@ -91,7 +119,7 @@ "hostType": "Repository" } ], - "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('newAppServicePlanName'))]", + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]", "reserved": true, "scmSiteAlsoStopped": false, "clientAffinityEnabled": false, @@ -114,17 +142,23 @@ "name": "SCM_DO_BUILD_DURING_DEPLOYMENT", "value": "true" } - ] + ], + "cors": { + "allowedOrigins": [ + "https://botservice.hosting.portal.azure.net", + "https://hosting.onecloud.azure-test.net/" + ] + } } } }, { "type": "Microsoft.Web/sites/config", "apiVersion": "2016-08-01", - "name": "[concat(parameters('newWebAppName'), '/web')]", - "location": "West US", + "name": "[concat(variables('webAppName'), '/web')]", + "location": "[variables('resourcesLocation')]", "dependsOn": [ - "[resourceId('Microsoft.Web/sites', parameters('newWebAppName'))]" + "[resourceId('Microsoft.Web/sites', variables('webAppName'))]" ], "properties": { "numberOfWorkers": 1, @@ -155,7 +189,7 @@ "use32BitWorkerProcess": true, "webSocketsEnabled": false, "alwaysOn": false, - "appCommandLine": "gunicorn --bind=0.0.0.0 --timeout 600 main:app", + "appCommandLine": "", "managedPipelineMode": "Integrated", "virtualApplications": [ { @@ -180,6 +214,29 @@ "ftpsState": "AllAllowed", "reservedInstanceCount": 0 } + }, + { + "apiVersion": "2017-12-01", + "type": "Microsoft.BotService/botServices", + "name": "[parameters('botId')]", + "location": "global", + "kind": "bot", + "sku": { + "name": "[parameters('botSku')]" + }, + "properties": { + "name": "[parameters('botId')]", + "displayName": "[parameters('botId')]", + "endpoint": "[variables('botEndpoint')]", + "msaAppId": "[parameters('appId')]", + "developerAppInsightsApplicationId": null, + "developerAppInsightKey": null, + "publishingCredentials": null, + "storageResourceId": null + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/sites/', variables('webAppName'))]" + ] } ] } \ No newline at end of file From c2b929845af8301b11b04700fb6f1aaba1278028 Mon Sep 17 00:00:00 2001 From: stevengum <14935595+stevengum@users.noreply.github.com> Date: Sun, 23 Jun 2019 16:10:12 -0700 Subject: [PATCH 3/4] rename ARM template in flask core-bot --- .../{exported_template.json => template-with-preexisting-rg.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/python-flask/13.core-bot/deploymentTemplates/{exported_template.json => template-with-preexisting-rg.json} (100%) diff --git a/samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json b/samples/python-flask/13.core-bot/deploymentTemplates/template-with-preexisting-rg.json similarity index 100% rename from samples/python-flask/13.core-bot/deploymentTemplates/exported_template.json rename to samples/python-flask/13.core-bot/deploymentTemplates/template-with-preexisting-rg.json From 8f4a98d3557589ff1e54af81ccb9a26c1795b4e5 Mon Sep 17 00:00:00 2001 From: stevengum <14935595+stevengum@users.noreply.github.com> Date: Wed, 26 Jun 2019 00:01:21 -0700 Subject: [PATCH 4/4] add back docstring in config.py for flask core-bot --- samples/python-flask/13.core-bot/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/python-flask/13.core-bot/config.py b/samples/python-flask/13.core-bot/config.py index 6fc74978d..b8ff72672 100644 --- a/samples/python-flask/13.core-bot/config.py +++ b/samples/python-flask/13.core-bot/config.py @@ -4,6 +4,7 @@ import os +""" Bot Configuration """ class DefaultConfig(object): """ Bot Configuration """ PORT = 3978