Skip to content

Commit 5a85fbc

Browse files
MehakBindraMehak Bindra
andauthored
Config changes for python deployment - dev env (#346)
1. add env.dev file, so ATK displays the option of "dev" env 2. Use Single tenant auth 3. Made python specific changes - use linux instead of windows for webapp, generate requirements.txt before deployment, use python main.py as startup command Co-authored-by: Mehak Bindra <[email protected]>
1 parent 3054ad0 commit 5a85fbc

File tree

5 files changed

+106
-52
lines changed

5 files changed

+106
-52
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Built-in environment variables
2+
TEAMSFX_ENV=dev
3+
APP_NAME_SUFFIX=dev
4+
5+
# Updating AZURE_SUBSCRIPTION_ID or AZURE_RESOURCE_GROUP_NAME after provision may also require an update to RESOURCE_SUFFIX, because some services require a globally unique name across subscriptions/resource groups.
6+
AZURE_SUBSCRIPTION_ID=
7+
AZURE_RESOURCE_GROUP_NAME=
8+
RESOURCE_SUFFIX=
9+
10+
TEAMS_APP_ID=
11+
TEAMS_APP_TENANT_ID=
12+
BOT_ID=
13+
AAD_APP_OBJECT_ID=
14+
AAD_APP_TENANT_ID=
15+
BOT_AZURE_APP_SERVICE_RESOURCE_ID=
16+
BOT_DOMAIN=

packages/cli/configs/atk/basic/python/infra/azure.bicep

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,84 @@
33
@description('Used to generate names for all resources in this file')
44
param resourceBaseName string
55

6-
param webAppSKU string
6+
@description('Required when create Azure Bot service')
7+
param botAadAppClientId string
8+
9+
@secure()
10+
@description('Required by Bot Framework package in your bot project')
11+
param botAadAppClientSecret string
712

813
@maxLength(42)
914
param botDisplayName string
1015

16+
param webAppSKU string
17+
param linuxFxVersion string
18+
param tenantId string
19+
1120
param serverfarmsName string = resourceBaseName
1221
param webAppName string = resourceBaseName
13-
param identityName string = resourceBaseName
1422
param location string = resourceGroup().location
15-
16-
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
17-
location: location
18-
name: identityName
19-
}
23+
param pythonVersion string = linuxFxVersion
2024

2125
// Compute resources for your Web App
2226
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
23-
kind: 'app'
27+
kind: 'app,linux'
2428
location: location
2529
name: serverfarmsName
2630
sku: {
2731
name: webAppSKU
2832
}
33+
properties:{
34+
reserved: true
35+
}
2936
}
3037

3138
// Web App that hosts your agent
39+
// Web App that hosts your bot
3240
resource webApp 'Microsoft.Web/sites@2021-02-01' = {
33-
kind: 'app'
41+
kind: 'app,linux'
3442
location: location
3543
name: webAppName
3644
properties: {
3745
serverFarmId: serverfarm.id
38-
httpsOnly: true
3946
siteConfig: {
4047
alwaysOn: true
48+
appCommandLine: 'python main.py'
49+
linuxFxVersion: pythonVersion
4150
appSettings: [
4251
{
43-
name: 'WEBSITE_RUN_FROM_PACKAGE'
44-
value: '1'
45-
}
46-
{
47-
name: 'WEBSITE_PYTHON_VERSION'
48-
value: '3.11'
52+
name: 'SCM_DO_BUILD_DURING_DEPLOYMENT'
53+
value: 'true'
4954
}
5055
{
51-
name: 'RUNNING_ON_AZURE'
52-
value: '1'
56+
name: 'CLIENT_ID'
57+
value: botAadAppClientId
5358
}
5459
{
55-
name: 'BOT_ID'
56-
value: identity.properties.clientId
60+
name: 'CLIENT_SECRET'
61+
value: botAadAppClientSecret
5762
}
5863
{
59-
name: 'BOT_TENANT_ID'
60-
value: identity.properties.tenantId
64+
name: 'TENANT_ID'
65+
value: tenantId
6166
}
6267
]
6368
ftpsState: 'FtpsOnly'
6469
}
6570
}
66-
identity: {
67-
type: 'UserAssigned'
68-
userAssignedIdentities: {
69-
'${identity.id}': {}
70-
}
71-
}
7271
}
7372

7473
// Register your web service as a bot with the Bot Framework
7574
module azureBotRegistration './botRegistration/azurebot.bicep' = {
7675
name: 'Azure-Bot-registration'
7776
params: {
7877
resourceBaseName: resourceBaseName
79-
identityClientId: identity.properties.clientId
80-
identityResourceId: identity.id
81-
identityTenantId: identity.properties.tenantId
78+
botAadAppClientId: botAadAppClientId
8279
botAppDomain: webApp.properties.defaultHostName
8380
botDisplayName: botDisplayName
81+
tenantId: tenantId
8482
}
8583
}
8684

8785
output BOT_AZURE_APP_SERVICE_RESOURCE_ID string = webApp.id
8886
output BOT_DOMAIN string = webApp.properties.defaultHostName
89-
output BOT_ID string = identity.properties.clientId
90-
output BOT_TENANT_ID string = identity.properties.tenantId

packages/cli/configs/atk/basic/python/infra/azure.parameters.json.hbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"webAppSKU": {
99
"value": "B1"
1010
},
11+
"botAadAppClientId": {
12+
"value": "$\{{BOT_ID}}"
13+
},
14+
"botAadAppClientSecret": {
15+
"value": "$\{{SECRET_BOT_PASSWORD}}"
16+
},
17+
"tenantId": {
18+
"value": "$\{{AAD_APP_TENANT_ID}}"
19+
},
20+
"linuxFxVersion": {
21+
"value": "PYTHON|3.12"
22+
},
1123
"botDisplayName": {
1224
"value": "{{ toPascalCase name }}Infra"
1325
}

packages/cli/configs/atk/basic/python/infra/botRegistration/azurebot.bicep

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ param botDisplayName string
88

99
param botServiceName string = resourceBaseName
1010
param botServiceSku string = 'F0'
11-
param identityResourceId string
12-
param identityClientId string
13-
param identityTenantId string
11+
param botAadAppClientId string
1412
param botAppDomain string
13+
param tenantId string
1514

1615
// Register your web service as a bot with the Bot Framework
1716
resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
@@ -21,10 +20,9 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
2120
properties: {
2221
displayName: botDisplayName
2322
endpoint: 'https://${botAppDomain}/api/messages'
24-
msaAppId: identityClientId
25-
msaAppMSIResourceId: identityResourceId
26-
msaAppTenantId: identityTenantId
27-
msaAppType: 'UserAssignedMSI'
23+
msaAppId: botAadAppClientId
24+
msaAppType: 'SingleTenant'
25+
msaAppTenantId: tenantId
2826
}
2927
sku: {
3028
name: botServiceSku

packages/cli/configs/atk/basic/python/teamsapp.yml.hbs

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,52 @@ provision:
2020
writeToEnvironmentFile:
2121
teamsAppId: TEAMS_APP_ID
2222

23-
# Automates the creation an Azure AD app registration which is required for a bot.
24-
# The Bot ID (AAD app client ID) and Bot Password (AAD app client secret) are saved to an environment file.
25-
- uses: botAadApp/create
23+
# Creates a new Microsoft Entra app to authenticate users if
24+
# the environment variable that stores clientId is empty
25+
- uses: aadApp/create
2626
with:
27-
name: {{ toPascalCase name }}$\{{APP_NAME_SUFFIX}}
27+
# Note: when you run aadApp/update, the Microsoft Entra app name will be updated
28+
# based on the definition in manifest. If you don't want to change the
29+
# name, make sure the name in Microsoft Entra manifest is the same with the name
30+
# defined here.
31+
name: {{ toPascalCase name }}$\{{APP_NAME_SUFFIX}}
32+
# If the value is false, the driver will not generate client secret for you
33+
generateClientSecret: true
34+
# organization's Microsoft Entra tenant (for example, single tenant).
35+
signInAudience: AzureADMultipleOrgs
36+
# Write the information of created resources into environment file for the
37+
# specified environment variable(s).
2838
writeToEnvironmentFile:
29-
botId: BOT_ID
30-
botPassword: SECRET_BOT_PASSWORD
39+
clientId: BOT_ID
40+
# Environment variable that starts with `SECRET_` will be stored to the
41+
# .env.{envName}.user environment file
42+
clientSecret: SECRET_BOT_PASSWORD
43+
objectId: AAD_APP_OBJECT_ID
44+
tenantId: AAD_APP_TENANT_ID
3145

32-
# Automates the creation of infrastructure defined in ARM templates to host the bot.
33-
# The created resource IDs are saved to an environment file.
34-
- uses: arm/deploy
46+
- uses: arm/deploy # Deploy given ARM templates parallelly.
3547
with:
48+
# AZURE_SUBSCRIPTION_ID is a built-in environment variable,
49+
# if its value is empty, TeamsFx will prompt you to select a subscription.
50+
# Referencing other environment variables with empty values
51+
# will skip the subscription selection prompt.
3652
subscriptionId: $\{{AZURE_SUBSCRIPTION_ID}}
53+
# AZURE_RESOURCE_GROUP_NAME is a built-in environment variable,
54+
# if its value is empty, TeamsFx will prompt you to select or create one
55+
# resource group.
56+
# Referencing other environment variables with empty values
57+
# will skip the resource group selection prompt.
3758
resourceGroupName: $\{{AZURE_RESOURCE_GROUP_NAME}}
3859
templates:
39-
- path: ./infra/azure.bicep
60+
- path: ./infra/azure.bicep # Relative path to this file
61+
# Relative path to this yaml file.
62+
# Placeholders will be replaced with corresponding environment
63+
# variable before ARM deployment.
4064
parameters: ./infra/azure.parameters.json
41-
deploymentName: Create-resources-for-tab
65+
# Required when deploying ARM template
66+
deploymentName: Create-resources-for-bot
67+
# M365 Agents Toolkit will download this bicep CLI version from github for you,
68+
# will use bicep CLI in PATH if you remove this config.
4269
bicepCliVersion: v0.9.1
4370

4471
# Optional: Automates schema and error checking of the Teams app manifest and outputs the results in the console.
@@ -65,10 +92,15 @@ provision:
6592
appPackagePath: ./appPackage/build/appPackage.$\{{TEAMSFX_ENV}}.zip
6693

6794
deploy:
95+
- uses: script
96+
with:
97+
run: |
98+
uv sync
99+
uv export --no-hashes -o src/requirements.txt
68100
# Deploy to an Azure App Service using the zip file created in the provision step.
69101
- uses: azureAppService/zipDeploy
70102
with:
71-
artifactFolder: .
103+
artifactFolder: src
72104
ignoreFile: .webappignore
73105
# This example uses the env var thats generated by the arm/deploy action.
74106
# You can replace it with an existing Azure Resource ID or other

0 commit comments

Comments
 (0)