Skip to content

Commit c91d555

Browse files
authored
Configure Application from AZD Up command (#548)
* Add Cosmos DB post-configuration script and update requirements - Initial POC * post deploy configure services in cosmosdb * refactor to prevent post deploy configuration + begin support of key based auth. * Add additional parameter validation for creating entra app * Refactor Bicep modules for improved authentication and key management - Added keyVault-Secrets.bicep module for storing secrets in Key Vault. - Modified keyVault.bicep to remove enterprise app client secret handling and commented out managed identity role assignments. - Removed openAI-existing.bicep and refactored openAI.bicep to handle model deployments dynamically. - Added setPermissions.bicep for managing role assignments for various resources. - Updated postconfig.py to reflect changes in environment variable handling for authentication type. * Refactor Bicep modules to conditionally add settings based on authentication type and enable resource declarations for services * initial support for VideoIndexer service * Refactor Bicep modules to enhance VideoIndexer service integration and update diagnostic settings configurations * move from using chainguard-dev builder image to python slim image. * Updates to support post deployment app config * Add post-deployment permissions script for CosmosDB and update authentication type handling * fix typo in enhanced citation deployment config * Refactor Dockerfile to use Python 3.13-slim and streamline build process * restart web application after deployment settings applied * remove setting for disableLocalAuth * update to latest version of bicep deployment * remove dead code * code cleanup / formatting * removed unnecessary content from readme.md * fix token scope for commericial search service * set permission correctly for lookup of openAI models * fixes required to configure search with managed identity
1 parent 3bf067a commit c91d555

37 files changed

+1075
-1093
lines changed

application/single_app/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Builder stage: install dependencies in a virtualenv
2-
FROM cgr.dev/chainguard/python:latest-dev AS builder
2+
# FROM cgr.dev/chainguard/python:latest-dev AS builder
3+
FROM python:3.13-slim AS builder
34

45
USER root
56

@@ -12,14 +13,19 @@ WORKDIR /app
1213
RUN python -m venv /app/venv
1314

1415
# Create and permission the flask_session directory
15-
RUN mkdir -p /app/flask_session && chown -R nonroot:nonroot /app/flask_session
16+
#RUN mkdir -p /app/flask_session && chown -R nonroot:nonroot /app/flask_session
17+
RUN mkdir -p /app/flask_session
1618

1719
# Copy requirements and install them into the virtualenv
1820
COPY application/single_app/requirements.txt .
1921
ENV PATH="/app/venv/bin:$PATH"
2022
RUN pip install --no-cache-dir -r requirements.txt
2123

22-
FROM cgr.dev/chainguard/python:latest
24+
#FROM cgr.dev/chainguard/python:latest
25+
FROM python:3.13-slim
26+
27+
# Create nonroot user
28+
RUN useradd -m -u 1000 nonroot
2329

2430
WORKDIR /app
2531

@@ -40,4 +46,4 @@ EXPOSE 5000
4046

4147
USER nonroot:nonroot
4248

43-
ENTRYPOINT [ "python", "/app/app.py" ]
49+
ENTRYPOINT [ "python", "/app/app.py" ]

application/single_app/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
credential_scopes=[resource_manager + "/.default"]
185185
cognitive_services_scope = "https://cognitiveservices.azure.com/.default"
186186
video_indexer_endpoint = "https://api.videoindexer.ai"
187+
search_resource_manager = "https://search.azure.com"
187188
KEY_VAULT_DOMAIN = ".vault.azure.net"
188189

189190
def get_redis_cache_infrastructure_endpoint(redis_hostname: str) -> str:

application/single_app/route_backend_settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,7 @@ def _test_azure_ai_search_connection(payload):
694694
url = f"{endpoint.rstrip('/')}/indexes?api-version=2023-11-01"
695695

696696
if direct_data.get('auth_type') == 'managed_identity':
697-
if AZURE_ENVIRONMENT in ("usgovernment", "custom"): # change credential scopes for US Gov or custom environments
698-
credential_scopes=search_resource_manager + "/.default"
697+
credential_scopes=search_resource_manager + "/.default"
699698
arm_scope = credential_scopes
700699
credential = DefaultAzureCredential()
701700
arm_token = credential.get_token(arm_scope).token

deployers/Initialize-EntraApplication.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@
4141
[CmdletBinding()]
4242
param(
4343
[Parameter(Mandatory = $true)]
44+
[ValidateLength(3, 12)] # Length between 3 and 12
45+
[ValidatePattern('^[a-zA-Z0-9]+$')] # Only letters and numbers
4446
[string]$AppName,
4547

4648
[Parameter(Mandatory = $true)]
49+
[ValidateLength(2, 10)] # Length between 2 and 10
50+
[ValidatePattern('^[a-zA-Z0-9]+$')] # Only letters and numbers
4751
[string]$Environment,
4852

4953
[Parameter(Mandatory = $false)]

deployers/azure.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,48 @@ infra:
55
provider: bicep
66
path: bicep
77
hooks:
8+
postprovision:
9+
posix:
10+
shell: sh
11+
run: |
12+
# Set up variables
13+
14+
export var_configureApplication=${var_configureApplication}
15+
export var_cosmosDb_uri=${var_cosmosDb_uri}
16+
export var_subscriptionId=${AZURE_SUBSCRIPTION_ID}
17+
export var_rgName=${var_rgName}
18+
export var_keyVaultUri=${var_keyVaultUri}
19+
20+
export var_authenticationType=${var_authenticationType}
21+
22+
export var_openAIEndpoint=${var_openAIEndpoint}
23+
export var_openAIResourceGroup=${var_openAIResourceGroup}
24+
export var_openAIGPTModel=${var_openAIGPTModel}
25+
export var_openAITextEmbeddingModel=${var_openAITextEmbeddingModel}
26+
export var_blobStorageEndpoint=${var_blobStorageEndpoint}
27+
export var_contentSafetyEndpoint=${var_contentSafetyEndpoint}
28+
export var_searchServiceEndpoint=${var_searchServiceEndpoint}
29+
export var_documentIntelligenceServiceEndpoint=${var_documentIntelligenceServiceEndpoint}
30+
export var_videoIndexerName=${var_videoIndexerName}
31+
export var_deploymentLocation=${var_deploymentLocation}
32+
export var_videoIndexerAccountId=${var_videoIndexerAccountId}
33+
export var_speechServiceEndpoint=${var_speechServiceEndpoint}
34+
35+
# Execute post-configuration script if enabled
36+
if [ "${var_configureApplication}" = "true" ]; then
37+
echo "Grant permissions to CosmosDB for post deployment steps..."
38+
bash ./bicep/cosmosDb-postDeployPerms.sh
39+
echo "Running post-deployment configuration..."
40+
python3 -m pip install --user -r ./bicep/requirements.txt
41+
python3 ./bicep/postconfig.py
42+
echo "Post-deployment configuration completed."
43+
echo "Restarting web service to apply new settings..."
44+
az webapp restart --name ${var_webService} --resource-group ${var_rgName}
45+
echo "Web service restarted."
46+
else
47+
echo "Skipping post-deployment configuration (var_configureApplication is not true)"
48+
fi
49+
850
predeploy:
951
posix:
1052
shell: sh

deployers/bicep/README.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ The folloiwng variables will be used within this document:
2525
- *\<imageName\>* - Should be presented in the form *imageName:label* **Example:** *simple-chat:latest*
2626

2727

28-
The following variables may be entered with a blank depending on the response to other parameters:
29-
30-
If *\<useExistingAcr\>* = *true* then the following variables need to be set with applicable values, if *false* a blank is permitted
31-
- *\<existingACRResourceGroup\>* - Resource group name for the existing Azure Container Registry.
32-
- *\<existingACRResourceName\>* - Azure Container Registry name
33-
34-
if *\<useExistingOpenAISvc\>* = *true* then the following variables need to be set with applicable values, if *false* a blank is permitted.
35-
- *\<existingOpenAIResourceGroupName\>* - Resource group name for the existing Azure OpenAI service.
36-
- *\<existingOpenAIResourceName\>* - Azure OpenAI service name.
37-
3828
## Deployment Process
3929

4030
The below steps cover the process to deploy the Simple Chat application to an Azure Subscription. It is assumed the user has administrative rights to the subscription for deployment. If the user does not also have permissions to create an Application Registration in Entra, a stand-alone script can be provided to an administrator with the correct permissions.
@@ -113,26 +103,19 @@ Using the bash terminal in Visual Studio Code
113103

114104
- Select an Azure Subscription to use: *\<select from available list\>*
115105
- Enter a value for the 'appName' infrastructure parameter: *\<appName\>*
106+
- Enter a value for the 'authenticationType' infrastructure parameter: *\<authType\>*
107+
- Enter a vaule for the 'cloudEnvironment' infrastructure parameter: *\<AzureCloud | AzureUSGovernment\>*
108+
- Enter a value for the 'configureApplicationPermissions' infrastructure parameter: \<true | false\>*
116109
- Enter a value for the 'deployContentSafety' infrastructure parameter: *\<true | false\>*
117110
- Enter a value for the 'deployRedisCache' infrastructure parameter: *\<true | false\>*
118111
- Enter a value for the 'deploySpeechService' infrastructure parameter: *\<true | false\>*
112+
- Enter a value for the 'deployVideoIndexerService' infrastructure parameter: *\<true | false\>*
119113
- Enter a value for the 'enableDiagLogging' infrastructure parameter: *\<true | false\>*
120114
- Enter a value for the 'enterpriseAppClientId' infrastructure parameter: *\<clientID\>*
121115
- Enter a value for the 'enterpriseAppClientSecret' infrastructure secured parameter: *\<clientSecret\>*
122116
- Enter a value for the 'environment' infrastructure parameter: *\<environment\>*
123-
124-
>Note: The following variables may be blank depending on other parameter settings
125-
126-
- Enter a value for the 'existingAcrResourceGroup' infrastructure parameter:
127-
- Enter a value for the 'existingAcrResourceName' infrastructure parameter:
128-
- Enter a value for the 'existingOpenAIResourceGroupName' infrastructure parameter:
129-
- Enter a value for the 'existingOpenAIResourceName' infrastructure parameter:
130-
131-
>Remaining parameters
132117
- Enter a value for the 'imageName' infrastructure parameter: *\<imageName\>*
133118
- Enter a value for the 'location' infrastructure parameter: *\<select from the list provided\>*
134-
- Enter a value for the 'useExistingAcr' infrastructure parameter: *\<true | false\>*
135-
- Enter a value for the 'useExistingOpenAISvc' infrastructure parameter: *\<true | false\>*
136119

137120
Provisioning may take between 10-40 minutes depending on the options selected.
138121

@@ -142,31 +125,24 @@ On the completion of the deployment, a URL will be presented, the user may use t
142125

143126
### Post Deployment Tasks:
144127

145-
Once logged in to the newly deployed application with admin credentials, the application will need to be configured with several configurations:
128+
Once logged in to the newly deployed application with admin credentials, the application will need to be set up with several configurations:
146129

147-
1. Admin Settings > Health Check > "Enable External Health Check Endpoint" - Set to "ON"
148-
1. AI Models > GPT Configuration & Embeddings Configuration. Use managed Identity. Configure the subscription and resource group. Click Save
130+
1. AI Models > GPT Configuration & Embeddings Configuration. Application is pre-configured with the chosen security model (key / managed identity). Select "Test GPT Connection" and "Test Embedding Connection" to verify connection.
149131

150132
> Known Bug: User will be unable to Fetch GPT or Embedding models. </br>
151133
Workaround: Set configurations in CosmosDB. For details see [Workarounds](##Workarounds) below.
152134

153-
1. Agents and Actions > Agents Configuration > "Enable Agents" - Set to "ON"
154135
1. Logging > Application Insights Logging > "Enable Application Insights Global Logging - Set to "ON"
155136
1. Citations > Ehnahced Citations > "Enable Enhanced Citations" - Set to "ON"
156137
- Configure "All Filetypes"
157138
- "Storage Account Authentication Type" = Managed Identity
158139
- "Storage Account Blob Endpoint" = "https://\<appName\>\<environment\>sa.blob.core.windows.net" (or appropiate domain if in Azure Gov.)
159-
1. Workflow > Workflow Settings > "Enable Workflow" - Set to "ON"
160-
> Note if the deployment option for "deployContentSafety" was set to true follow the next step.
161-
1. Safety > Content Safety > "Enable Content Safety" - Set to "ON"
162-
- "Content Safety Endpoint" - "https://\<appName\>-\<environment\>-contentsafety.cognitiveservices.azure.com/" (or appropiate domain if in Azure Gov.)
163140
1. Safety > Conversation Archiving > "Enable Conversation Archiving" - Set to "ON"
164-
1. PII Analysis > PII Analysis > "Enable PII Analysis" - Set to "ON"
165141
1. Search & Extract > Azure AI Search
166142
- "Search Endpoint" = "https://\<appName\>-\<environment\>-search.search.windows.net" (or appropiate domain if in Azure Gov.)
167143
> Known Bug: Unable to configure "Managed Identity" authentication type. Must use "Key"
168144
- "Authentication Type" - Key
169-
- "Search Key" - Retreive from the deployed search service.
145+
- "Search Key" - *Pre-populated from key vault value*.
170146
- At the top of the Admin Page you'll see warning boxes indicating Index Schema Mismatch.
171147
- Click "Create user Index"
172148
- Click "Create group Index"

deployers/bicep/README_orig.md

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

0 commit comments

Comments
 (0)