Skip to content

Commit 79f0677

Browse files
commit post deployment changes
1 parent aef6288 commit 79f0677

3 files changed

Lines changed: 41 additions & 45 deletions

File tree

infra/scripts/post-provision/index_datasets.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ def extract_docx_text(docx_bytes):
8686
print("Usage: python index_datasets.py <storage_account_name> <blob_container_name> <ai_search_endpoint> [<ai_search_index_name>]")
8787
sys.exit(1)
8888

89-
storage_account_name = sys.argv[1]
90-
blob_container_name = sys.argv[2]
91-
ai_search_endpoint = sys.argv[3]
92-
ai_search_index_name = sys.argv[4] if len(sys.argv) > 4 else "sample-dataset-index"
93-
if not ai_search_endpoint.__contains__("search.windows.net"):
89+
# Strip whitespace and trailing CR (Windows CRLF in env values can leave a \r in argv values,
90+
# which produces invalid URLs like 'https://srch-name\r.search.windows.net' -> 400 Bad Request)
91+
storage_account_name = sys.argv[1].strip().strip("\r\n")
92+
blob_container_name = sys.argv[2].strip().strip("\r\n")
93+
ai_search_endpoint = sys.argv[3].strip().strip("\r\n")
94+
ai_search_index_name = (sys.argv[4] if len(sys.argv) > 4 else "sample-dataset-index").strip().strip("\r\n")
95+
if "search.windows.net" not in ai_search_endpoint:
9496
ai_search_endpoint = f"https://{ai_search_endpoint}.search.windows.net"
9597

9698
credential = AzureCliCredential()

infra/scripts/post-provision/post_deploy.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ try {
686686
exit 1
687687
}
688688

689-
$venvPath = "infra/scripts/scriptenv"
689+
$venvPath = "infra/scripts/post-provision/scriptenv"
690690
if (-not (Test-Path $venvPath)) {
691691
Write-Host "Creating virtual environment..."
692692
& $pythonCmd -m venv $venvPath
@@ -699,6 +699,10 @@ try {
699699
else { $null }
700700
if ($activateScript) { . $activateScript }
701701

702+
# Pin pythonCmd to the venv interpreter so subsequent calls always use the venv.
703+
if (Test-Path "$venvPath/Scripts/python.exe") { $pythonCmd = (Resolve-Path "$venvPath/Scripts/python.exe").Path }
704+
elseif (Test-Path "$venvPath/bin/python") { $pythonCmd = (Resolve-Path "$venvPath/bin/python").Path }
705+
702706
Write-Host "Installing Python dependencies..."
703707
pip install --quiet -r infra/scripts/post-provision/requirements.txt
704708

infra/scripts/post-provision/post_deploy.sh

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ get_value_from_deployment() {
231231
local primary_key="$2"
232232
local fallback_key="$3"
233233

234-
python3 - <<PY
234+
"${python_cmd:-python3}" - <<PY
235235
import json
236236
import sys
237237
outputs = json.load(sys.stdin)
@@ -388,10 +388,10 @@ deploy_content_pack() {
388388
return 0
389389
fi
390390

391-
info " Deploying data for content pack: $(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["name"])' "$pack_json_path")"
391+
info " Deploying data for content pack: $("${python_cmd:-python3}" -c 'import json,sys; print(json.load(open(sys.argv[1]))["name"])' "$pack_json_path")"
392392
local had_failure=false
393393

394-
python3 - "$pack_json_path" <<'PY' > "$SCRIPT_DIR/.pack_items.tmp"
394+
"${python_cmd:-python3}" - "$pack_json_path" <<'PY' > "$SCRIPT_DIR/.pack_items.tmp"
395395
import json, sys
396396
pack = json.load(open(sys.argv[1]))
397397
root = sys.argv[1]
@@ -559,12 +559,19 @@ select_subscription() {
559559
}
560560

561561
activate_python_env() {
562-
if command_exists python3; then
563-
python_cmd="python3"
564-
elif command_exists python; then
565-
python_cmd="python"
566-
else
567-
fatal "Python not found. Install Python 3.10+ and add it to PATH."
562+
# Pick a working python interpreter. On Windows, `python3` may resolve to the
563+
# Microsoft Store alias which prints "Python was not found..." instead of running.
564+
# We validate by actually executing it.
565+
for candidate in python3 python python3.exe python.exe; do
566+
if command_exists "$candidate"; then
567+
if "$candidate" -c "import sys" >/dev/null 2>&1; then
568+
python_cmd="$candidate"
569+
break
570+
fi
571+
fi
572+
done
573+
if [ -z "$python_cmd" ]; then
574+
fatal "Python not found or not runnable. Install Python 3.10+ and add it to PATH (and disable Windows App Execution Aliases for python/python3 if on Windows)."
568575
fi
569576

570577
if [ ! -d "$venv_path" ]; then
@@ -574,9 +581,21 @@ activate_python_env() {
574581
info "Virtual environment already exists. Skipping creation."
575582
fi
576583

584+
# Activate the venv (Linux/macOS use bin/, Windows uses Scripts/)
577585
if [ -f "$venv_path/bin/activate" ]; then
578586
# shellcheck disable=SC1091
579587
. "$venv_path/bin/activate"
588+
elif [ -f "$venv_path/Scripts/activate" ]; then
589+
# shellcheck disable=SC1091
590+
. "$venv_path/Scripts/activate"
591+
fi
592+
593+
# Pin python_cmd to the venv interpreter so subsequent calls don't accidentally
594+
# hit the Microsoft Store alias on Windows.
595+
if [ -x "$venv_path/bin/python" ]; then
596+
python_cmd="$venv_path/bin/python"
597+
elif [ -x "$venv_path/Scripts/python.exe" ]; then
598+
python_cmd="$venv_path/Scripts/python.exe"
580599
fi
581600

582601
info "Installing Python dependencies..."
@@ -831,33 +850,4 @@ main() {
831850
echo ""
832851
fi
833852
}
834-
835-
main "$@"uccessfully."
836-
fi
837-
fi
838-
fi
839-
840-
echo ""
841-
if [ "$has_errors" = true ]; then
842-
echo "========================================"
843-
echo " Post-deployment seeding completed with ERRORS"
844-
echo "========================================"
845-
frontend_host="$(azd env get-value webSiteDefaultHostname 2>/dev/null || true)"
846-
if [ -n "$frontend_host" ]; then
847-
echo "Frontend: https://$frontend_host"
848-
fi
849-
echo ""
850-
exit 1
851-
else
852-
echo "========================================"
853-
echo " Post-deployment data seeding complete!"
854-
echo "========================================"
855-
frontend_host="$(azd env get-value webSiteDefaultHostname 2>/dev/null || true)"
856-
if [ -n "$frontend_host" ]; then
857-
echo "Frontend: https://$frontend_host"
858-
fi
859-
echo ""
860-
fi
861-
}
862-
863-
main "$@"
853+
main "$@"

0 commit comments

Comments
 (0)