Skip to content

Commit

Permalink
happy path integration ok (#51)
Browse files Browse the repository at this point in the history
## Purpose
happy provision path for petclinic with open AI

## Does this introduce a breaking change?
<!-- Mark one with an "x". -->
```
[x] Yes
[ ] No
```

## Pull Request Type
What kind of change does this Pull Request introduce?

<!-- Please check the one that applies to this PR using "x". -->
```
[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:
```
  • Loading branch information
sonwan2020 authored Sep 24, 2024
1 parent 8cae078 commit 19ccef6
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 99 deletions.
45 changes: 34 additions & 11 deletions infra/bicep/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ param acrGroupName string = ''
@description('Subscription of the azure container registry.')
param acrSubscription string = ''

@description('Enable OpenAI components')
param enableOpenAi bool = false
@description('Resource group of the Open AI')
param openAiResourceGroup string
@description('Location of the Open AI')
param openAiLocation string
@description('Subscription of the Open AI')
param openAiSubscription string

@description('Name of the log analytics server. Default la-{environmentName}')
param logAnalyticsName string = ''

Expand Down Expand Up @@ -71,7 +80,7 @@ var abbrs = loadJsonContent('./abbreviations.json')
var tags = { 'azd-env-name': environmentName }

@description('Organize resources in a resource group')
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
resource rg 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
location: location
tags: tags
Expand Down Expand Up @@ -120,6 +129,17 @@ module vnet './modules/network/vnet.bicep' = {
}
}

module mysql 'modules/database/mysql.bicep' = {
name: 'mysql'
scope: rg
params: {
administratorLogin: sqlAdmin
administratorLoginPassword: sqlAdminPassword
serverName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${environmentName}'
databaseName: 'petclinic'
}
}

module logAnalytics 'modules/shared/logAnalyticsWorkspace.bicep' = {
name: 'log-analytics'
scope: rg
Expand Down Expand Up @@ -188,23 +208,25 @@ module javaComponents 'modules/containerapps/containerapp-java-components.bicep'
}
}

module mysql 'modules/database/mysql.bicep' = {
name: 'mysql'
scope: rg
// You must use modules to deploy resources to a different scope.
module rgOpenAi 'modules/shared/resourceGroup.bicep' = if (enableOpenAi) {
name: 'rg-openai'
scope: subscription(openAiSubscription)
params: {
administratorLogin: sqlAdmin
administratorLoginPassword: sqlAdminPassword
serverName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${environmentName}'
databaseName: 'petclinic'
resourceGroupName: openAiResourceGroup
resourceGroupLocation: location
}
}

module openai 'modules/ai/openai.bicep' = {
module openai 'modules/ai/openai.bicep' = if (enableOpenAi) {
name: 'openai'
scope: rg
dependsOn: [
rgOpenAi
]
scope: resourceGroup(openAiSubscription, openAiResourceGroup)
params: {
accountName: 'openai-${environmentName}'
location: location
location: openAiLocation
appPrincipalId: umiApps.outputs.principalId
}
}
Expand All @@ -228,6 +250,7 @@ module applications 'modules/app/petclinic.bicep' = {
chatAgentImage: !empty(chatAgentImage) ? chatAgentImage : placeholderImage
targetPort: 8080
applicationInsightsConnString: applicationInsights.outputs.connectionString
enableOpenAi: enableOpenAi
azureOpenAiEndpoint: openai.outputs.endpoint
openAiClientId: umiApps.outputs.id
}
Expand Down
12 changes: 12 additions & 0 deletions infra/bicep/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
},
"acrSubscription": {
"value": "<your-acr-subscription>"
},
"enableOpenAi": {
"value": true
},
"openAiResourceGroup": {
"value": "rg-openai"
},
"openAiLocation": {
"value": "westus"
},
"openAiSubscription": {
"value": "<your-openai-subscription>"
}
}
}
165 changes: 86 additions & 79 deletions infra/bicep/modules/ai/openai.bicep
Original file line number Diff line number Diff line change
@@ -1,79 +1,86 @@
@description('Required. Name of your Azure OpenAI service account. ')
param accountName string

@description('Required. Location for all resources.')
param location string

@description('Optional. model name for the TextEmbeddingAda002 language model. ')
param modelTextEmbeddingAda002 string = 'text-embedding-ada-002'

@description('Optional. model name for the gpt-4 language model. ')
param modelGpt4 string = 'gpt-4'

@description('Optional. model format for the language models. ')
param modelFormat string = 'OpenAI'

@description('Required. The principal ID of the MI for the chate agent application. ')
param appPrincipalId string

@description('Optional. The role definition ID for the Cognitive Services OpenAI User role. ')
// https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-openai-user
param roleDefinitionId string = '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'

resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: accountName
location: location
sku: {
name: 'S0'
}
kind: 'OpenAI'
properties: {
customSubDomainName: accountName
publicNetworkAccess: 'Enabled'
disableLocalAuth: true
}
}

resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
name: modelTextEmbeddingAda002
parent: account
properties: {
model: {
name: modelTextEmbeddingAda002
version: '2'
format: modelFormat
}
}
sku: {
name: 'Standard'
capacity: 1
}
}

resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
name: modelGpt4
parent: account
properties: {
model: {
name: modelGpt4
version: '0613'
format: modelFormat
}
}
sku: {
name: 'GlobalBatch'
capacity: 1
}
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
properties: {
roleDefinitionId: roleDefinitionId
principalId: appPrincipalId
principalType: 'ServicePrincipal'
}
}

output endpoint string = account.properties.endpoint
output resourceId string = account.id
targetScope = 'resourceGroup'

@description('Required. Name of your Azure OpenAI service account. ')
param accountName string

@description('Required. Location for all resources.')
param location string

@description('Optional. model name for the TextEmbeddingAda002 language model. ')
param modelTextEmbeddingAda002 string = 'text-embedding-ada-002'

@description('Optional. model name for the gpt-4 language model. ')
param modelGpt4 string = 'gpt-4'

@description('Optional. model format for the language models. ')
param modelFormat string = 'OpenAI'

@description('Required. The principal ID of the MI for the chate agent application. ')
param appPrincipalId string

@description('Optional. The role definition ID for the Cognitive Services OpenAI User role. ')
// https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-openai-user
param roleDefinitionId string = '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'

resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: accountName
location: location
sku: {
name: 'S0'
}
kind: 'OpenAI'
properties: {
customSubDomainName: accountName
publicNetworkAccess: 'Enabled'
disableLocalAuth: true
}
}

resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
name: modelTextEmbeddingAda002
parent: account
properties: {
model: {
name: modelTextEmbeddingAda002
version: '2'
format: modelFormat
}
}
sku: {
name: 'Standard'
capacity: 1
}
}

resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
name: modelGpt4
dependsOn: [ modelDeploymentTextEmbeddingAda002 ]
parent: account
properties: {
model: {
name: modelGpt4
version: '0613'
format: modelFormat
}
}
sku: {
name: 'GlobalBatch'
capacity: 1
}
}

resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
scope: account
dependsOn: [
modelDeploymentGpt4
modelDeploymentTextEmbeddingAda002
]
properties: {
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
principalId: appPrincipalId
}
}

output endpoint string = account.properties.endpoint
output resourceId string = account.id
18 changes: 16 additions & 2 deletions infra/bicep/modules/app/petclinic.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ param adminServerImage string
param chatAgentImage string

param applicationInsightsConnString string = ''

param enableOpenAi bool

param azureOpenAiEndpoint string
param openAiClientId string

Expand Down Expand Up @@ -145,7 +148,7 @@ module visitsService '../containerapps/containerapp.bicep' = {
}
}

module chatAgent '../containerapps/containerapp.bicep' = {
module chatAgent '../containerapps/containerapp.bicep' = if (enableOpenAi) {
name: 'chat-agent'
params: {
location: environment.location
Expand All @@ -159,7 +162,18 @@ module chatAgent '../containerapps/containerapp.bicep' = {
external: true
targetPort: targetPort
createSqlConnection: false
env: concat(env, empty(applicationInsightsConnString) ? [] : [
env: concat(env,
empty(applicationInsightsConnString) ? [] : [
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsightsConnString
}
{
name: 'APPLICATIONINSIGHTS_CONFIGURATION_CONTENT'
value: '{"role": {"name": "chat-agent"}}'
}
],
!enableOpenAi ? [] : [
{
name: 'SPRING_AI_AZURE_OPENAI_ENDPOINT'
value: azureOpenAiEndpoint
Expand Down
11 changes: 11 additions & 0 deletions infra/bicep/modules/shared/resourceGroup.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
targetScope='subscription'

param resourceGroupName string
param resourceGroupLocation string

resource rg 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: resourceGroupName
location: resourceGroupLocation
}

output name string = rg.name
7 changes: 0 additions & 7 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${version.spring.cloud.azure}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
Expand Down

0 comments on commit 19ccef6

Please sign in to comment.