Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add / postdeploy hook for data #252

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ hooks:
postprovision:
posix:
shell: sh
continueOnError: false
continueOnError: true
interactive: true
run: infra/hooks/postprovision.sh
windows:
shell: pwsh
continueOnError: false
continueOnError: true
interactive: true
run: infra/hooks/postprovision.ps1
postdeploy:
posix:
shell: sh
continueOnError: true
interactive: true
run: infra/hooks/postdeploy.sh
windows:
shell: pwsh
continueOnError: true
interactive: true
run: infra/hooks/postdeploy.ps1
infra:
provider: "bicep"

Expand Down
17 changes: 17 additions & 0 deletions infra/hooks/postdeploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env pwsh

Write-Host "--- ☑️ 1. Starting postdeploy ---"

# -----------------------------------------------------------
# Setup to run notebooks
python -m pip install -r ./src/api/requirements.txt > $null
Write-Host "---- ✅ 3. Installed required dependencies ---"

# -----------------------------------------------------------
# Run notebooks to populate data
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/customer_info/create-cosmos-db.ipynb > $null
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/product_info/create-azure-search.ipynb > $null
Write-Host "---- ✅ 4. Completed populating data ---"

# -----------------------------------------------------------
Write-Host "--- ✅ Completed postdeploy ---"
20 changes: 20 additions & 0 deletions infra/hooks/postdeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

echo "--- ☑️ Starting postpdeploy ---"

# -----------------------------------------------------------
# Setup to run notebooks
python -m pip install -r ./src/api/requirements.txt > /dev/null
python -m pip install ipython ipykernel > /dev/null # Install ipython and ipykernel
ipython kernel install --name=python3 --user > /dev/null # Configure the IPython kernel
jupyter kernelspec list > /dev/null # Verify kernelspec list isn't empty
echo "---- ✅ 3. Installed required dependencies ---"

# -----------------------------------------------------------
# Run notebooks to populate data
echo "Populating data ...."
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/customer_info/create-cosmos-db.ipynb > /dev/null
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/product_info/create-azure-search.ipynb > /dev/null
echo "---- ✅ 4. Completed populating data ---"

echo "--- ✅ Completed postdeploy ---"
32 changes: 17 additions & 15 deletions infra/hooks/postprovision.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env pwsh

Write-Host "Starting postprovisioning..."
Write-Host "--- ☑️ 1. Starting postprovisioning ---"

# -----------------------------------------------------------
# Retrieve service names, resource group name, and other values from environment variables

# Retrieve service names, resource group name, and other values from environment variables
$resourceGroupName = $env:AZURE_RESOURCE_GROUP
Expand All @@ -23,25 +26,24 @@ Write-Host "azureSearchEndpoint: $azureSearchEndpoint"

# Ensure all required environment variables are set
if ([string]::IsNullOrEmpty($resourceGroupName) -or [string]::IsNullOrEmpty($openAiService) -or [string]::IsNullOrEmpty($subscriptionId)) {
Write-Host "One or more required environment variables are not set."
Write-Host "🅇 One or more required environment variables are not set."
Write-Host "Ensure that AZURE_RESOURCE_GROUP, AZURE_OPENAI_NAME, AZURE_SUBSCRIPTION_ID are set."
exit 1
}

# Set additional environment variables expected by app
# --- Removed these since they are already set in azd env refresh ---
# azd env set AZURE_OPENAI_API_VERSION $AZURE_OPENAI_API_VERSION # 2023-03-15-preview
# azd env set AZURE_OPENAI_CHAT_DEPLOYMENT AZURE_OPENAI_API_VERSION # gpt-35-turbo
# azd env set AZURE_SEARCH_ENDPOINT $AZURE_SEARCH_ENDPOINT

# Output environment variables to .env file using azd env get-values
azd env get-values > .env
Write-Host "Script execution completed successfully."
#Write-Host "--- ✅ 2. Set environment variables ---"

# -----------------------------------------------------------
# Setup to run notebooks
#python -m pip install -r ./src/api/requirements.txt > $null
#Write-Host "---- ✅ 3. Installed required dependencies ---"

Write-Host 'Installing dependencies from "requirements.txt"'
python -m pip install -r ./src/api/requirements.txt > $null
# -----------------------------------------------------------
# Run notebooks to populate data
#jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/customer_info/create-cosmos-db.ipynb > $null
#jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/product_info/create-azure-search.ipynb > $null
#Write-Host "---- ✅ 4. Completed populating data ---"

# populate data
Write-Host "Populating data ...."
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/customer_info/create-cosmos-db.ipynb > $null
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/product_info/create-azure-search.ipynb > $null
Write-Host "--- ✅ Completed postprovisioning ---"
31 changes: 6 additions & 25 deletions infra/hooks/postprovision.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

echo "--- ☑️ Starting postprovisioning ---"

# -----------------------------------------------------------
# Retrieve service names, resource group name, and other values from environment variables
resourceGroupName=$AZURE_RESOURCE_GROUP
searchService=$AZURE_SEARCH_NAME
Expand All @@ -14,33 +17,11 @@ if [ -z "$resourceGroupName" ] || [ -z "$searchService" ] || [ -z "$openAiServic
exit 1
fi

# Set additional environment variables expected by app
# --- Removed these since they are already set in azd env refresh ---
# azd env set AZURE_OPENAI_API_VERSION $AZURE_OPENAI_API_VERSION # 2023-03-15-preview
# azd env set AZURE_OPENAI_CHAT_DEPLOYMENT AZURE_OPENAI_CHAT_DEPLOYMENT # gpt-35-turbo
# azd env set AZURE_SEARCH_ENDPOINT $AZURE_SEARCH_ENDPOINT


# Output environment variables to .env file using azd env get-values
azd env get-values >.env
echo "--- ✅ 2. Set environment variables ---"

echo "--- ✅ | 1. Post-provisioning - env configured ---"

# Setup to run notebooks
echo 'Installing dependencies from "requirements.txt"'
python -m pip install -r ./src/api/requirements.txt > /dev/null
python -m pip install ipython ipykernel > /dev/null # Install ipython and ipykernel
ipython kernel install --name=python3 --user > /dev/null # Configure the IPython kernel
jupyter kernelspec list > /dev/null # Verify kernelspec list isn't empty
echo "--- ✅ | 2. Post-provisioning - ready execute notebooks ---"

echo "Populating data ...."
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/customer_info/create-cosmos-db.ipynb > /dev/null
jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 data/product_info/create-azure-search.ipynb > /dev/null
echo "--- ✅ | 3. Post-provisioning - populated data ---"

#echo "Running evaluations ...."
#jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 evaluations/evaluate-chat-flow-sdk.ipynb
#jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 evaluations/evaluate-chat-flow-custom-no-sdk.ipynb
#jupyter nbconvert --execute --to python --ExecutePreprocessor.timeout=-1 evaluations/evaluate-chat-flow-custom.ipynb
#echo "--- ✅ | 4. Post-provisioning - ran evaluations ---"
echo "--- ✅ Completed postprovisioning ---"
# -----------------------------------------------------------
Loading