Skip to content

Commit 3502bd7

Browse files
authored
Merge pull request #83 from Azure-Samples/howie/fix-deploy-to-azure
Howie/fix deploy to azure
2 parents 01504e3 + 3358511 commit 3502bd7

14 files changed

+202
-1224
lines changed

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The app code runs in Azure Container apps to process the user input and generate
2525

2626
### Quick Deploy
2727

28-
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/get-started-with-ai-agents) | [![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/get-started-with-ai-agents) |
28+
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/get-started-with-ai-agents) | [![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/get-started-with-ai-agents) |
2929
|---|---|
3030

3131
Github Codespaces and Dev Containers both allow you to download and deploy the code for development. You can also continue with local development. Once you have selected your environment, follow the instructions below to customize and deploy your solution.
@@ -50,6 +50,7 @@ Make sure the following tools are installed:
5050
2. [Python 3.9+](https://www.python.org/downloads/)
5151
3. [Git](https://git-scm.com/downloads)
5252
4. [Docker Desktop](https://www.docker.com/products/docker-desktop/)
53+
5. \[Windows Only\] [PowerShell](https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-windows) of the latest version, needed only for local application development on Windows operation system. Please make sure that power shell executable `pwsh.exe` is added to the `PATH` variable.
5354

5455
## Configure your Environment
5556

@@ -246,7 +247,7 @@ Once you've opened the project in [Codespaces](#github-codespaces) or in [Dev Co
246247
```
247248
⚠️ If you do not increase your quota, you may encounter rate limit issues. If needed, you can increase the quota after deployment by editing your model in the Models and Endpoints tab of the [Azure AI Foundry Portal](https://ai.azure.com/).
248249
249-
3. Provision and deploy all the resources by running the following in get-started-with-ai-agents directory:
250+
3. Provision and deploy all the resources with public docker image `azdtemplate.azurecr.io/get-start-with-ai-agents:latest` by running the following in get-started-with-ai-agents directory:
250251
251252
```shell
252253
azd up
@@ -273,20 +274,10 @@ Once you've opened the project in [Codespaces](#github-codespaces) or in [Dev Co
273274
* In the [Azure Portal](https://portal.azure.com/), navigate to your environment's resource group. The name will be `rg-[your environment name]`. Here, you should see your container app, storage account, and all of the other [resources](#resources) that are created in the deployment.
274275
* In the [Azure AI Foundry Portal](https://ai.azure.com/), select your project. If you navigate to the Assistants tab, you should be able to view your new assistant, named `agent-template-assistant`. If you navigate to the Models and Endpoints tab, you should see your AI Services connection with your model deployments.
275276
276-
7. (Optional) If you make further modification to the app code, you can deploy the updated version with:
277+
7. (Optional) You can use a local development server to test app changes locally. To do so, follow the steps in [local deployment server](#local-development-server) after your app is deployed.
277278
278-
```shell
279-
azd deploy
280-
```
281-
You can get more detailed output with the ```--debug``` parameter.
282-
```shell
283-
azd deploy --debug
284-
```
285-
>**Important:**
286-
>
287-
>Check carefully for any errors during deployment and the startup phase of the Azure Container App. If the container fails to start correctly after deployment, the application changes you made will not take effect, and Azure Container Apps will continue serving requests from the previous stable revision.
279+
8. (Optional) Follow this [tutorial](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-quick-task) to build your changes into a Docker image and deploy to Azure Container App.
288280
289-
8. (Optional) You can use a local development server to test app changes locally. To do so, follow the steps in [local deployment server](#local-development-server) after your app is deployed.
290281
291282
## Resource Clean-up
292283

azure.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ name: azd-get-started-with-ai-agents
66
metadata:
77
88

9-
services:
10-
api_and_frontend:
11-
project: ./src
12-
language: py
13-
host: containerapp
14-
docker:
15-
image: api-and-frontend
16-
remoteBuild: true
17-
189
hooks:
1910
postprovision:
2011
windows:

infra/api.bicep

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ param tags object = {}
44

55
param identityName string
66
param containerAppsEnvironmentName string
7-
param containerRegistryName string
8-
param serviceName string = 'api'
9-
param exists bool
107
param projectConnectionString string
118
param agentDeploymentName string
129
param searchConnectionName string
@@ -16,6 +13,7 @@ param embeddingDeploymentDimensions string
1613
param searchServiceEndpoint string
1714
param agentName string
1815
param agentID string
16+
param projectName string
1917

2018
resource apiIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
2119
name: identityName
@@ -69,24 +67,21 @@ var env = [
6967
}
7068
]
7169

72-
var module_name = replace(serviceName, ' ', '-')
7370

7471
module app 'core/host/container-app-upsert.bicep' = {
75-
name: '${module_name}-container-app-module'
72+
name: 'container-app-module'
7673
params: {
7774
name: name
7875
location: location
79-
tags: union(tags, { 'azd-service-name': serviceName })
76+
tags: tags
8077
identityName: apiIdentity.name
81-
exists: exists
8278
containerAppsEnvironmentName: containerAppsEnvironmentName
83-
containerRegistryName: containerRegistryName
8479
targetPort: 50505
8580
env: env
81+
projectName: projectName
8682
}
8783
}
8884

8985
output SERVICE_API_IDENTITY_PRINCIPAL_ID string = apiIdentity.properties.principalId
9086
output SERVICE_API_NAME string = app.outputs.name
9187
output SERVICE_API_URI string = app.outputs.uri
92-
output SERVICE_API_IMAGE_NAME string = app.outputs.imageName

infra/core/ai/hub-dependencies.bicep

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ param aiServiceModelDeployments array = []
1313
param logAnalyticsName string = ''
1414
@description('Name of the Application Insights instance')
1515
param applicationInsightsName string = ''
16-
@description('Name of the container registry')
17-
param containerRegistryName string = ''
1816
@description('Name of the Azure Cognitive Search service')
1917
param searchServiceName string = ''
2018

@@ -114,15 +112,6 @@ module applicationInsights '../monitor/applicationinsights.bicep' =
114112
}
115113
}
116114

117-
module containerRegistry '../host/container-registry.bicep' =
118-
if (!empty(containerRegistryName)) {
119-
name: 'containerRegistry'
120-
params: {
121-
location: location
122-
tags: tags
123-
name: containerRegistryName
124-
}
125-
}
126115

127116
module cognitiveServices '../ai/cognitiveservices.bicep' = {
128117
name: 'cognitiveServices'
@@ -154,10 +143,6 @@ output keyVaultEndpoint string = keyVault.outputs.endpoint
154143
output storageAccountId string = storageAccount.outputs.id
155144
output storageAccountName string = storageAccount.outputs.name
156145

157-
output containerRegistryId string = !empty(containerRegistryName) ? containerRegistry.outputs.id : ''
158-
output containerRegistryName string = !empty(containerRegistryName) ? containerRegistry.outputs.name : ''
159-
output containerRegistryEndpoint string = !empty(containerRegistryName) ? containerRegistry.outputs.loginServer : ''
160-
161146
output applicationInsightsId string = !empty(applicationInsightsName) ? applicationInsights.outputs.id : ''
162147
output applicationInsightsName string = !empty(applicationInsightsName) ? applicationInsights.outputs.name : ''
163148
output logAnalyticsWorkspaceId string = !empty(logAnalyticsName) ? logAnalytics.outputs.id : ''

infra/core/ai/hub.bicep

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ param storageAccountId string
88
param keyVaultId string
99
@description('The application insights ID to use for the AI Foundry Hub Resource')
1010
param applicationInsightsId string = ''
11-
@description('The container registry ID to use for the AI Foundry Hub Resource')
12-
param containerRegistryId string = ''
1311
@description('The AI Services account name to use for the AI Foundry Hub Resource')
1412
param aiServicesName string
1513
@description('The AI Services connection name to use for the AI Foundry Hub Resource')
@@ -49,7 +47,6 @@ resource hub 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' =
4947
storageAccount: storageAccountId
5048
keyVault: keyVaultId
5149
applicationInsights: !empty(applicationInsightsId) ? applicationInsightsId : null
52-
containerRegistry: !empty(containerRegistryId) ? containerRegistryId : null
5350
hbiWorkspace: false
5451
managedNetwork: {
5552
isolationMode: 'Disabled'

infra/core/host/ai-environment.bicep

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module hubDependencies '../ai/hub-dependencies.bicep' = {
3535
tags: tags
3636
keyVaultName: keyVaultName
3737
storageAccountName: storageAccountName
38-
containerRegistryName: containerRegistryName
3938
applicationInsightsName: applicationInsightsName
4039
logAnalyticsName: logAnalyticsName
4140
aiServicesName: aiServicesName
@@ -53,7 +52,6 @@ module hub '../ai/hub.bicep' = {
5352
displayName: hubName
5453
keyVaultId: hubDependencies.outputs.keyVaultId
5554
storageAccountId: hubDependencies.outputs.storageAccountId
56-
containerRegistryId: hubDependencies.outputs.containerRegistryId
5755
applicationInsightsId: hubDependencies.outputs.applicationInsightsId
5856
aiServicesName: hubDependencies.outputs.aiServicesName
5957
aiServicesConnectionName: aiServicesConnectionName
@@ -94,10 +92,6 @@ output keyVaultEndpoint string = hubDependencies.outputs.keyVaultEndpoint
9492
output applicationInsightsName string = hubDependencies.outputs.applicationInsightsName
9593
output logAnalyticsWorkspaceName string = hubDependencies.outputs.logAnalyticsWorkspaceName
9694

97-
// Container Registry
98-
output containerRegistryName string = hubDependencies.outputs.containerRegistryName
99-
output containerRegistryEndpoint string = hubDependencies.outputs.containerRegistryEndpoint
100-
10195
// Storage Account
10296
output storageAccountName string = hubDependencies.outputs.storageAccountName
10397

infra/core/host/container-app-upsert.bicep

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ param containerMinReplicas int = 1
2323
@description('The name of the container')
2424
param containerName string = 'main'
2525

26-
@description('The name of the container registry')
27-
param containerRegistryName string = ''
28-
29-
@description('Hostname suffix for container registry. Set when deploying to sovereign clouds')
30-
param containerRegistryHostSuffix string = 'azurecr.io'
31-
3226
@allowed([ 'http', 'grpc' ])
3327
@description('The protocol used by Dapr to connect to the app, e.g., HTTP or gRPC')
3428
param daprAppProtocol string = 'http'
@@ -39,9 +33,6 @@ param daprEnabled bool = false
3933
@description('The Dapr app ID')
4034
param daprAppId string = containerName
4135

42-
@description('Specifies if the resource already exists')
43-
param exists bool = false
44-
4536
@description('Specifies if Ingress is enabled for the container app')
4637
param ingressEnabled bool = true
4738

@@ -52,9 +43,6 @@ param identityType string = 'None'
5243
@description('The name of the user-assigned identity')
5344
param identityName string = ''
5445

55-
@description('The name of the container image')
56-
param imageName string = ''
57-
5846
@description('The secrets required for the container')
5947
@secure()
6048
param secrets object = {}
@@ -71,9 +59,8 @@ param serviceBinds array = []
7159
@description('The target port for the container')
7260
param targetPort int = 80
7361

74-
resource existingApp 'Microsoft.App/containerApps@2023-05-02-preview' existing = if (exists) {
75-
name: name
76-
}
62+
param projectName string
63+
7764

7865
module app 'container-app.bicep' = {
7966
name: '${deployment().name}-update'
@@ -86,8 +73,6 @@ module app 'container-app.bicep' = {
8673
ingressEnabled: ingressEnabled
8774
containerName: containerName
8875
containerAppsEnvironmentName: containerAppsEnvironmentName
89-
containerRegistryName: containerRegistryName
90-
containerRegistryHostSuffix: containerRegistryHostSuffix
9176
containerCpuCoreCount: containerCpuCoreCount
9277
containerMemory: containerMemory
9378
containerMinReplicas: containerMinReplicas
@@ -98,13 +83,12 @@ module app 'container-app.bicep' = {
9883
secrets: secrets
9984
external: external
10085
env: env
101-
imageName: !empty(imageName) ? imageName : exists ? existingApp.properties.template.containers[0].image : ''
10286
targetPort: targetPort
10387
serviceBinds: serviceBinds
88+
dependOn: projectName
10489
}
10590
}
10691

10792
output defaultDomain string = app.outputs.defaultDomain
108-
output imageName string = app.outputs.imageName
10993
output name string = app.outputs.name
11094
output uri string = app.outputs.uri

infra/core/host/container-app.bicep

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ param containerMinReplicas int = 1
2525
@description('The name of the container')
2626
param containerName string = 'main'
2727

28-
@description('The name of the container registry')
29-
param containerRegistryName string = ''
30-
31-
@description('Hostname suffix for container registry. Set when deploying to sovereign clouds')
32-
param containerRegistryHostSuffix string = 'azurecr.io'
33-
3428
@description('The protocol used by Dapr to connect to the app, e.g., http or grpc')
3529
@allowed([ 'http', 'grpc' ])
3630
param daprAppProtocol string = 'http'
@@ -54,14 +48,14 @@ param identityName string = ''
5448
@allowed([ 'None', 'SystemAssigned', 'UserAssigned' ])
5549
param identityType string = 'None'
5650

57-
@description('The name of the container image')
58-
param imageName string = ''
5951

6052
@description('Specifies if Ingress is enabled for the container app')
6153
param ingressEnabled bool = true
6254

6355
param revisionMode string = 'Single'
6456

57+
param dependOn string = ''
58+
6559
@description('The secrets required for the container')
6660
@secure()
6761
param secrets object = {}
@@ -79,20 +73,9 @@ resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-
7973
name: identityName
8074
}
8175

82-
// Private registry support requires both an ACR name and a User Assigned managed identity
83-
var usePrivateRegistry = !empty(identityName) && !empty(containerRegistryName)
84-
8576
// Automatically set to `UserAssigned` when an `identityName` has been set
8677
var normalizedIdentityType = !empty(identityName) ? 'UserAssigned' : identityType
8778

88-
module containerRegistryAccess '../security/registry-access.bicep' = if (usePrivateRegistry) {
89-
name: '${deployment().name}-registry-access'
90-
params: {
91-
containerRegistryName: containerRegistryName
92-
principalId: usePrivateRegistry ? userIdentity.properties.principalId : ''
93-
}
94-
}
95-
9679
resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
9780
name: name
9881
location: location
@@ -101,7 +84,7 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
10184
// otherwise the container app will throw a provision error
10285
// This also forces us to use an user assigned managed identity since there would no way to
10386
// provide the system assigned identity with the ACR pull access before the app is created
104-
dependsOn: usePrivateRegistry ? [ containerRegistryAccess ] : []
87+
dependsOn: empty(dependOn)? [] : [dependOn]
10588
identity: {
10689
type: normalizedIdentityType
10790
userAssignedIdentities: !empty(identityName) && normalizedIdentityType == 'UserAssigned' ? { '${userIdentity.id}': {} } : null
@@ -129,18 +112,13 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
129112
value: secret.value
130113
}]
131114
service: !empty(serviceType) ? { type: serviceType } : null
132-
registries: usePrivateRegistry ? [
133-
{
134-
server: '${containerRegistryName}.${containerRegistryHostSuffix}'
135-
identity: userIdentity.id
136-
}
137-
] : []
115+
registries: []
138116
}
139117
template: {
140118
serviceBinds: !empty(serviceBinds) ? serviceBinds : null
141119
containers: [
142120
{
143-
image: !empty(imageName) ? imageName : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
121+
image: 'azdtemplate.azurecr.io/get-start-with-ai-agents:latest'
144122
name: containerName
145123
env: env
146124
resources: {
@@ -163,7 +141,6 @@ resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01'
163141

164142
output defaultDomain string = containerAppsEnvironment.properties.defaultDomain
165143
output identityPrincipalId string = normalizedIdentityType == 'None' ? '' : (empty(identityName) ? app.identity.principalId : userIdentity.properties.principalId)
166-
output imageName string = imageName
167144
output name string = app.name
168145
output serviceBind object = !empty(serviceType) ? { serviceId: app.id, name: name } : {}
169146
output uri string = ingressEnabled ? 'https://${app.properties.configuration.ingress.fqdn}' : ''

infra/core/host/container-apps.bicep

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
metadata description = 'Creates an Azure Container Registry and an Azure Container Apps environment.'
1+
metadata description = 'Creates an Azure Container Apps environment.'
22
param name string
33
param location string = resourceGroup().location
44
param tags object = {}
55

66
param containerAppsEnvironmentName string
7-
param containerRegistryName string
8-
param containerRegistryResourceGroupName string = ''
9-
param containerRegistryAdminUserEnabled bool = false
107
param logAnalyticsWorkspaceName string
118
param applicationInsightsName string = ''
129

@@ -21,20 +18,7 @@ module containerAppsEnvironment 'container-apps-environment.bicep' = {
2118
}
2219
}
2320

24-
module containerRegistry 'container-registry.bicep' = {
25-
name: '${name}-container-registry'
26-
scope: !empty(containerRegistryResourceGroupName) ? resourceGroup(containerRegistryResourceGroupName) : resourceGroup()
27-
params: {
28-
name: containerRegistryName
29-
location: location
30-
adminUserEnabled: containerRegistryAdminUserEnabled
31-
tags: tags
32-
}
33-
}
34-
3521
output defaultDomain string = containerAppsEnvironment.outputs.defaultDomain
3622
output environmentName string = containerAppsEnvironment.outputs.name
3723
output environmentId string = containerAppsEnvironment.outputs.id
3824

39-
output registryLoginServer string = containerRegistry.outputs.loginServer
40-
output registryName string = containerRegistry.outputs.name

0 commit comments

Comments
 (0)