Skip to content

Commit

Permalink
update hello sample to use correct host.json and to support autoscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt committed Apr 2, 2021
1 parent e663c1f commit 3c5c586
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
42 changes: 29 additions & 13 deletions samples/Hello/deploy-on-premium.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#!/usr/bin/pwsh

# review these parameters before running the script
$numNodes=2
$planSku="EP1"
param (
$Plan="EP2",
$MinNodes="1",
$MaxNodes="20",
$Configuration="Release"
)

# read the parameters
. ./settings.ps1

# enter the directory with the release binaries
if (-not (Test-Path -Path ./bin/Release/netcoreapp3.1/bin)) {
throw 'No release binaries found. Must `dotnet build -c Release` first.'
} else {
cd bin/Release/netcoreapp3.1
}
Write-Host Building $Configuration Configuration...
dotnet build -c $Configuration

Write-Host Building $Configuration Configuration...
dotnet build -c $Configuration

# enter the directory with the binaries
Push-Location -Path bin/$Configuration/netcoreapp3.1

# look up the eventhubs namespace connection string
$eventHubsConnectionString = (az eventhubs namespace authorization-rule keys list --resource-group $groupName --namespace-name $namespaceName --name RootManageSharedAccessKey | ConvertFrom-Json).primaryConnectionString

if (-not ((az functionapp list -g $groupName --query "[].name"| ConvertFrom-Json) -contains $functionAppName))
{
Write-Host "Creating Function App..."
az functionapp plan create --resource-group $groupName --name $functionAppName --location $location --sku $planSku
Write-Host "Creating $Plan Function App..."
az functionapp plan create --resource-group $groupName --name $functionAppName --location $location --sku $Plan
az functionapp create --name $functionAppName --storage-account $storageName --plan $functionAppName --resource-group $groupName --functions-version 3
az functionapp config set -n $functionAppName -g $groupName --use-32bit-worker-process false
az functionapp config appsettings set -n $functionAppName -g $groupName --settings EventHubsConnection=$eventHubsConnectionString
Expand All @@ -30,9 +36,19 @@ else
Write-Host "Function app already exists."
}

Write-Host "Configuring Scale..."
az functionapp plan update -g $groupName -n $functionAppName --max-burst $numNodes --number-of-workers $numNodes --min-instances $numNodes
az resource update -n $functionAppName/config/web -g $groupName --set properties.minimumElasticInstanceCount=$numNodes --resource-type Microsoft.Web/sites
Write-Host "Configuring Scale=$MinNodes-$MaxNodes"
az functionapp plan update -g $groupName -n $functionAppName --max-burst $MaxNodes --number-of-workers $MinNodes --min-instances $MinNodes
az resource update -n $functionAppName/config/web -g $groupName --set properties.minimumElasticInstanceCount=$MinNodes --resource-type Microsoft.Web/sites
if ($MinNode -eq $MaxNodes)
{
az resource update -n $functionAppName/config/web -g $groupName --set properties.functionsRuntimeScaleMonitoringEnabled=0 --resource-type Microsoft.Web/sites
}
else
{
az resource update -n $functionAppName/config/web -g $groupName --set properties.functionsRuntimeScaleMonitoringEnabled=1 --resource-type Microsoft.Web/sites
}

Write-Host "Publishing Code to Function App..."
func azure functionapp publish $functionAppName

Pop-Location
1 change: 1 addition & 0 deletions samples/Hello/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"extendedSessionsEnabled": "true",
"UseGracefulShutdown": true,
"storageProvider": {
"type":"Netherite",
"StorageConnectionName": "AzureWebJobsStorage",
"EventHubsConnectionName": "EventHubsConnection"
}
Expand Down

0 comments on commit 3c5c586

Please sign in to comment.