@@ -10,29 +10,24 @@ set -euo pipefail
1010# 4) Rules Engine demo via Rule Set + Rule (ep-rules)
1111# 5) Endpoint enabled/disabled state toggle (ep-state)
1212#
13- # It supports deploying to real Azure or to LocalStack’s Azure emulator via azlocal interception.
1413# By default, all scenarios are deployed. You can selectively skip scenarios via flags.
1514#
1615# Requirements
1716# - az CLI
1817# - bash, zip
19- # - Optional for LocalStack mode: azlocal (CLI interceptor), Azure Functions Core Tools (' func' )
18+ # - Optional: Azure Functions Core Tools (‘ func’ )
2019#
2120# Examples
2221# # Real Azure (eastus by default)
2322# bash ./scripts/deploy_all.sh --name-prefix demo
2423#
25- # # LocalStack emulator
26- # bash ./scripts/deploy_all.sh --name-prefix demo --use-localstack
27- #
2824
2925# -------------------------------
3026# Defaults (overridable via flags)
3127# -------------------------------
3228NAME_PREFIX=" funcafdall"
3329LOCATION=" eastus"
3430RESOURCE_GROUP=" "
35- USE_LOCALSTACK=" false"
3631PYTHON_VERSION=" 3.11"
3732
3833# Scenario toggles
@@ -51,7 +46,6 @@ Options:
5146 -l, --location STR Azure region (default: eastus)
5247 -g, --resource-group STR Resource group name (auto-generated if omitted)
5348 --python-version STR Python runtime for Function App(s) (default: 3.11)
54- --use-localstack Use azlocal for LocalStack emulator
5549
5650 # Scenario toggles (all enabled by default)
5751 --no-basic Skip basic single-origin scenario
@@ -70,7 +64,6 @@ while [[ $# -gt 0 ]]; do
7064 -l|--location) LOCATION=${2:- } ; shift 2;;
7165 -g|--resource-group) RESOURCE_GROUP=${2:- } ; shift 2;;
7266 --python-version) PYTHON_VERSION=${2:- } ; shift 2;;
73- --use-localstack) USE_LOCALSTACK=" true" ; shift ;;
7467 --no-basic) DO_BASIC=" false" ; shift ;;
7568 --no-multi) DO_MULTI=" false" ; shift ;;
7669 --no-spec) DO_SPEC=" false" ; shift ;;
@@ -145,45 +138,17 @@ ruleSetName="rs${prefix}${suffix}"
145138ruleName=" ruleAddHeader"
146139
147140# -------------------------------
148- # LocalStack interception lifecycle (optional)
141+ # Cleanup on exit
149142# -------------------------------
150- INTERCEPTION_STARTED=" false"
151- AZURE_CONFIG_DIR_CREATED=" false"
152143finish () {
153144 set +e
154145 [[ -f " $ZIP_MAIN " ]] && rm -f " $ZIP_MAIN "
155146 [[ -f " $ZIP_A " ]] && rm -f " $ZIP_A "
156147 [[ -f " $ZIP_B " ]] && rm -f " $ZIP_B "
157- if [[ " $INTERCEPTION_STARTED " == " true" ]] && command -v azlocal > /dev/null 2>&1 ; then
158- azlocal stop-interception > /dev/null 2>&1 || true
159- fi
160- if [[ " $AZURE_CONFIG_DIR_CREATED " == " true" && -n " ${AZURE_CONFIG_DIR:- } " && -d " $AZURE_CONFIG_DIR " ]]; then
161- rm -rf " $AZURE_CONFIG_DIR "
162- fi
163148 set -e
164149}
165150trap finish EXIT
166151
167- if [[ " $USE_LOCALSTACK " == " true" ]]; then
168- if command -v mktemp > /dev/null 2>&1 ; then
169- AZ_TEMP_CONFIG_DIR=" $( mktemp -d) "
170- else
171- AZ_TEMP_CONFIG_DIR=" $ROOT_DIR /.azlocal_config_$$ " ; mkdir -p " $AZ_TEMP_CONFIG_DIR "
172- fi
173- export AZURE_CONFIG_DIR=" $AZ_TEMP_CONFIG_DIR " ; AZURE_CONFIG_DIR_CREATED=" true"
174- echo " Using isolated AZURE_CONFIG_DIR: $AZURE_CONFIG_DIR "
175- if ! command -v azlocal > /dev/null 2>&1 ; then
176- echo " Error: --use-localstack specified but 'azlocal' not found in PATH." >&2
177- exit 1
178- fi
179- if azlocal start-interception; then
180- INTERCEPTION_STARTED=" true" ; echo " LocalStack interception started."
181- else
182- echo " Error: azlocal failed to start interception. Ensure LocalStack is running." >&2
183- exit 1
184- fi
185- fi
186-
187152echo " Resource Group: $RESOURCE_GROUP "
188153
189154# -------------------------------
@@ -202,35 +167,14 @@ create_function_app() {
202167 --runtime python --runtime-version " $PYTHON_VERSION " \
203168 --functions-version 4 --os-type Linux \
204169 --storage-account " $storageName " --disable-app-insights -o none
205- if [[ " $USE_LOCALSTACK " != " true" ]]; then
206- az functionapp config appsettings set -g " $RESOURCE_GROUP " -n " $funcName " \
207- --settings WEBSITE_RUN_FROM_PACKAGE=1 FUNCTIONS_WORKER_RUNTIME=python SCM_DO_BUILD_DURING_DEPLOYMENT=false -o none
208- else
209- az functionapp config appsettings set -g " $RESOURCE_GROUP " -n " $funcName " \
210- --settings FUNCTIONS_WORKER_RUNTIME=python WEBSITE_RUN_FROM_PACKAGE=0 -o none
211- local STORAGE_KEY
212- STORAGE_KEY=$( az storage account keys list -g " $RESOURCE_GROUP " -n " $storageName " --query " [0].value" -o tsv)
213- if [[ -z " $STORAGE_KEY " ]]; then echo " Failed to get storage key for $storageName " >&2 ; exit 1; fi
214- local STORAGE_CONNECTION_STRING
215- STORAGE_CONNECTION_STRING=" DefaultEndpointsProtocol=http;AccountName=$storageName ;AccountKey=$STORAGE_KEY ;BlobEndpoint=http://$storageName .blob.localhost.localstack.cloud:4566;QueueEndpoint=http://$storageName .queue.localhost.localstack.cloud:4566;TableEndpoint=http://$storageName .table.localhost.localstack.cloud:4566;FileEndpoint=http://$storageName .file.localhost.localstack.cloud:4566"
216- az functionapp config appsettings set -g " $RESOURCE_GROUP " -n " $funcName " \
217- --settings AzureWebJobsStorage=" $STORAGE_CONNECTION_STRING " WEBSITE_CONTENTAZUREFILECONNECTIONSTRING=" $STORAGE_CONNECTION_STRING " SCM_RUN_FROM_PACKAGE= -o none
218- fi
170+ az functionapp config appsettings set -g " $RESOURCE_GROUP " -n " $funcName " \
171+ --settings WEBSITE_RUN_FROM_PACKAGE=1 FUNCTIONS_WORKER_RUNTIME=python SCM_DO_BUILD_DURING_DEPLOYMENT=false -o none
219172}
220173
221174publish_function_code () {
222175 local funcName=" $1 " ; local zipPath=" $2 "
223- if [[ " $USE_LOCALSTACK " == " true" ]]; then
224- if ! command -v func > /dev/null 2>&1 ; then
225- echo " Error: Azure Functions Core Tools ('func') not found in PATH." >&2 ; exit 1
226- fi
227- pushd " $FUNCTION_SRC " > /dev/null
228- func azure functionapp publish " $funcName " --python --build local # --verbose --debug
229- popd > /dev/null
230- else
231- rm -f " $zipPath " ; ( cd " $FUNCTION_SRC " && zip -rq " $zipPath " . )
232- az functionapp deployment source config-zip -g " $RESOURCE_GROUP " -n " $funcName " --src " $zipPath "
233- fi
176+ rm -f " $zipPath " ; ( cd " $FUNCTION_SRC " && zip -rq " $zipPath " . )
177+ az functionapp deployment source config-zip -g " $RESOURCE_GROUP " -n " $funcName " --src " $zipPath "
234178}
235179
236180if [[ " $DO_BASIC " == " true" || " $DO_SPEC " == " true" || " $DO_RULES " == " true" || " $DO_STATE " == " true" ]]; then
@@ -410,11 +354,11 @@ hostBasic=""; hostMulti=""; hostSpec=""; hostRules=""; hostState=""
410354[[ " $DO_RULES " == " true" ]] && hostRules=$( resolve_ep_host " $epRules " )
411355[[ " $DO_STATE " == " true" ]] && hostState=$( resolve_ep_host " $epState " )
412356
413- # Local addresses for emulator
414- if [[ " $USE_LOCALSTACK " == " true " ]] ; then
415- funcMainLocal= " ${funcMain} website.localhost.localstack.cloud:4566 "
416- funcALocal= " ${funcA} website.localhost.localstack.cloud:4566 "
417- funcBLocal= " ${funcB} website.localhost.localstack.cloud:4566 "
357+ # Detect LocalStack environment for local URLs
358+ IS_LOCALSTACK= " false "
359+ ENVIRONMENT= $( az account show --query environmentName --output tsv 2> /dev/null || true )
360+ if [[ " $ENVIRONMENT " == " LocalStack " ]] ; then
361+ IS_LOCALSTACK= " true "
418362 epBasicLocal=" ${epBasic} .afd.localhost.localstack.cloud:4566"
419363 epMultiLocal=" ${epMulti} .afd.localhost.localstack.cloud:4566"
420364 epSpecLocal=" ${epSpec} .afd.localhost.localstack.cloud:4566"
@@ -446,44 +390,29 @@ echo
446390echo " Deployment complete."
447391echo " Resource Group: $RESOURCE_GROUP "
448392if [[ " $DO_BASIC " == " true" ]]; then
449- if [[ " $USE_LOCALSTACK " == " true" ]]; then
450- echo " [Basic] AFD Local Endpoint: https://$epBasicLocal /john"
451- else
452- echo " [Basic] AFD Endpoint: https://$hostBasic /john"
453- fi
393+ echo " [Basic] AFD Endpoint: https://$hostBasic /john"
394+ [[ " $IS_LOCALSTACK " == " true" ]] && echo " Local Endpoint: http://$epBasicLocal /john"
454395fi
455396if [[ " $DO_MULTI " == " true" ]]; then
456- if [[ " $USE_LOCALSTACK " == " true" ]]; then
457- echo " [Multi] AFD Local Endpoint: https://$epMultiLocal /john"
458- echo " You can inspect responses to see which origin served them (function echoes WEBSITE_HOSTNAME)."
459- else
460- echo " [Multi] AFD Endpoint: https://$hostMulti /john"
461- fi
397+ echo " [Multi] AFD Endpoint: https://$hostMulti /john"
398+ [[ " $IS_LOCALSTACK " == " true" ]] && echo " Local Endpoint: http://$epMultiLocal /john"
462399fi
463400if [[ " $DO_SPEC " == " true" ]]; then
464- if [[ " $USE_LOCALSTACK " == " true" ]]; then
465- echo " [Spec] AFD Local Endpoint: https://$epSpecLocal /john (specific route)"
466- echo " Also try: https://$epSpecLocal /jane (catch-all)"
467- else
468- echo " [Spec] AFD Endpoint: https://$hostSpec /john (specific route)"
469- echo " Also try: https://$hostSpec /jane (catch-all)"
401+ echo " [Spec] AFD Endpoint: https://$hostSpec /john (specific route)"
402+ echo " Also try: https://$hostSpec /jane (catch-all)"
403+ if [[ " $IS_LOCALSTACK " == " true" ]]; then
404+ echo " Local Endpoint: http://$epSpecLocal /john (specific route)"
405+ echo " Also try: http://$epSpecLocal /jane (catch-all)"
470406 fi
471407fi
472408if [[ " $DO_RULES " == " true" ]]; then
473- if [[ " $USE_LOCALSTACK " == " true" ]]; then
474- echo " [Rules] AFD Local Endpoint: https://$epRulesLocal /john"
475- echo " Expect response header: X-CDN: MSFT (if rules are supported)."
476- else
477- echo " [Rules] AFD Endpoint: https://$hostRules /john"
478- echo " Expect response header: X-CDN: MSFT (once propagation completes)."
479- fi
409+ echo " [Rules] AFD Endpoint: https://$hostRules /john"
410+ echo " Expect response header: X-CDN: MSFT (once propagation completes)."
411+ [[ " $IS_LOCALSTACK " == " true" ]] && echo " Local Endpoint: http://$epRulesLocal /john"
480412fi
481413if [[ " $DO_STATE " == " true" ]]; then
482- if [[ " $USE_LOCALSTACK " == " true" ]]; then
483- echo " [State] AFD Local Endpoint: https://$epStateLocal /john"
484- else
485- echo " [State] AFD Endpoint: https://$hostState /john"
486- fi
414+ echo " [State] AFD Endpoint: https://$hostState /john"
415+ [[ " $IS_LOCALSTACK " == " true" ]] && echo " Local Endpoint: http://$epStateLocal /john"
487416 echo " To test enabled-state toggle:"
488417 echo " az afd endpoint update -g $RESOURCE_GROUP --profile-name $profileName --endpoint-name $epState --enabled-state Disabled"
489418 echo " # Then re-enable:"
0 commit comments