Last active
May 7, 2025 07:08
-
-
Save solita-tonimiettinen/5ff4bde67f124b9183c83ea49c890c36 to your computer and use it in GitHub Desktop.
Deploy function app to a Function with only private access to function endpoints
This file contains hidden or 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
| #!/bin/bash | |
| # This script basically does what Azure/functions-action@v1 github action does | |
| # when it detects a flex consumption function app. | |
| # Create a zip package of the app (dotnet publish --configuration Release --output staging, and zip folder contents) | |
| # You must be logged in with az login, and set $ARM_SUBSCRIPTION_ID variable | |
| # Agent must have az cli, curl, jq, xmllint installed (GH agents have all but xmllint) | |
| # param 1: resource group name | |
| # param 2: func app name | |
| # param 3: zip file to deploy | |
| echo "get credentials" | |
| AZ_TOKEN=$(az account get-access-token | jq -r .accessToken) | |
| PUBLISHPROFILE=$(curl -s -X POST -H "Content-Length:0" -H "Authorization:Bearer $AZ_TOKEN" "https://management.azure.com/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$1/providers/Microsoft.Web/sites/$2/publishxml?api-version=2022-03-01") | |
| PWD=$(echo $PUBLISHPROFILE | xmllint --xpath 'string(//publishProfile[@publishMethod="ZipDeploy"]/@userPWD)' -) | |
| USER=$(echo $PUBLISHPROFILE | xmllint --xpath 'string(//publishProfile[@publishMethod="ZipDeploy"]/@userName)' -) | |
| CREDS="${USER}:${PWD}" | |
| SCMURL="https://$2.scm.azurewebsites.net/api" | |
| echo "deploy zip ${SCMURL}" | |
| DRESP=$(curl -sS -X POST -H "Content-Type:application/zip" -u "$CREDS" -T $3 "$SCMURL/publish") | |
| DEPLO_ID=$(echo $DRESP | tr -d '"') | |
| echo "deployment id: $DEPLO_ID" | |
| echo -n "waiting for deployment to complete..." | |
| COMPLETE="false" | |
| while [ "$COMPLETE" = "false" ]; do # poll for status with deployment id | |
| sleep 5 | |
| DSTATUS=$(curl -sS --fail -u "$CREDS" "$SCMURL/deployments/$DEPLO_ID") # .complete, .status, .status_text | |
| COMPLETE=$(echo $DSTATUS | jq -r ".complete") | |
| echo -n "." | |
| done | |
| echo "" | |
| echo "deployment complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment