Fix the deployment errors on your free App Service

Fix the deployment errors on your free App Service header image

I love automated deployments. So it is safe to say that in most projects I try to get the deployment pipeline as automated as possible. This is especially true for Azure App Services. I love the fact that I can just push my code to a git or devops repository and the deployment is done. But what if you are using a free App Service?

The problem with Microsoft Teams Apps

And it cannot be a surprise that I like the CLI for Microsoft 365 as well 🚀. So for Microsoft Teams Apps we use that approach to deploy the Teams App using one of the samples. Everything was working flawlessly. Yet for our development environment we picked the free S1 app service plan. And after a while we where hit by errors.

image of the error

After spending some time on this I found out that the free app service plan has a limit of 1GB of storage. And the Teams App deployment is using that storage to store the zip file. So when you are deploying a Teams App that is larger than 1GB you will get the error above. The clue in this case was that the app itself was small enough; but because we where using the Linux Deployment mode the deployed zips where not deleted. So over time all these apps accumulated to over 1 GB in size. And that is when the error started to appear.

The Solution

Once the error was found the solution was straightforward. All we had to do is was to make sure the zip files where deleted after (or right before) a deployment. Doing so can be done using. The script below will delete all the zip files in the data/sitePackages folder. The location used to store the ZIP files during deployment. And it will do so using the vfs api. By adding the ?recursive=true parameter we make sure that all the zip files are deleted.

$resourceGroup = "your-resource-group"
$appName = "app-service-name"

Write-Host "Resetting content"

$user = az webapp deployment list-publishing-profiles -n $appName -g $resourceGroup `
    --query "[?publishMethod=='MSDeploy'].userName" -o tsv

$pass = az webapp deployment list-publishing-profiles -n $appName -g $resourceGroup `
    --query "[?publishMethod=='MSDeploy'].userPWD" -o tsv

Write-Host "Deleting files with publish profile"

$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    Authorization = $basicAuthValue;
    "If-Match"="*"
}

try {
    Invoke-WebRequest -Uri https://$appName.scm.azurewebsites.net/api/vfs/data/SitePackages?recursive=true -Headers $Headers -Method DELETE -ContentType "multipart/form-data"
}
catch {
    Write-Host "Error"
    Write-Host $_
}

Executing this step as part of your release pipeline you can make sure the files are deleted. And that will make sure you can deploy your Teams App to a free App Service.

release pipeline steps

You can read all details about the API used in the Kudu Github documentation. If you are looking for other options like iterating through the files you can write a similar setup before deleting them. In our case we just wanted to delete all contents of the folder as we still have our pipeline artifacts in case we ever want to roll back.

Conclusion

While we are a bit cheap for using the Free APp Service Plan for our dev scenario it is a great way to get started with Microsoft Teams Apps. And with this small trick you can make sure you can deploy your Teams App to a free App Service without being bothered with disk size slowly running out.

Loading comments…