Skip to content

Commit 0da2665

Browse files
authored
integrate for services, now services are running ok (#54)
## Purpose <!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? --> * ... ## Does this introduce a breaking change? <!-- Mark one with an "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 [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. -->
1 parent 93439b3 commit 0da2665

File tree

6 files changed

+89
-42
lines changed

6 files changed

+89
-42
lines changed

config/application-passwordless.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
server:
22
port: 8080
3+
4+
spring:
35
sql:
46
init:
57
schema-locations: classpath*:db/mysql/schema.sql

infra/bicep/main.bicep

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ param acrSubscription string = ''
4646

4747
@description('Enable OpenAI components')
4848
param enableOpenAi bool = false
49+
@description('Name of the Open AI name')
50+
param openAiName string = ''
4951
@description('Resource group of the Open AI')
50-
param openAiResourceGroup string
52+
param openAiResourceGroup string = ''
5153
@description('Location of the Open AI')
52-
param openAiLocation string
54+
param openAiLocation string = ''
5355
@description('Subscription of the Open AI')
54-
param openAiSubscription string
56+
param openAiSubscription string = ''
5557

5658
@description('Name of the log analytics server. Default la-{environmentName}')
5759
param logAnalyticsName string = ''
@@ -225,9 +227,11 @@ module openai 'modules/ai/openai.bicep' = if (enableOpenAi) {
225227
]
226228
scope: resourceGroup(openAiSubscription, openAiResourceGroup)
227229
params: {
228-
accountName: 'openai-${environmentName}'
230+
accountName: !empty(openAiName) ? openAiName : 'openai-${environmentName}'
229231
location: openAiLocation
230232
appPrincipalId: umiApps.outputs.principalId
233+
tags: tags
234+
newOrExisting: 'existing'
231235
}
232236
}
233237

@@ -238,8 +242,9 @@ module applications 'modules/app/petclinic.bicep' = {
238242
managedEnvironmentsName: managedEnvironment.outputs.containerAppsEnvironmentName
239243
eurekaId: javaComponents.outputs.eurekaId
240244
configServerId: javaComponents.outputs.configServerId
241-
mysqlDBId: mysql.outputs.databaseId
242-
mysqlUserAssignedIdentityClientId: umiApps.outputs.clientId
245+
mysqlDatabaseId: mysql.outputs.databaseId
246+
umiAppsClientId: umiApps.outputs.clientId
247+
umiAppsIdentityId: umiApps.outputs.id
243248
acrRegistry: '${acrRoleAssignments.outputs.registryName}.azurecr.io' // add dependency to make sure roles are assigned
244249
acrIdentityId: umiAcrPull.outputs.id
245250
apiGatewayImage: !empty(apiGatewayImage) ? apiGatewayImage : placeholderImage
@@ -251,8 +256,8 @@ module applications 'modules/app/petclinic.bicep' = {
251256
targetPort: 8080
252257
applicationInsightsConnString: applicationInsights.outputs.connectionString
253258
enableOpenAi: enableOpenAi
254-
azureOpenAiEndpoint: openai.outputs.endpoint
255-
openAiClientId: umiApps.outputs.id
259+
openAiEndpoint: openai.outputs.endpoint
260+
openAiClientId: umiApps.outputs.clientId
256261
}
257262
}
258263

infra/bicep/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"enableOpenAi": {
3939
"value": true
4040
},
41+
"openAiName": {
42+
"value": "openai-petclinic"
43+
},
4144
"openAiResourceGroup": {
4245
"value": "rg-openai"
4346
},

infra/bicep/modules/ai/openai.bicep

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ param location string
1010
param modelTextEmbeddingAda002 string = 'text-embedding-ada-002'
1111

1212
@description('Optional. model name for the gpt-4 language model. ')
13-
param modelGpt4 string = 'gpt-4'
13+
param modelGpt4 string = 'gpt-4o'
1414

1515
@description('Optional. model format for the language models. ')
1616
param modelFormat string = 'OpenAI'
@@ -22,21 +22,32 @@ param appPrincipalId string
2222
// https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-openai-user
2323
param roleDefinitionId string = '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
2424

25-
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
25+
@description('Optional. Tags of the resource.')
26+
param tags object = {}
27+
28+
@description('Optional. Determines whether or not new ApplicationInsights should be provisioned.')
29+
@allowed([
30+
'new'
31+
'existing'
32+
])
33+
param newOrExisting string = 'new'
34+
35+
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = if (newOrExisting == 'new') {
2636
name: accountName
2737
location: location
2838
sku: {
2939
name: 'S0'
3040
}
3141
kind: 'OpenAI'
42+
tags: tags
3243
properties: {
3344
customSubDomainName: accountName
3445
publicNetworkAccess: 'Enabled'
3546
disableLocalAuth: true
3647
}
3748
}
3849

39-
resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
50+
resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = if (newOrExisting == 'new') {
4051
name: modelTextEmbeddingAda002
4152
parent: account
4253
properties: {
@@ -52,24 +63,24 @@ resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/account
5263
}
5364
}
5465

55-
resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
66+
resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = if (newOrExisting == 'new') {
5667
name: modelGpt4
5768
dependsOn: [ modelDeploymentTextEmbeddingAda002 ]
5869
parent: account
5970
properties: {
6071
model: {
6172
name: modelGpt4
62-
version: '0613'
73+
version: '2024-05-13'
6374
format: modelFormat
6475
}
6576
}
6677
sku: {
67-
name: 'GlobalBatch'
78+
name: 'GlobalStandard'
6879
capacity: 1
6980
}
7081
}
7182

72-
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
83+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (newOrExisting == 'new') {
7384
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
7485
scope: account
7586
dependsOn: [
@@ -82,5 +93,21 @@ resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
8293
}
8394
}
8495

85-
output endpoint string = account.properties.endpoint
86-
output resourceId string = account.id
96+
resource accountExist 'Microsoft.CognitiveServices/accounts@2023-05-01' existing = if (newOrExisting == 'existing') {
97+
name: accountName
98+
}
99+
100+
resource roleAssignmentExist 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (newOrExisting == 'existing') {
101+
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
102+
scope: accountExist
103+
properties: {
104+
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
105+
principalId: appPrincipalId
106+
}
107+
}
108+
109+
@description('Endpoint of the Azure OpenAI service account.')
110+
output endpoint string = (newOrExisting == 'new') ? account.properties.endpoint : accountExist.properties.endpoint
111+
112+
@description('Resource Id of the Azure OpenAI service account.')
113+
output resourceId string = (newOrExisting == 'new') ? account.id : accountExist.id

infra/bicep/modules/app/petclinic.bicep

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ param managedEnvironmentsName string
44
param eurekaId string
55
param configServerId string
66

7-
param mysqlDBId string
8-
param mysqlUserAssignedIdentityClientId string
7+
param mysqlDatabaseId string
98

109
param acrRegistry string
1110
param acrIdentityId string
1211

12+
param umiAppsClientId string
13+
param umiAppsIdentityId string
14+
1315
param apiGatewayImage string
1416
param customersServiceImage string
1517
param vetsServiceImage string
@@ -21,7 +23,7 @@ param applicationInsightsConnString string = ''
2123

2224
param enableOpenAi bool
2325

24-
param azureOpenAiEndpoint string
26+
param openAiEndpoint string
2527
param openAiClientId string
2628

2729
param targetPort int = 8080
@@ -42,7 +44,8 @@ module apiGateway '../containerapps/containerapp.bicep' = {
4244
configServerId: configServerId
4345
registry: acrRegistry
4446
image: apiGatewayImage
45-
containerRegistryUserAssignedIdentityId: acrIdentityId
47+
acrIdentityId: acrIdentityId
48+
umiAppsIdentityId: umiAppsIdentityId
4649
external: true
4750
targetPort: targetPort
4851
createSqlConnection: false
@@ -69,12 +72,13 @@ module customersService '../containerapps/containerapp.bicep' = {
6972
configServerId: configServerId
7073
registry: acrRegistry
7174
image: customersServiceImage
72-
containerRegistryUserAssignedIdentityId: acrIdentityId
75+
acrIdentityId: acrIdentityId
7376
external: false
7477
targetPort: targetPort
7578
createSqlConnection: true
76-
mysqlDBId: mysqlDBId
77-
mysqlUserAssignedIdentityClientId: mysqlUserAssignedIdentityClientId
79+
mysqlDatabaseId: mysqlDatabaseId
80+
umiAppsClientId: umiAppsClientId
81+
umiAppsIdentityId: umiAppsIdentityId
7882
readinessProbeInitialDelaySeconds: 20
7983
livenessProbeInitialDelaySeconds: 40
8084
env: concat(env, empty(applicationInsightsConnString) ? [] : [
@@ -100,12 +104,13 @@ module vetsService '../containerapps/containerapp.bicep' = {
100104
configServerId: configServerId
101105
registry: acrRegistry
102106
image: vetsServiceImage
103-
containerRegistryUserAssignedIdentityId: acrIdentityId
107+
acrIdentityId: acrIdentityId
104108
external: false
105109
targetPort: targetPort
106110
createSqlConnection: true
107-
mysqlDBId: mysqlDBId
108-
mysqlUserAssignedIdentityClientId: mysqlUserAssignedIdentityClientId
111+
mysqlDatabaseId: mysqlDatabaseId
112+
umiAppsClientId: umiAppsClientId
113+
umiAppsIdentityId: umiAppsIdentityId
109114
env: concat(env, empty(applicationInsightsConnString) ? [] : [
110115
{
111116
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
@@ -129,12 +134,13 @@ module visitsService '../containerapps/containerapp.bicep' = {
129134
configServerId: configServerId
130135
registry: acrRegistry
131136
image: visitsServiceImage
132-
containerRegistryUserAssignedIdentityId: acrIdentityId
137+
acrIdentityId: acrIdentityId
133138
external: false
134139
targetPort: targetPort
135140
createSqlConnection: true
136-
mysqlDBId: mysqlDBId
137-
mysqlUserAssignedIdentityClientId: mysqlUserAssignedIdentityClientId
141+
mysqlDatabaseId: mysqlDatabaseId
142+
umiAppsClientId: umiAppsClientId
143+
umiAppsIdentityId: umiAppsIdentityId
138144
env: concat(env, empty(applicationInsightsConnString) ? [] : [
139145
{
140146
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
@@ -158,7 +164,8 @@ module chatAgent '../containerapps/containerapp.bicep' = if (enableOpenAi) {
158164
configServerId: configServerId
159165
registry: acrRegistry
160166
image: chatAgentImage
161-
containerRegistryUserAssignedIdentityId: acrIdentityId
167+
acrIdentityId: acrIdentityId
168+
umiAppsIdentityId: umiAppsIdentityId
162169
external: true
163170
targetPort: targetPort
164171
createSqlConnection: false
@@ -176,7 +183,7 @@ module chatAgent '../containerapps/containerapp.bicep' = if (enableOpenAi) {
176183
!enableOpenAi ? [] : [
177184
{
178185
name: 'SPRING_AI_AZURE_OPENAI_ENDPOINT'
179-
value: azureOpenAiEndpoint
186+
value: openAiEndpoint
180187
}
181188
{
182189
name: 'SPRING_AI_AZURE_OPENAI_CLIENT_ID'
@@ -196,7 +203,8 @@ module adminServer '../containerapps/containerapp.bicep' = {
196203
configServerId: configServerId
197204
registry: acrRegistry
198205
image: adminServerImage
199-
containerRegistryUserAssignedIdentityId: acrIdentityId
206+
acrIdentityId: acrIdentityId
207+
umiAppsIdentityId: umiAppsIdentityId
200208
external: true
201209
targetPort: targetPort
202210
createSqlConnection: false

infra/bicep/modules/containerapps/containerapp.bicep

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ param appName string
66
param eurekaId string
77
param configServerId string
88
param external bool = false
9-
param containerRegistryUserAssignedIdentityId string
9+
param acrIdentityId string
10+
param umiAppsIdentityId string
11+
param umiAppsClientId string = ''
1012
param env array = []
1113
param targetPort int
1214
param createSqlConnection bool = false
13-
param mysqlDBId string = ''
14-
param mysqlUserAssignedIdentityClientId string = ''
15+
param mysqlDatabaseId string = ''
1516
param readinessProbeInitialDelaySeconds int = 10
1617
param livenessProbeInitialDelaySeconds int = 30
1718

@@ -21,7 +22,8 @@ resource app 'Microsoft.App/containerApps@2024-02-02-preview' = {
2122
identity: {
2223
type: 'UserAssigned'
2324
userAssignedIdentities: {
24-
'${containerRegistryUserAssignedIdentityId}': {}
25+
'${acrIdentityId}': {}
26+
'${umiAppsIdentityId}': {}
2527
}
2628
}
2729
properties: {
@@ -31,10 +33,10 @@ resource app 'Microsoft.App/containerApps@2024-02-02-preview' = {
3133
external: external
3234
targetPort: targetPort
3335
}
34-
registries: containerRegistryUserAssignedIdentityId == null ? null : [
36+
registries: empty(acrIdentityId) ? null : [
3537
{
3638
server: registry
37-
identity: containerRegistryUserAssignedIdentityId
39+
identity: acrIdentityId
3840
}
3941
]
4042
runtime: {
@@ -108,7 +110,7 @@ resource app 'Microsoft.App/containerApps@2024-02-02-preview' = {
108110
}
109111
}
110112

111-
var mysqlToken = !empty(mysqlDBId) ? split(mysqlDBId, '/') : array('')
113+
var mysqlToken = !empty(mysqlDatabaseId) ? split(mysqlDatabaseId, '/') : array('')
112114
var mysqlSubscriptionId = length(mysqlToken) > 2 ? mysqlToken[2] : ''
113115

114116
var connectionName = 'mysql_conn'
@@ -121,13 +123,13 @@ resource connectDB 'Microsoft.ServiceLinker/linkers@2023-04-01-preview' = if (cr
121123
clientType: 'springBoot'
122124
authInfo: {
123125
authType: 'userAssignedIdentity'
124-
clientId: mysqlUserAssignedIdentityClientId
126+
clientId: umiAppsClientId
125127
subscriptionId: mysqlSubscriptionId
126128
userName: 'aad_${connectionName}'
127129
}
128130
targetService: {
129131
type: 'AzureResource'
130-
id: mysqlDBId
132+
id: mysqlDatabaseId
131133
}
132134
}
133135
}

0 commit comments

Comments
 (0)