Azure Web App run from package demo
$location = "West Europe" | |
$resGroupName = "RunFromPackageDemo" | |
az group create -n $resGroupName -l $location | |
$random = Get-Random -Minimum 10000 -Maximum 99999 | |
$storageAccountName = "runfrompackage$random" | |
az storage account create -n $storageAccountName -g $resGroupName --sku "Standard_LRS" | |
$connectionString = az storage account show-connection-string -n $storageAccountName -g $resGroupName --query "connectionString" -o tsv | |
$env:AZURE_STORAGE_CONNECTION_STRING = $connectionString | |
$containerName = "assets" | |
az storage container create -n $containerName --public-access off | |
Function ZipAndUpload { | |
Param ([string]$InputPath, [string] $ZipName) | |
Compress-Archive -Path $InputPath -DestinationPath $ZipName | |
$blobName = $ZipName # name them the same | |
$_ = az storage blob upload -c $containerName -f $ZipName -n $blobName | |
$blobUrl = az storage blob url -c $containerName -n $blobName -o tsv | |
$expiry = (Get-Date).ToUniversalTime().AddYears(5).ToString("yyyy-MM-dd\THH\:mm\Z") | |
$sas = az storage blob generate-sas -c $containerName -n $blobName ` | |
--permissions r -o tsv ` | |
--expiry $expiry | |
return "$($blobUrl)?$($sas)" | |
} | |
Write-Output "<h1>Version 3</h1>" > "index.html" | |
$uriV1 = (ZipAndUpload -InputPath "index.html" -ZipName "version3.zip").Replace("&","^^^&") | |
# n.b. very difficult to set app settings containing SAS URI, hence | |
# ugly escaping | |
# https://github.com/Azure/azure-cli/issues/5228 and | |
# https://github.com/Azure/azure-cli/issues/7147 | |
$appServicePlanName = "RunFromPackageDemo" | |
az appservice plan create -n $appServicePlanName -g $resGroupName --sku B1 | |
$webAppName = "runfrompackage$random" | |
az webapp create -n $webAppName -g $resGroupName --plan $appServicePlanName | |
# https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package | |
az webapp config appsettings set -n $webAppName -g $resGroupName ` | |
--settings "WEBSITE_RUN_FROM_PACKAGE=$uriV1" | |
$hostName = az webapp show -n $webAppName -g $resGroupName --query "defaultHostName" -o tsv | |
# https://docs.microsoft.com/en-us/rest/api/appservice/webapps/listapplicationsettings | |
# https://docs.microsoft.com/en-us/rest/api/appservice/webapps/updateapplicationsettings | |
Start-Process "https://$hostName" | |
Write-Output "<h1>Version 4</h1>" > "index.html" | |
$uriV2 = (ZipAndUpload -InputPath "index.html" -ZipName "version4.zip").Replace("&","^^^&") | |
az webapp config appsettings set -n $webAppName -g $resGroupName ` | |
--settings "WEBSITE_RUN_FROM_PACKAGE=$uriV2" | |
Start-Process "https://$hostName" | |
#### Now local | |
$webAppName = "runfromlocal$random" | |
az webapp create -n $webAppName -g $resGroupName --plan $appServicePlanName | |
$hostName = az webapp show -n $webAppName -g $resGroupName --query "defaultHostName" -o tsv | |
az webapp config appsettings set -n $webAppName -g $resGroupName ` | |
--settings "WEBSITE_RUN_FROM_PACKAGE=1" | |
az webapp deployment source config-zip -n $webAppName -g $resGroupName --src version3.zip | |
Start-Process "https://$hostName" | |
az webapp deployment source config-zip -n $webAppName -g $resGroupName --src version4.zip | |
# https://runfromlocal86687.scm.azurewebsites.net/DebugConsole | |
# D:\home\data\SitePackages>dir | |
# Volume in drive D is Windows | |
# Volume Serial Number is E859-323E | |
# | |
# Directory of D:\home\data\SitePackages | |
# | |
# 01/14/2019 02:49 PM <DIR> . | |
# 01/14/2019 02:49 PM <DIR> .. | |
# 01/14/2019 02:47 PM 157 20190114144716.zip | |
# 01/14/2019 02:49 PM 157 20190114144929.zip | |
# 01/14/2019 02:49 PM 18 packagename.txt | |
# 3 File(s) 332 bytes | |
# 2 Dir(s) 10,737,258,496 bytes free | |
# | |
# D:\home\data\SitePackages>type packagename.txt | |
# 20190114144929.zip | |
# D:\home\site\wwwroot>dir | |
# Volume in drive D is Windows | |
# Volume Serial Number is E859-323E | |
# | |
# Directory of D:\home\site\wwwroot | |
# | |
# 01/14/2019 02:43 PM 42 index.html | |
# 1 File(s) 42 bytes | |
# 0 Dir(s) 0 bytes free | |
# | |
# D:\home\site\wwwroot> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment