5 Azure Functions V2 hosting options
Marie Hoeger редактировал(а) эту страницу 2021-01-20 11:04:57 -08:00

⚠️ NOTICE: Outdated documentation. Please see official Microsoft documentation on hosting options deployment methods including enabling "run from package" ⚠️

Azure Functions v2 consists of 2 main components: an open source runtime, and a hosting component.

The runtime component defines the programming model and does the loading and invocation of these functions. The hosting component on Azure facilitates running those functions in the cloud either in a Consumption Plan or a Dedicated Plan.

The runtime is cross-platform and runs on Windows, Mac OS, and Linux. On Azure you the option of Windows or Linux hosting, and both offer Consumption or Dedicated plans.

Platform Consumption Dedicated
Windows windows-consumption windows-dedicated
Linux linux-consumption linux-dedicated

Deployments:

The deployment mechanism depends on the hosting option and not all mechanisms are supported on all hosting options:

Supported deployment methods:

Deployment Method Windows Dedicated† Windows Consumption† Linux Dedicated Linux Consumption Details
WEBSITE_RUN_FROM_PACKAGE = https://... details
WEBSITE_RUN_FROM_PACKAGE = 1 details
curl -XPOST --binary-data /ZipDeploy details
Docker Container details

Windows supports Azure Functions V1 and V2 applications and deployment methods works for both. Linux is V2 only

On Linux Consumption the App Setting is actually called WEBSITE_RUN_FROM_ZIP. We are in the process of renaming that to the more generic WEBSITE_RUN_FROM_PACKAGE as more formats will be added. However if you're deploying to Linux Consumption, that should be WEBSITE_RUN_FROM_ZIP for now

Below is the documentation of each deployment mechanism:

1- WEBSITE_RUN_FROM_PACKAGE = https://....

Set an App Setting WEBSITE_RUN_FROM_PACKAGE to a URL for your package, usually a blob SAS url. This package will become the content of your app.

Best Practices:

  • The URL must always be accessible as long as it's defined in your application. As your application moves across VMs, or restarts the content of the application is always fetched from that location.
  • If you're using Azure Blob Storage make sure the storage account is in the same region as the function app to reduce cross-region traffic and improve download latency and time.

For more details see full documentation at: https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package

2- WEBSITE_RUN_FROM_PACKAGE = 1

Set an App Setting WEBSITE_RUN_FROM_PACKAGE to 1. Then you can deploy using method #3 below. This stores your zip file in your app regular storage, under D:\home\data\SitePackages\xxxx.zip and stores a reference to the one to be use for your app content under D:\home\data\SitePackages\packagename.txt.

Best Practices:

  • Use deployment method #3 below for pushing a zip file. This will take care of storing the zip in the right location and updating packagename.txt automatically.

For more details see full documentation at: https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package

3- curl -XPOST --binary-data /ZipDeploy

You can deploy a zip file to your application using

curl -X POST -u <user> --data-binary @<zipfile> https://{sitename}.scm.azurewebsites.net/api/zipdeploy

Best Practices:

  • It's highly recommended to enable WEBSITE_RUN_FROM_PACKAGE = 1 as mentioned in method #2 above. It's however not requires and without it, the zip archive will be unzipped to D:\home\site\wwwroot

For more details see full documentation at: https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file

4- Docker Container

When running on Linux, you're always running in a Docker Container. However, if you don't want to deal with docker deployments, you can use method #3 above.

If you need to customize your Linux environment, maybe by installing additional packages or utilities, you can use the base image provided here https://hub.docker.com/r/microsoft/azure-functions and add your functions to it. Some sample Dockerfiles for building that are available here https://github.com/Azure/azure-functions-core-tools/tree/master/src/Azure.Functions.Cli/StaticResources

To check the container your Linux app is running you can go to: Platform features -> All settings -> Container settings It's also available through the REST APIs at

https://management.azure.com/subscriptions/../resourceGroups/../providers/Microsoft.Web/sites/../config/web?api-version=2018-02-01

as linuxFxVersion.

By default it'll be one of the images in https://hub.docker.com/r/microsoft/azure-functions, but you can change it if you're deploying your own container.

Note

  • By default Azure will mount a persisted volume over /home/site/wwwroot. If your docker image contains your code, this volume will mask all the content. To stop that mounting, set an App Setting WEBSITES_ENABLE_APP_SERVICE_STORAGE = false