enhance CI workflow to build and package Azure Function app with upda… #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Azure Function | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
zip-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Echo Python version | |
run: python --version | |
- name: Build and Package /az-function python app to app.zip | |
run: | | |
cd az-function | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt --target=".python_packages/lib/site-packages" | |
zip -r ../app.zip . | |
cd .. | |
- name: Azure Login | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Upload app.zip to Azure Storage | |
run: | | |
az storage blob upload -f 'app.zip' --account-name ${{ vars.AZURE_STORAGE_ACCOUNT }} -c ${{ vars.AZURE_STORAGE_CONTAINER }} -n 'app.zip' --overwrite true --auth-mode login | |
url=$(az storage blob url -c ${{ vars.AZURE_STORAGE_CONTAINER }} -n 'app.zip' --account-name ${{ vars.AZURE_STORAGE_ACCOUNT }} --auth-mode login) | |
echo "Blob URL: $url" | |
echo "blob_url=$url" >> $GITHUB_ENV | |
- name: Deploy to Azure Function | |
run: | | |
az functionapp config appsettings set --name ${{ vars.AZURE_FUNCTION_APP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }} \ | |
--settings WEBSITE_RUN_FROM_PACKAGE=${{ env.blob_url }} \ | |
AzureOpenAiApiVersion=${{ vars.AzureOpenAiApiVersion }} \ | |
AzureOpenAiDeployment=${{ vars.AzureOpenAiDeployment }} \ | |
AzureOpenAiEndpoint=${{ vars.AzureOpenAiEndpoint }} \ | |
AzureOpenAiTextTemperature=${{ vars.AzureOpenAiTextTemperature }} \ | |
AzureOpenAiVisionTemperature=${{ vars.AzureOpenAiVisionTemperature }} \ | |
AzureWebJobsStorage__blobServiceUri='https://${{ vars.AZURE_STORAGE_ACCOUNT }}.blob.core.windows.net' \ | |
AzureWebJobsStorage__queueServiceUri='https://${{ vars.AZURE_STORAGE_ACCOUNT }}.queue.core.windows.net' \ | |
AzureWebJobsStorage__tableServiceUri='https://${{ vars.AZURE_STORAGE_ACCOUNT }}.table.core.windows.net' \ | |
WEBSITE_RUN_FROM_PACKAGE_BLOB_MI_RESOURCE_ID=${{ vars.WEBSITE_RUN_FROM_PACKAGE_BLOB_MI_RESOURCE_ID }} | |
az functionapp restart --name ${{ vars.AZURE_FUNCTION_APP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }} |