Skip to content

Commit 72ff72e

Browse files
Merge pull request #198 from microsoft/cps-rm-local-build
feat: Removed local build from preprovision and added as part of post deployment & AZD Quota check implementation
2 parents ff4e5b7 + 5ab8b9c commit 72ff72e

13 files changed

+344
-397
lines changed

azure.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ metadata:
88
99

1010
hooks:
11-
preprovision:
12-
posix:
13-
shell: sh
14-
run: timestamp=$(date +"%Y%m%d-%H%M%S"); logFile="azd_preprovision_$timestamp.log"; sed -i 's/\r$//' ./infra/scripts/docker-build.sh; ./infra/scripts/docker-build.sh "$AZURE_SUBSCRIPTION_ID" "$AZURE_ENV_NAME" "$AZURE_LOCATION" "$AZURE_RESOURCE_GROUP" "$USE_LOCAL_BUILD" "$AZURE_ENV_IMAGETAG" 2>&1 | tee "$logFile"
15-
windows:
16-
shell: pwsh
17-
run: $timestamp = Get-Date -Format "yyyyMMdd-HHmmss"; $logFile = "azd_preprovision_$timestamp.log"; ./infra/scripts/docker-build.ps1 $env:AZURE_SUBSCRIPTION_ID $env:AZURE_ENV_NAME $env:AZURE_LOCATION $env:AZURE_RESOURCE_GROUP $env:USE_LOCAL_BUILD $env:AZURE_ENV_IMAGETAG *>&1 | Tee-Object -FilePath $logFile
1811
postprovision:
1912
posix:
2013
shell: sh

docs/CustomizingAzdParameters.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ By default this template will use the environment name as the prefix to prevent
1616
| `AZURE_ENV_MODEL_NAME` | string | `gpt-4o` | Specifies the GPT model name (allowed values: `gpt-4o`).
1717
| `AZURE_ENV_MODEL_VERSION` | string | `2024-08-06` | Specifies the GPT model version (allowed values: `2024-08-06`). |
1818
| `AZURE_ENV_MODEL_CAPACITY` | integer | `30` | Sets the model capacity (choose based on your subscription's available GPT capacity). |
19-
| `USE_LOCAL_BUILD` | boolean | `false` | Indicates whether to use a local container build for deployment. |
2019
| `AZURE_ENV_IMAGETAG` | boolean | `latest` | Set the Image tag Like (allowed values: latest, dev, hotfix) |
2120
| `AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID` | string | `<Existing Workspace Id>` | Reuses an existing Log Analytics Workspace instead of provisioning a new one. |
2221

docs/DeploymentGuide.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,36 +184,26 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
184184
185185
7. If you are done trying out the application, you can delete the resources by running `azd down`.
186186
187-
### Publishing Local Build Container to Azure Container Registry
188-
189-
If you need to rebuild the source code and push the updated container to the deployed Azure Container Registry, follow these steps:
187+
## Post Deployment Steps
188+
1. Optional: Publishing Local Build Container to Azure Container Registry
190189
191-
1. Set the environment variable `USE_LOCAL_BUILD` to `True`:
190+
If you need to rebuild the source code and push the updated container to the deployed Azure Container Registry, follow these steps:
192191
193192
- **Linux/macOS**:
194193
```bash
195-
export USE_LOCAL_BUILD=True
194+
cd ./infra/scripts/
195+
./docker-build.sh
196196
```
197197
198198
- **Windows (PowerShell)**:
199199
```powershell
200-
$env:USE_LOCAL_BUILD = $true
200+
cd .\infra\scripts\
201+
.\docker-build.ps1
201202
```
202-
2. Run the `az login` command
203-
```bash
204-
az login
205-
```
206-
207-
3. Run the `azd up` command again to rebuild and push the updated container:
208-
```bash
209-
azd up
210-
```
211203
212-
This will rebuild the source code, package it into a container, and push it to the Azure Container Registry associated with your deployment.
213-
214-
## Post Deployment Steps
204+
This will create a new Azure Container Registry, rebuild the source code, package it into a container, and push it to the Container Registry created.
215205
216-
1. **Register Schema Files**
206+
2. **Register Schema Files**
217207
218208
> Want to customize the schemas for your own documents? [Learn more about adding your own schemas here.](./CustomizeSchemaData.md)
219209
@@ -243,7 +233,7 @@ This will rebuild the source code, package it into a container, and push it to t
243233
- **Verify Results**
244234
![schema file registration](./images/SchemaFileRegistration.png)
245235
246-
2. **Import Sample Data**
236+
3. **Import Sample Data**
247237
- Grab the Schema IDs for Invoice and Property Damage Claim Form's Schema from first step
248238
- Move to the folder location to samples in ContentProcessorApi - [/src/ContentProcessorApi/samples/](/src/ContentProcessorApi/samples/)
249239
- Execute the script with Schema IDs

infra/container_app/deploy_container_app.bicep

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ param probes array = []
1616
param allowedOrigins array = []
1717
param minReplicas int = 1
1818
param maxReplicas int = 1
19-
param useLocalBuild string = 'false'
2019

2120
//Todo: Add Appconfig endpoint as Env variable
2221

@@ -34,12 +33,7 @@ resource processorContainerApp 'Microsoft.App/containerApps@2024-03-01' = {
3433
environmentId: containerEnvId
3534
workloadProfileName: 'Consumption'
3635
configuration:{
37-
registries: useLocalBuild == 'true' ? [
38-
{
39-
server: azureContainerRegistry
40-
identity: managedIdentityId
41-
}
42-
] : null
36+
registries: null
4337
ingress: enableIngress ? {
4438
external: true
4539
transport: 'auto'

infra/container_app/deploy_container_app_api_web.bicep

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ param maxReplicaContainerWeb int = 1
2525
// Container related params
2626
param azureContainerRegistry string
2727
param containerRegistryReaderId string
28-
param useLocalBuild string = 'false'
2928
param imageTag string
3029

3130
var abbrs = loadJsonContent('../abbreviations.json')
@@ -88,7 +87,6 @@ module containerApp 'deploy_container_app.bicep' = {
8887
enableIngress: false
8988
minReplicas: minReplicaContainerApp
9089
maxReplicas: maxReplicaContainerApp
91-
useLocalBuild: useLocalBuild
9290
}
9391
}
9492

@@ -112,7 +110,6 @@ module containerAppApi 'deploy_container_app.bicep' = {
112110
probes: probes
113111
minReplicas: minReplicaContainerApi
114112
maxReplicas: maxReplicaContainerApi
115-
useLocalBuild: useLocalBuild
116113
}
117114
}
118115

@@ -154,7 +151,6 @@ module containerAppWeb 'deploy_container_app.bicep' = {
154151
]
155152
minReplicas: minReplicaContainerWeb
156153
maxReplicas: maxReplicaContainerWeb
157-
useLocalBuild: useLocalBuild
158154
}
159155
}
160156

infra/deploy_container_registry.bicep

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ param location string = resourceGroup().location
1414

1515
@description('Provide a tier of your Azure Container Registry.')
1616
param acrSku string = 'Basic'
17+
18+
@description('List of Principal Ids to which ACR pull role assignment is required')
19+
param acrPullPrincipalIds array = []
1720

1821
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-09-01' = {
1922
name: containerNameCleaned
@@ -26,6 +29,19 @@ resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-09-01' =
2629
zoneRedundancy: 'Disabled'
2730
}
2831
}
32+
33+
// Add Role assignments for required principal id's
34+
resource acrPullRoleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for principalId in acrPullPrincipalIds: {
35+
name: guid(principalId, 'acrpull')
36+
scope: containerRegistry
37+
properties: {
38+
roleDefinitionId: subscriptionResourceId(
39+
'Microsoft.Authorization/roleDefinitions',
40+
'7f951dda-4ed3-4680-a7ca-43fe172d538d'
41+
)
42+
principalId: principalId
43+
}
44+
}]
2945

3046
output createdAcrName string = containerNameCleaned
3147
output createdAcrId string = containerRegistry.id

infra/deploy_role_assignments.bicep

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ param storagePrincipalId string // Resource ID of the Storage account
99
param aiServiceCUId string // Resource ID of the Azure AI Content Understanding Service
1010
param aiServiceId string // Resource ID of the Azure Open AI service
1111

12-
param containerRegistryReaderPrincipalId string
13-
1412
resource appConfigDataReader 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
1513
scope: resourceGroup()
1614
name: '516239f1-63e1-4d78-a4de-a74fb236a071'
@@ -130,15 +128,3 @@ resource cognitiveServicesUserRoleAssignment 'Microsoft.Authorization/roleAssign
130128
principalType: 'ServicePrincipal'
131129
}
132130
}
133-
134-
resource acrPullRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
135-
name: guid(containerRegistryReaderPrincipalId, 'acrpull')
136-
scope: resourceGroup()
137-
properties: {
138-
roleDefinitionId: subscriptionResourceId(
139-
'Microsoft.Authorization/roleDefinitions',
140-
'7f951dda-4ed3-4680-a7ca-43fe172d538d'
141-
) // AcrPull role
142-
principalId: containerRegistryReaderPrincipalId
143-
}
144-
}

infra/main.bicep

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ param secondaryLocation string = 'EastUs2'
2020
type: 'location'
2121
}
2222
})
23-
param contentUnderstandingLocation string
23+
param contentUnderstandingLocation string = 'WestUS'
24+
25+
@metadata({azd: {
26+
type: 'location'
27+
usageName: [
28+
'OpenAI.GlobalStandard.gpt-4o,100'
29+
]
30+
}
31+
})
32+
param aiDeploymentsLocation string
2433

2534
@minLength(1)
2635
@description('GPT model deployment type:')
@@ -36,8 +45,6 @@ param gptModelName string = 'gpt-4o'
3645
@description('Version of the GPT model to deploy:')
3746
param gptModelVersion string = '2024-08-06'
3847

39-
//var gptModelVersion = '2024-02-15-preview'
40-
4148
@minValue(10)
4249
@description('Capacity of the GPT deployment:')
4350
// You can increase this, but capacity is limited per model/region, so you will get errors if you go over
@@ -62,9 +69,6 @@ param minReplicaContainerWeb int = 1
6269
@description('Maximum number of replicas to be added for Container Web App')
6370
param maxReplicaContainerWeb int = 1
6471

65-
@description('Set this flag to true only if you are deplpoying from Local')
66-
param useLocalBuild string = 'false'
67-
6872
@description('Optional: Existing Log Analytics Workspace Resource ID')
6973
param existingLogAnalyticsWorkspaceId string = ''
7074

@@ -76,9 +80,6 @@ var resourceGroupLocation = resourceGroup().location
7680
// Load the abbrevations file required to name the azure resources.
7781
var abbrs = loadJsonContent('./abbreviations.json')
7882

79-
// Convert input to lowercase
80-
var useLocalBuildLower = toLower(useLocalBuild)
81-
8283
// ========== Managed Identity ========== //
8384
module managedIdentityModule 'deploy_managed_identity.bicep' = {
8485
name: 'deploy_managed_identity'
@@ -111,13 +112,13 @@ module applicationInsights 'deploy_app_insights.bicep' = {
111112
}
112113
}
113114

114-
// ========== Container Registry ========== //
115-
module containerRegistry 'deploy_container_registry.bicep' = {
116-
name: 'deploy_container_registry'
117-
params: {
118-
environmentName: environmentName
119-
}
120-
}
115+
// // ========== Container Registry ========== //
116+
// module containerRegistry 'deploy_container_registry.bicep' = {
117+
// name: 'deploy_container_registry'
118+
// params: {
119+
// environmentName: environmentName
120+
// }
121+
// }
121122

122123
// ========== Storage Account ========== //
123124
module storage 'deploy_storage_account.bicep' = {
@@ -134,7 +135,7 @@ module aifoundry 'deploy_ai_foundry.bicep' = {
134135
name: 'deploy_ai_foundry'
135136
params: {
136137
solutionName: solutionPrefix
137-
solutionLocation: resourceGroupLocation
138+
solutionLocation: aiDeploymentsLocation
138139
cuLocation: contentUnderstandingLocation
139140
deploymentType: deploymentType
140141
gptModelName: gptModelName
@@ -173,7 +174,6 @@ module containerApps './container_app/deploy_container_app_api_web.bicep' = {
173174
maxReplicaContainerApi: maxReplicaContainerApi
174175
minReplicaContainerWeb: minReplicaContainerWeb
175176
maxReplicaContainerWeb: maxReplicaContainerWeb
176-
useLocalBuild: 'false'
177177
imageTag: 'latest'
178178
}
179179
}
@@ -221,7 +221,6 @@ module roleAssignments 'deploy_role_assignments.bicep' = {
221221
containerAppPrincipalId: containerApps.outputs.containerAppPrincipalId
222222
aiServiceCUId: aifoundry.outputs.aiServicesCuId
223223
aiServiceId: aifoundry.outputs.aiServicesId
224-
containerRegistryReaderPrincipalId: containerAppEnv.outputs.containerRegistryReaderPrincipalId
225224
}
226225
}
227226

@@ -230,7 +229,7 @@ module updateContainerApp './container_app/deploy_container_app_api_web.bicep' =
230229
params: {
231230
solutionName: solutionPrefix
232231
location: secondaryLocation
233-
azureContainerRegistry: useLocalBuildLower == 'true' ? containerRegistry.outputs.acrEndpoint : containerImageEndPoint
232+
azureContainerRegistry: containerImageEndPoint
234233
appConfigEndPoint: appconfig.outputs.appConfigEndpoint
235234
containerAppEnvId: containerAppEnv.outputs.containerEnvId
236235
containerRegistryReaderId: containerAppEnv.outputs.containerRegistryReaderId
@@ -242,7 +241,6 @@ module updateContainerApp './container_app/deploy_container_app_api_web.bicep' =
242241
maxReplicaContainerApi: maxReplicaContainerApi
243242
minReplicaContainerWeb: minReplicaContainerWeb
244243
maxReplicaContainerWeb: maxReplicaContainerWeb
245-
useLocalBuild: useLocalBuildLower
246244
imageTag: imageTag
247245
}
248246
dependsOn: [roleAssignments]
@@ -251,4 +249,8 @@ module updateContainerApp './container_app/deploy_container_app_api_web.bicep' =
251249
output CONTAINER_WEB_APP_NAME string = containerApps.outputs.containerAppWebName
252250
output CONTAINER_API_APP_NAME string = containerApps.outputs.containerAppApiName
253251
output CONTAINER_WEB_APP_FQDN string = containerApps.outputs.containweAppWebEndPoint
252+
output CONTAINER_APP_NAME string = containerApps.outputs.containerAppName
254253
output CONTAINER_API_APP_FQDN string = containerApps.outputs.containweAppApiEndPoint
254+
output CONTAINER_APP_USER_IDENTITY_ID string = containerAppEnv.outputs.containerRegistryReaderId
255+
output CONTAINER_APP_USER_PRINCIPAL_ID string = containerAppEnv.outputs.containerRegistryReaderPrincipalId
256+
output AZURE_ENV_IMAGETAG string = imageTag

infra/main.bicepparam

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)