Skip to content

Commit 8e652ab

Browse files
Merge pull request #477 from microsoft/us-19154
fix: updated scripts to add subscription selection and added retry logic for uploading documents, exp changes doc update
2 parents 8bb3ce7 + 7900fe3 commit 8e652ab

File tree

6 files changed

+145
-1
lines changed

6 files changed

+145
-1
lines changed

docs/DeploymentGuide.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,67 @@ To adjust quota settings, follow these [steps](./AzureGPTQuotaSettings.md).
134134

135135
</details>
136136

137+
<details>
138+
139+
<summary><b>Deploy in existing Resource Group</b></summary>
140+
141+
To use an existing Azure Resource Group for your deployment, follow these steps:
142+
143+
#### 1. Identify the Resource Group
144+
145+
- Visit the [Azure Portal](https://portal.azure.com) and choose the Resource Group you want to reuse.
146+
147+
#### 2. Set the Resource Group in your Environment
148+
149+
Before running `azd up`, set the resource group name:
150+
151+
```bash
152+
azd env set AZURE_RESOURCE_GROUP <rg-name>
153+
```
154+
Replace `<rg-name>` with the name of your chosen Resource Group.
155+
156+
#### 3. Continue Deployment
157+
158+
Continue with the [deploying steps](#deploying-with-azd).
159+
160+
</details>
161+
162+
<details>
163+
164+
<summary><b>Reusing an Existing Log Analytics Workspace</b></summary>
165+
166+
To configure your environment to use an existing Log Analytics Workspace, follow these steps:
167+
168+
#### 1. Navigate to Azure Portal
169+
Go to [Azure Portal](https://portal.azure.com)
170+
171+
#### 2. Find Your Log Analytics Workspace
172+
- In the search bar at the top, type "Log Analytics workspaces" and select it.
173+
- Click on the workspace you want to use.
174+
175+
![Log Analytics Resource List](../docs/images/logAnalyticsList.png)
176+
177+
#### 3. Copy Workspace Id
178+
- In the Overview pane, Click on **JSON View**
179+
180+
![Log Analytics](../docs/images/logAnalytics.png)
181+
182+
- Copy the **Resource ID** (this is your Workspace ID)
183+
184+
![Log Analytics JSON](../docs/images/logAnalyticsJson.png)
185+
186+
#### 4. Set the Workspace ID in Your Environment
187+
Run the following command in your terminal
188+
```bash
189+
azd env set AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID '<Existing Log Analytics Workspace Id>'
190+
```
191+
Replace `<Existing Log Analytics Workspace Id>` with the full Resource ID obtained from Step 3.
192+
193+
#### 5. Continue Deployment
194+
Continue with the [deploying steps](#deploying-with-azd).
195+
196+
</details>
197+
137198
### Deploying with AZD
138199

139200
Once you've opened the project in [Codespaces](#github-codespaces), [Dev Containers](#vs-code-dev-containers), or [locally](#local-environment), you can deploy it to Azure by following these steps:

docs/images/logAnalytics.png

142 KB
Loading

docs/images/logAnalyticsJson.png

196 KB
Loading

docs/images/logAnalyticsList.png

88.9 KB
Loading

infra/scripts/copy_kb_files.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ if [ -z "$role_assignment" ]; then
4646
MSYS_NO_PATHCONV=1 az role assignment create --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --output none
4747
if [ $? -eq 0 ]; then
4848
echo "Role assignment completed successfully."
49+
sleep 5
4950
retries=3
5051
while [ $retries -gt 0 ]; do
5152
# Check if the role assignment was successful
5253
role_assignment_check=$(MSYS_NO_PATHCONV=1 az role assignment list --assignee $signed_user_id --role "Storage Blob Data Contributor" --scope $storage_account_resource_id --query "[].roleDefinitionId" -o tsv)
5354
if [ -n "$role_assignment_check" ]; then
5455
echo "Role assignment verified successfully."
56+
sleep 5
5557
break
5658
else
5759
echo "Role assignment not found, retrying..."
@@ -93,6 +95,27 @@ unzip -o $zipUrl1 -d infra/data/"$extractedFolder1"
9395
# unzip /mnt/azscripts/azscriptinput/"$zipFileName2" -d /mnt/azscripts/azscriptinput/"$extractedFolder2"
9496

9597
# Using az storage blob upload-batch to upload files with managed identity authentication, as the az storage fs directory upload command is not working with managed identity authentication.
96-
echo "Uploading files to Azure Storage"
98+
echo "Uploading files to Azure Blob Storage"
9799
az storage blob upload-batch --account-name "$storageAccount" --destination "$fileSystem"/"$extractedFolder1" --source infra/data/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite --output none
100+
if [ $? -ne 0 ]; then
101+
retries=3
102+
sleepTime=10
103+
echo "Error: Failed to upload files to Azure Blob Storage. Retrying upload...($((4 - retries)) of 3)"
104+
while [ $retries -gt 0 ]; do
105+
sleep $sleepTime
106+
az storage blob upload-batch --account-name "$storageAccount" --destination "$fileSystem"/"$extractedFolder1" --source infra/data/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite --output none
107+
if [ $? -eq 0 ]; then
108+
echo "Files uploaded successfully to Azure Blob Storage."
109+
break
110+
else
111+
((retries--))
112+
echo "Retrying upload... ($((4 - retries)) of 3)"
113+
sleepTime=$((sleepTime * 2))
114+
sleep $sleepTime
115+
fi
116+
done
117+
exit 1
118+
else
119+
echo "Files uploaded successfully to Azure Blob Storage."
120+
fi
98121
# az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder2" --source /mnt/azscripts/azscriptinput/"$extractedFolder2" --auth-mode login --pattern '*' --overwrite

infra/scripts/process_sample_data.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,72 @@ if [ -z "$aiFoundryName" ]; then
3434
aiFoundryName=$(azd env get-value AI_FOUNDRY_NAME)
3535
fi
3636

37+
azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
38+
3739
# Check if all required arguments are provided
3840
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ] || [ -z "$aiFoundryName" ]; then
3941
echo "Usage: $0 <storageAccount> <storageContainerName> <keyvaultName> <cosmosDbAccountName> <resourceGroupName> <aiFoundryName>"
4042
exit 1
4143
fi
4244

45+
# Authenticate with Azure
46+
if az account show &> /dev/null; then
47+
echo "Already authenticated with Azure."
48+
else
49+
if [ -n "$managedIdentityClientId" ]; then
50+
# Use managed identity if running in Azure
51+
echo "Authenticating with Managed Identity..."
52+
az login --identity --client-id ${managedIdentityClientId}
53+
else
54+
# Use Azure CLI login if running locally
55+
echo "Authenticating with Azure CLI..."
56+
az login
57+
fi
58+
echo "Not authenticated with Azure. Attempting to authenticate..."
59+
fi
60+
61+
#check if user has selected the correct subscription
62+
currentSubscriptionId=$(az account show --query id -o tsv)
63+
currentSubscriptionName=$(az account show --query name -o tsv)
64+
if [ "$currentSubscriptionId" != "$azSubscriptionId" ]; then
65+
echo "Current selected subscription is $currentSubscriptionName ( $currentSubscriptionId )."
66+
read -rp "Do you want to continue with this subscription?(y/n): " confirmation
67+
if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then
68+
echo "Fetching available subscriptions..."
69+
availableSubscriptions=$(az account list --query "[?state=='Enabled'].[name,id]" --output tsv)
70+
while true; do
71+
echo ""
72+
echo "Available Subscriptions:"
73+
echo "========================"
74+
echo "$availableSubscriptions" | awk '{printf "%d. %s ( %s )\n", NR, $1, $2}'
75+
echo "========================"
76+
echo ""
77+
read -rp "Enter the number of the subscription (1-$(echo "$availableSubscriptions" | wc -l)) to use: " subscriptionIndex
78+
if [[ "$subscriptionIndex" =~ ^[0-9]+$ ]] && [ "$subscriptionIndex" -ge 1 ] && [ "$subscriptionIndex" -le $(echo "$availableSubscriptions" | wc -l) ]; then
79+
selectedSubscription=$(echo "$availableSubscriptions" | sed -n "${subscriptionIndex}p")
80+
selectedSubscriptionName=$(echo "$selectedSubscription" | cut -f1)
81+
selectedSubscriptionId=$(echo "$selectedSubscription" | cut -f2)
82+
83+
# Set the selected subscription
84+
if az account set --subscription "$selectedSubscriptionId"; then
85+
echo "Switched to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )"
86+
break
87+
else
88+
echo "Failed to switch to subscription: $selectedSubscriptionName ( $selectedSubscriptionId )."
89+
fi
90+
else
91+
echo "Invalid selection. Please try again."
92+
fi
93+
done
94+
else
95+
echo "Proceeding with the current subscription: $currentSubscriptionName ( $currentSubscriptionId )"
96+
az account set --subscription "$currentSubscriptionId"
97+
fi
98+
else
99+
echo "Proceeding with the subscription: $currentSubscriptionName ( $currentSubscriptionId )"
100+
az account set --subscription "$currentSubscriptionId"
101+
fi
102+
43103
# Call add_cosmosdb_access.sh
44104
echo "Running add_cosmosdb_access.sh"
45105
bash infra/scripts/add_cosmosdb_access.sh "$resourceGroupName" "$cosmosDbAccountName" "$managedIdentityClientId"

0 commit comments

Comments
 (0)