Azure Function - Run From Package deployment

Azure Function - Run From Package deployment

Azure functions is evolving alot and many new improvements have been made. One thing that has been troublesome from time to time has been deployment. Locked files and functions not being correctly updated has been some of the issues I've experienced.

When deploying Azure functions I always use Azure DevOps, it's easy to use and I don't have to worry about deployment after the pipelines have been made. To improve deployment and overcome some of the previous issues the option to "Run from package" has been added sometime during 2018, but it wasn't until I read this thread on GitHub I became aware of it, so let me share it with you .

Getting started

To control this option yourself you need to use version 4.* of the deployment task

If you're running a previous version, the deployment task will by default make a best guess of the best suited deployment method, which might result in unexpected deployment locations of your function files deployed.

Run From Package

Run from package is not brand new thing, it has just been hidden. The official documentation also describes it in details here. The main difference is where the files are deployed to and how the files are being deployed. Before this feature all files would be deployed to the wwwroot folder of the function app. You can explore the files by by navigation to KUDU using this url https://{nameOfYourFunctionapp}.scm.azurewebsites.net/ from here you can navigate the deployed files.

You can also find the link from the Azure portal here:

When navigated, you'll see something similar to this, when not using Run From Package.

With Run From Package the files are now deployed to a new location located at /data/SitePackages/ together with a file named packagename.txt. This file contains the name of the package to use when running the function.

If you download one of the zip files you will see files similar to the ones previously deployed to wwwroot. For more details please read the official documentation.

Enabling Run From package

To enable Run From Package, a few changes need to be made to your deployment tasks in Azure DevOps. As mentioned earlier you need to run version 4.* of the deployment task. Within this task you must explicit set the Deployment method

Deployment method

This ensures the Zip deployment package gets deployed to SitePackages. To ensure the release pipeline has the required package to deploy, a few changes must be made to your build pipelines as well. These has already been very well described in this GitHub issue. Please pay attention to the uncheck of the checkbox. If this is not unchecked, an additional folder will be inside your deployed package and result in a deployment that from an Azure DevOps perspective works, but your Functions will not be running or listed in the Azure Portal. I spent quite a few hours to locate this issue.

Almost there...

After everything is deployed one final step is required to tell the Azure Function runtime to run your functions as a package. Inside the Azure portal ensure the function app's app settings has the key WEBSITE_RUN_FROM_PACKAGE and it has the value of 1

By default this is added when you're using Azure DevOps release pipelines. Now everything is ready to use Run From Package and every change you make and deploy, should be reflected as expected when deployed.