|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# Get the directory where this script is located |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | + |
3 | 6 | # Variables - Grouped by service for clarity |
4 | 7 | # General Azure |
5 | 8 | resourceGroupName="${1}" |
@@ -345,6 +348,92 @@ get_values_from_azd_env() { |
345 | 348 | return 0 |
346 | 349 | } |
347 | 350 |
|
| 351 | +get_values_from_az_deployment() { |
| 352 | + echo "Getting values from Azure deployment outputs..." |
| 353 | + |
| 354 | + deploymentName=$(az group show --name "$resourceGroupName" --query "tags.DeploymentName" -o tsv) |
| 355 | + echo "Deployment Name (from tag): $deploymentName" |
| 356 | + |
| 357 | + echo "Fetching deployment outputs..." |
| 358 | + # Get all outputs |
| 359 | + deploymentOutputs=$(az deployment group show \ |
| 360 | + --name "$deploymentName" \ |
| 361 | + --resource-group "$resourceGroupName" \ |
| 362 | + --query "properties.outputs" -o json) |
| 363 | + |
| 364 | + # Helper function to extract value from deployment outputs |
| 365 | + # Usage: extract_value "primaryKey" "fallbackKey" |
| 366 | + extract_value() { |
| 367 | + local primary_key="$1" |
| 368 | + local fallback_key="$2" |
| 369 | + local value |
| 370 | + |
| 371 | + value=$(echo "$deploymentOutputs" | grep -A 3 "\"$primary_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/') |
| 372 | + if [ -z "$value" ] && [ -n "$fallback_key" ]; then |
| 373 | + value=$(echo "$deploymentOutputs" | grep -A 3 "\"$fallback_key\"" | grep '"value"' | sed 's/.*"value": *"\([^"]*\)".*/\1/') |
| 374 | + fi |
| 375 | + echo "$value" |
| 376 | + } |
| 377 | + |
| 378 | + # Extract each value using the helper function |
| 379 | + storageAccountName=$(extract_value "storageAccountName" "storagE_ACCOUNT_NAME") |
| 380 | + fileSystem=$(extract_value "storageContainerName" "storagE_CONTAINER_NAME") |
| 381 | + sqlServerName=$(extract_value "sqlDBServer" "sqldB_SERVER") |
| 382 | + SqlDatabaseName=$(extract_value "sqlDBDatabase" "sqldB_DATABASE") |
| 383 | + backendUserMidClientId=$(extract_value "backendUserMid" "backenD_USER_MID") |
| 384 | + backendUserMidDisplayName=$(extract_value "backendUserMidName" "backenD_USER_MID_NAME") |
| 385 | + aiSearchName=$(extract_value "azureAISearchName" "azurE_AI_SEARCH_NAME") |
| 386 | + searchEndpoint=$(extract_value "azureAISearchEndpoint" "azurE_AI_SEARCH_ENDPOINT") |
| 387 | + aif_resource_id=$(extract_value "aiFoundryResourceId" "aI_FOUNDRY_RESOURCE_ID") |
| 388 | + cu_foundry_resource_id=$(extract_value "cuFoundryResourceId" "cU_FOUNDRY_RESOURCE_ID") |
| 389 | + openaiEndpoint=$(extract_value "azureOpenAIEndpoint" "azurE_OPENAI_ENDPOINT") |
| 390 | + embeddingModel=$(extract_value "azureOpenAIEmbeddingModel" "azurE_OPENAI_EMBEDDING_MODEL") |
| 391 | + cuEndpoint=$(extract_value "azureOpenAICuEndpoint" "azurE_OPENAI_CU_ENDPOINT") |
| 392 | + aiAgentEndpoint=$(extract_value "azureAiAgentEndpoint" "azurE_AI_AGENT_ENDPOINT") |
| 393 | + cuApiVersion=$(extract_value "azureContentUnderstandingApiVersion" "azurE_CONTENT_UNDERSTANDING_API_VERSION") |
| 394 | + deploymentModel=$(extract_value "azureOpenAIDeploymentModel" "azurE_OPENAI_DEPLOYMENT_MODEL") |
| 395 | + usecase=$(extract_value "useCase" "usE_CASE") |
| 396 | + |
| 397 | + # Strip FQDN suffix from SQL server name if present (Azure CLI needs just the server name) |
| 398 | + sqlServerName="${sqlServerName%.database.windows.net}" |
| 399 | + |
| 400 | + # Define required values with their display names for error reporting |
| 401 | + declare -A required_values=( |
| 402 | + ["storageAccountName"]="STORAGE_ACCOUNT_NAME" |
| 403 | + ["fileSystem"]="STORAGE_CONTAINER_NAME" |
| 404 | + ["sqlServerName"]="SQLDB_SERVER" |
| 405 | + ["SqlDatabaseName"]="SQLDB_DATABASE" |
| 406 | + ["backendUserMidClientId"]="BACKEND_USER_MID" |
| 407 | + ["backendUserMidDisplayName"]="BACKEND_USER_MID_NAME" |
| 408 | + ["aiSearchName"]="AZURE_AI_SEARCH_NAME" |
| 409 | + ["aif_resource_id"]="AI_FOUNDRY_RESOURCE_ID" |
| 410 | + ["cu_foundry_resource_id"]="CU_FOUNDRY_RESOURCE_ID" |
| 411 | + ["searchEndpoint"]="AZURE_AI_SEARCH_ENDPOINT" |
| 412 | + ["openaiEndpoint"]="AZURE_OPENAI_ENDPOINT" |
| 413 | + ["embeddingModel"]="AZURE_OPENAI_EMBEDDING_MODEL" |
| 414 | + ["cuEndpoint"]="AZURE_OPENAI_CU_ENDPOINT" |
| 415 | + ["aiAgentEndpoint"]="AZURE_AI_AGENT_ENDPOINT" |
| 416 | + ["cuApiVersion"]="AZURE_CONTENT_UNDERSTANDING_API_VERSION" |
| 417 | + ["deploymentModel"]="AZURE_OPENAI_DEPLOYMENT_MODEL" |
| 418 | + ["usecase"]="USE_CASE" |
| 419 | + ) |
| 420 | + |
| 421 | + # Validate and collect missing values |
| 422 | + missing_values=() |
| 423 | + for var_name in "${!required_values[@]}"; do |
| 424 | + if [ -z "${!var_name}" ]; then |
| 425 | + missing_values+=("${required_values[$var_name]}") |
| 426 | + fi |
| 427 | + done |
| 428 | + |
| 429 | + if [ ${#missing_values[@]} -gt 0 ]; then |
| 430 | + echo "Error: The following required values could not be retrieved from Azure deployment outputs:" |
| 431 | + printf ' - %s\n' "${missing_values[@]}" | sort |
| 432 | + return 1 |
| 433 | + fi |
| 434 | + return 0 |
| 435 | +} |
| 436 | + |
348 | 437 | # Check if user is logged in to Azure |
349 | 438 | echo "Checking Azure authentication..." |
350 | 439 | if az account show &> /dev/null; then |
|
404 | 493 | echo "" |
405 | 494 |
|
406 | 495 | echo "" |
407 | | -if ! get_values_from_azd_env; then |
408 | | - echo "Failed to get values from azd environment." |
409 | | - echo "" |
410 | | - exit 1 |
| 496 | + |
| 497 | +if [ -z "$resourceGroupName" ]; then |
| 498 | + # No resource group provided - use azd env |
| 499 | + if ! get_values_from_azd_env; then |
| 500 | + echo "Failed to get values from azd environment." |
| 501 | + echo "" |
| 502 | + echo "If you want to use deployment outputs instead, please provide the resource group name as an argument." |
| 503 | + echo "Usage: $0 [ResourceGroupName]" |
| 504 | + echo "Example: $0 my-resource-group" |
| 505 | + echo "" |
| 506 | + exit 1 |
| 507 | + fi |
| 508 | +else |
| 509 | + # Resource group provided - use deployment outputs |
| 510 | + echo "" |
| 511 | + echo "Resource group provided: $resourceGroupName" |
| 512 | + |
| 513 | + # Call deployment function |
| 514 | + if ! get_values_from_az_deployment; then |
| 515 | + echo "Failed to get values from deployment outputs." |
| 516 | + echo "" |
| 517 | + echo "Would you like to enter the values manually? (y/n): " |
| 518 | + read -r manual_input_choice |
| 519 | + if [[ "$manual_input_choice" == "y" || "$manual_input_choice" == "Y" ]]; then |
| 520 | + if ! get_values_from_user; then |
| 521 | + echo "Error: Manual input failed." |
| 522 | + exit 1 |
| 523 | + fi |
| 524 | + else |
| 525 | + echo "Exiting script." |
| 526 | + exit 1 |
| 527 | + fi |
| 528 | + fi |
411 | 529 | fi |
412 | 530 |
|
413 | 531 | echo "" |
@@ -441,7 +559,7 @@ if [ $? -ne 0 ]; then |
441 | 559 | exit 1 |
442 | 560 | fi |
443 | 561 |
|
444 | | -pythonScriptPath="infra/scripts/index_scripts/" |
| 562 | +pythonScriptPath="$SCRIPT_DIR/index_scripts/" |
445 | 563 |
|
446 | 564 | # Install the requirements |
447 | 565 | pip install --quiet -r ${pythonScriptPath}requirements.txt |
|
452 | 570 |
|
453 | 571 | # Create Content Understanding analyzers |
454 | 572 | echo "✓ Creating Content Understanding analyzer templates" |
455 | | -python infra/scripts/index_scripts/02_create_cu_template_text.py --cu_endpoint="$cuEndpoint" --cu_api_version="$cuApiVersion" |
| 573 | +python "${pythonScriptPath}02_create_cu_template_text.py" --cu_endpoint="$cuEndpoint" --cu_api_version="$cuApiVersion" |
456 | 574 | if [ $? -ne 0 ]; then |
457 | 575 | echo "Error: 02_create_cu_template_text.py failed." |
458 | 576 | exit 1 |
459 | 577 | fi |
460 | 578 |
|
461 | | -python infra/scripts/index_scripts/02_create_cu_template_audio.py --cu_endpoint="$cuEndpoint" --cu_api_version="$cuApiVersion" |
| 579 | +python "${pythonScriptPath}02_create_cu_template_audio.py" --cu_endpoint="$cuEndpoint" --cu_api_version="$cuApiVersion" |
462 | 580 | if [ $? -ne 0 ]; then |
463 | 581 | echo "Error: 02_create_cu_template_audio.py failed." |
464 | 582 | exit 1 |
|
467 | 585 | # Run 04_cu_process_custom_data.py |
468 | 586 | echo "✓ Processing custom data" |
469 | 587 | sql_server_fqdn="$sqlServerName.database.windows.net" |
470 | | -python infra/scripts/index_scripts/04_cu_process_custom_data.py \ |
| 588 | +python "${pythonScriptPath}04_cu_process_custom_data.py" \ |
471 | 589 | --search_endpoint "$searchEndpoint" \ |
472 | 590 | --openai_endpoint "$openaiEndpoint" \ |
473 | 591 | --ai_project_endpoint "$aiAgentEndpoint" \ |
|
0 commit comments