-
Notifications
You must be signed in to change notification settings - Fork 20
Add Bicep for Coboagent #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ming Gu (guming-learning)
wants to merge
4
commits into
main
Choose a base branch
from
coboagent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| param location string = resourceGroup().location | ||
| param tags object = {} | ||
|
|
||
| param containerRegistryName string | ||
| param serviceName string = 'cobo-agent' | ||
| param openaiEndpoint string | ||
| param openaiApiVersion string | ||
|
|
||
| @description('AI Foundry Account resource name for OpenAI access') | ||
| param aiServicesAccountName string | ||
|
|
||
| @description('AI Foundry Project name within the account') | ||
| param aiProjectName string | ||
|
|
||
| @description('Principal ID for authentication') | ||
| param authAppId string | ||
|
|
||
| var resourceToken = uniqueString(subscription().id, resourceGroup().id, location) | ||
| var prefix = 'ca-${aiProjectName}-${resourceToken}' | ||
| var containerAppsEnvironmentName = '${prefix}-env' | ||
| var containerAppName = replace(take(prefix, 32), '--', '-') | ||
| var userAssignedIdentityName = '${prefix}-id' | ||
|
|
||
| // Container Apps Environment for COBO agent | ||
| module containerAppsEnvironment '../host/container-apps-environment.bicep' = { | ||
| scope: resourceGroup() | ||
| name: 'container-apps-environment' | ||
| params: { | ||
| name: containerAppsEnvironmentName | ||
| location: location | ||
| tags: tags | ||
| } | ||
| } | ||
|
|
||
| // Get reference to the existing AI project to access its identity | ||
| resource aiAccount 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = { | ||
| name: aiServicesAccountName | ||
|
|
||
| resource project 'projects' existing = { | ||
| name: aiProjectName | ||
| } | ||
| } | ||
|
|
||
| // Using user-assigned managed identity instead of system-assigned to avoid | ||
| // the 60+ second delay required for ACR role assignment propagation. | ||
| // With user-assigned identity, we can create the identity and grant ACR access | ||
| // before creating the Container App, eliminating the delay during deployment. | ||
| resource apiIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { | ||
| name: userAssignedIdentityName | ||
| location: location | ||
| } | ||
|
|
||
| module app '../host/container-app.bicep' = { | ||
| name: '${serviceName}-container-app-module' | ||
| dependsOn: [containerAppsEnvironment] | ||
| params: { | ||
| name: containerAppName | ||
| location: location | ||
| tags: union(tags, { 'azd-service-name': serviceName }) | ||
| identityName: apiIdentity.name | ||
| containerAppsEnvironmentName: containerAppsEnvironmentName | ||
| containerRegistryName: containerRegistryName | ||
| targetPort: 8088 | ||
| imageName: '' // Empty during provision, azd deploy will update with actual image | ||
| authEnabled: true | ||
| authAppId: authAppId | ||
| authIssuerUrl: '' | ||
| authAllowedAudiences: [] | ||
| authRequireClientApp: false | ||
| secrets: [] | ||
| env: [ | ||
| { | ||
| name: 'AZURE_OPENAI_ENDPOINT' | ||
| value: openaiEndpoint | ||
| } | ||
| { | ||
| name: 'OPENAI_API_VERSION' | ||
| value: openaiApiVersion | ||
| } | ||
| { | ||
| name: 'AZURE_CLIENT_ID' | ||
| value: apiIdentity.properties.clientId | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| // Grant Container Apps Contributor role to AI Foundry Project's system-assigned identity on the Container App | ||
| // Role definition ID for "Container Apps Contributor" is: 358470bc-b998-42bd-ab17-a7e34c199c0f | ||
| module roleAssignment '../security/container-app-role.bicep' = { | ||
| name: '${serviceName}-role-assignment' | ||
| params: { | ||
| containerAppName: app.outputs.name | ||
| principalId: aiAccount::project.identity.principalId | ||
| roleDefinitionId: '358470bc-b998-42bd-ab17-a7e34c199c0f' | ||
| principalType: 'ServicePrincipal' | ||
| } | ||
| } | ||
|
|
||
| // Grant Azure AI User role to Container App's user-assigned managed identity on AI Foundry Account | ||
| // Role ID: 53ca6127-db72-4b80-b1b0-d745d6d5456d (Azure AI User) | ||
| resource aiUserRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
| name: guid(aiAccount.id, apiIdentity.id, '53ca6127-db72-4b80-b1b0-d745d6d5456d') | ||
| scope: aiAccount | ||
| properties: { | ||
| principalId: apiIdentity.properties.principalId | ||
| principalType: 'ServicePrincipal' | ||
| roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '53ca6127-db72-4b80-b1b0-d745d6d5456d') | ||
| } | ||
| } | ||
|
|
||
|
|
||
| output COBO_ACA_IDENTITY_PRINCIPAL_ID string = apiIdentity.properties.principalId | ||
| output SERVICE_API_RESOURCE_ID string = app.outputs.resourceId | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| param name string | ||
| param location string = resourceGroup().location | ||
| param tags object = {} | ||
|
|
||
| param containerAppsEnvironmentName string | ||
| param containerName string = 'main' | ||
| param containerRegistryName string | ||
|
|
||
| @description('Minimum number of replicas to run') | ||
| @minValue(1) | ||
| param containerMinReplicas int = 1 | ||
| @description('Maximum number of replicas to run') | ||
| @minValue(1) | ||
| param containerMaxReplicas int = 10 | ||
|
|
||
| param secrets array = [] | ||
| param env array = [] | ||
| param external bool = true | ||
| param imageName string | ||
| param targetPort int = 80 | ||
|
|
||
| @description('User assigned identity name') | ||
| param identityName string | ||
|
|
||
| @description('Enabled Ingress for container app') | ||
| param ingressEnabled bool = true | ||
|
|
||
| // Dapr Options | ||
| @description('Enable Dapr') | ||
| param daprEnabled bool = false | ||
| @description('Dapr app ID') | ||
| param daprAppId string = containerName | ||
| @allowed([ 'http', 'grpc' ]) | ||
| @description('Protocol used by Dapr to connect to the app, e.g. http or grpc') | ||
| param daprAppProtocol string = 'http' | ||
|
|
||
| @description('CPU cores allocated to a single container instance, e.g. 0.5') | ||
| param containerCpuCoreCount string = '0.5' | ||
|
|
||
| @description('Memory allocated to a single container instance, e.g. 1Gi') | ||
| param containerMemory string = '1.0Gi' | ||
|
|
||
| @description('Enable authentication') | ||
| param authEnabled bool = false | ||
|
|
||
| @description('Authentication App ID (client ID)') | ||
| param authAppId string = '' | ||
|
|
||
| @description('Authentication Issuer URL') | ||
| param authIssuerUrl string = '' | ||
|
|
||
| @description('Allowed token audiences') | ||
| param authAllowedAudiences array = [] | ||
|
|
||
| @description('Require client application (true) or allow requests only from this application itself (false)') | ||
| param authRequireClientApp bool = false | ||
|
|
||
| resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = { | ||
| name: identityName | ||
| } | ||
|
|
||
| module containerRegistryAccess '../security/registry-access.bicep' = { | ||
| name: '${deployment().name}-registry-access' | ||
| params: { | ||
| containerRegistryName: containerRegistryName | ||
| principalId: userIdentity.properties.principalId | ||
| } | ||
| } | ||
|
|
||
| resource app 'Microsoft.App/containerApps@2024-03-01' = { | ||
| name: name | ||
| location: location | ||
| tags: tags | ||
| // It is critical that the identity is granted ACR pull access before the app is created | ||
| // otherwise the container app will throw a provision error | ||
| // This also forces us to use an user assigned managed identity since there would no way to | ||
| // provide the system assigned identity with the ACR pull access before the app is created | ||
| dependsOn: [ containerRegistryAccess ] | ||
| identity: { | ||
| type: 'UserAssigned' | ||
| userAssignedIdentities: { '${userIdentity.id}': {} } | ||
| } | ||
| properties: { | ||
| managedEnvironmentId: containerAppsEnvironment.id | ||
| configuration: { | ||
| activeRevisionsMode: 'multiple' | ||
| ingress: ingressEnabled ? { | ||
| external: external | ||
| targetPort: targetPort | ||
| transport: 'auto' | ||
| } : null | ||
| dapr: daprEnabled ? { | ||
| enabled: true | ||
| appId: daprAppId | ||
| appProtocol: daprAppProtocol | ||
| appPort: ingressEnabled ? targetPort : 0 | ||
| } : { enabled: false } | ||
| secrets: secrets | ||
| registries: [ | ||
| { | ||
| server: '${containerRegistry.name}.azurecr.io' | ||
| identity: userIdentity.id | ||
| } | ||
| ] | ||
| } | ||
| template: { | ||
| containers: [ | ||
| { | ||
| image: !empty(imageName) ? imageName : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest' | ||
| name: containerName | ||
| env: env | ||
| resources: { | ||
| cpu: json(containerCpuCoreCount) | ||
| memory: containerMemory | ||
| } | ||
| } | ||
| ] | ||
| scale: { | ||
| minReplicas: containerMinReplicas | ||
| maxReplicas: containerMaxReplicas | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource appAuthConfig 'Microsoft.App/containerApps/authConfigs@2024-03-01' = if (authEnabled) { | ||
| name: 'current' | ||
| parent: app | ||
| properties: { | ||
| platform: { | ||
| enabled: true | ||
| } | ||
| globalValidation: { | ||
| unauthenticatedClientAction: 'Return401' | ||
| } | ||
| login: { | ||
| tokenStore: { | ||
| enabled: false | ||
| } | ||
| allowedExternalRedirectUrls: [] | ||
| } | ||
| identityProviders: { | ||
| azureActiveDirectory: { | ||
| enabled: true | ||
| registration: { | ||
| clientId: authAppId | ||
| openIdIssuer: authIssuerUrl | ||
| } | ||
| validation: { | ||
| allowedAudiences: authAllowedAudiences | ||
| defaultAuthorizationPolicy: { | ||
| allowedApplications: authRequireClientApp ? [] : [authAppId] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2024-03-01' existing = { | ||
| name: containerAppsEnvironmentName | ||
| } | ||
|
|
||
| // 2022-02-01-preview needed for anonymousPullEnabled | ||
| resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { | ||
| name: containerRegistryName | ||
| } | ||
|
|
||
| output defaultDomain string = containerAppsEnvironment.properties.defaultDomain | ||
| output imageName string = imageName | ||
| output name string = app.name | ||
| output uri string = 'https://${app.properties.configuration.ingress.fqdn}' | ||
| output resourceId string = app.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| param name string | ||
| param location string = resourceGroup().location | ||
| param tags object = {} | ||
|
|
||
| resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2024-03-01' = { | ||
| name: name | ||
| location: location | ||
| tags: tags | ||
| properties: {} | ||
| } | ||
|
|
||
| output defaultDomain string = containerAppsEnvironment.properties.defaultDomain | ||
| output name string = containerAppsEnvironment.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| param containerAppName string | ||
| param principalId string | ||
|
|
||
| @allowed([ | ||
| 'Device' | ||
| 'ForeignGroup' | ||
| 'Group' | ||
| 'ServicePrincipal' | ||
| 'User' | ||
| ]) | ||
| param principalType string = 'ServicePrincipal' | ||
| param roleDefinitionId string | ||
|
|
||
| resource containerApp 'Microsoft.App/containerApps@2024-03-01' existing = { | ||
| name: containerAppName | ||
| } | ||
|
|
||
| resource role 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
| scope: containerApp | ||
| name: guid(containerApp.id, principalId, roleDefinitionId) | ||
| properties: { | ||
| principalId: principalId | ||
| principalType: principalType | ||
| roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| param containerRegistryName string | ||
| param principalId string | ||
|
|
||
| var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') | ||
|
|
||
| resource aksAcrPull 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
| scope: containerRegistry // Use when specifying a scope that is different than the deployment scope | ||
| name: guid(subscription().id, resourceGroup().id, principalId, acrPullRole) | ||
| properties: { | ||
| roleDefinitionId: acrPullRole | ||
| principalType: 'ServicePrincipal' | ||
| principalId: principalId | ||
| } | ||
| } | ||
|
|
||
| resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { | ||
| name: containerRegistryName | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set this value to match what's in azure.yaml for ACA deployment to work:
We may need to map this from an env var in
main.parameters.jsonand set it during preprovision in the extensionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed . But where is this
azure.yaml? I don't see it in the repoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a base version https://github.com/Azure-Samples/azd-ai-starter-basic/blob/coboagent/azure.yaml, it's updated during
azd ai agent init