Trying to automate my deployments with powershell, because I have multiple endpoints.
I ended up building this ps1 file
<code>param(
[string]$subscriptionId,
[string]$resourceGroup,
[string[]]$functionAppNames,
[bool]$build = $true,
[bool]$deleteBuild = $true
)
clear
if ($build) {
# # Build your NestJS app
npm run build
# Zip it up
powershell Compress-Archive -Path .dist* -Update -DestinationPath dist.zip # slow...
# & "C:Program Files7-Zip7z.exe" a -r "dist.zip" ".dist*"
}
# Login to Azure and set the subscription
az login
az account set --subscription $subscriptionId
# Publish to each function app
foreach ($functionAppName in $functionAppNames) {
Write-Host "Deploying to function app: $functionAppName"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "SCM_DO_BUILD_DURING_DEPLOYMENT=true"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "WEBSITE_RUN_FROM_PACKAGE=1"
# tried both with no success...
az functionapp deployment source config-zip -g $resourceGroup -n $functionAppName --src .dist.zip
# Publish-AzWebapp -ResourceGroupName $ResourceGroup -Name $functionAppName -ArchivePath .dist.zip
}
if ($deleteBuild) {
Remove-Item .dist.zip
Remove-Item .dist -Recurse
}
</code>
<code>param(
[string]$subscriptionId,
[string]$resourceGroup,
[string[]]$functionAppNames,
[bool]$build = $true,
[bool]$deleteBuild = $true
)
clear
if ($build) {
# # Build your NestJS app
npm run build
# Zip it up
powershell Compress-Archive -Path .dist* -Update -DestinationPath dist.zip # slow...
# & "C:Program Files7-Zip7z.exe" a -r "dist.zip" ".dist*"
}
# Login to Azure and set the subscription
az login
az account set --subscription $subscriptionId
# Publish to each function app
foreach ($functionAppName in $functionAppNames) {
Write-Host "Deploying to function app: $functionAppName"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "SCM_DO_BUILD_DURING_DEPLOYMENT=true"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "WEBSITE_RUN_FROM_PACKAGE=1"
# tried both with no success...
az functionapp deployment source config-zip -g $resourceGroup -n $functionAppName --src .dist.zip
# Publish-AzWebapp -ResourceGroupName $ResourceGroup -Name $functionAppName -ArchivePath .dist.zip
}
if ($deleteBuild) {
Remove-Item .dist.zip
Remove-Item .dist -Recurse
}
</code>
param(
[string]$subscriptionId,
[string]$resourceGroup,
[string[]]$functionAppNames,
[bool]$build = $true,
[bool]$deleteBuild = $true
)
clear
if ($build) {
# # Build your NestJS app
npm run build
# Zip it up
powershell Compress-Archive -Path .dist* -Update -DestinationPath dist.zip # slow...
# & "C:Program Files7-Zip7z.exe" a -r "dist.zip" ".dist*"
}
# Login to Azure and set the subscription
az login
az account set --subscription $subscriptionId
# Publish to each function app
foreach ($functionAppName in $functionAppNames) {
Write-Host "Deploying to function app: $functionAppName"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "SCM_DO_BUILD_DURING_DEPLOYMENT=true"
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings "WEBSITE_RUN_FROM_PACKAGE=1"
# tried both with no success...
az functionapp deployment source config-zip -g $resourceGroup -n $functionAppName --src .dist.zip
# Publish-AzWebapp -ResourceGroupName $ResourceGroup -Name $functionAppName -ArchivePath .dist.zip
}
if ($deleteBuild) {
Remove-Item .dist.zip
Remove-Item .dist -Recurse
}
But for some reason, after the deployment is finished, there are no functions in my Function App.
OS: Windows
Plan: Consumption
PS: If I do the deployment using Visual Code (ctrl + P and selecting the instance), everything’s working fine. I want to replicate the same steps, but can’t find a way to make it work.