Deploy a Function App Container

You can automatically deploy your functions to Azure Function App for Linux Container after every successful build.

Before you begin

If you already have an app in GitHub that you want to deploy, you can try creating a pipeline for that code.

However, if you are a new user, then you might get a better start by using our sample code. In that case, fork this repo in GitHub:

    https://github.com/azooinmyluggage/GHFunctionAppContainer

Build your app

Follow the Build, test, and push Docker container apps to set up the build pipeline. When you're done, you'll have a YAML pipeline to build, test, and push the image to container registry.

We aren't yet advising new users to use YAML pipelines to deploy from Azure DevOps Server 2019. If you're an experienced pipeline user and already have a YAML pipeline to build your .NET Core app, then you might find the examples below useful.

YAML pipelines aren't available on TFS.

Now that the build pipeline is in place, you will learn a few more common configurations to customize the deployment of the Azure Function App Container.

Azure service connection

The Azure Function App on Container Deploy task, similar to other built-in Azure tasks, requires an Azure service connection as an input. The Azure service connection stores the credentials to connect from Azure Pipelines or Azure DevOps Server to Azure.

You must supply an Azure service connection to the AzureFunctionAppContainer task. Add the following YAML snippet to your existing azure-pipelines.yaml file. Make sure you add the service connection details in the variables section as shown below.

variables: 
  ## Add this under variables section in the pipeline
  azureSubscription: <Name of the Azure subscription>
  appName: <Name of the function App>
  containerRegistry: <Name of the Azure container registry>

YAML pipelines aren't available on TFS.

Configure registry credentials in Function App

App Service needs information about your registry and image to pull the private image. In the Azure portal, go to your Function App --> Platform features --> All settings. Select Container settings from the app service and update the Image source, Registry and save.

Screenshot showing Update image source and Registry in container settings.

Deploy with Azure Function App for Container

The simplest way to deploy to an Azure Function App Container is to use the Azure Function App on Container Deploy task.

To deploy to an Azure Function App container, add the following snippet at the end of your azure-pipelines.yml file:

trigger:
- main

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: <Docker registry service connection>
  imageRepository: <Name of your image repository>
  containerRegistry: <Name of the Azure container registry>
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

- task: AzureFunctionAppContainer@1 # Add this at the end of your file
  inputs:
    azureSubscription: '<Azure service connection>'
    appName: '<Name of the function app>'
    imageName: $(containerRegistry)/$(imageRepository):$(tag)

The snippet assumes that the build steps in your YAML file build and push the docker image to your Azure container registry. The Azure Function App on Container Deploy task will pull the appropriate docker image corresponding to the BuildId from the repository specified, and then deploys the image to the Azure Function App Container.

YAML pipelines aren't available on TFS.

Deploy to a slot

You can configure the Azure Function App container to have multiple slots. Slots allow you to safely deploy your app and test it before making it available to your customers.

The following YAML snippet shows how to deploy to a staging slot, and then swap to a production slot:

- task: AzureFunctionAppContainer@1
  inputs:
    azureSubscription: <Azure service connection>
    appName: <Name of the function app>
    imageName: $(containerRegistry)/$(imageRepository):$(tag)
    deployToSlotOrASE: true
    resourceGroupName: <Name of the resource group>
    slotName: staging

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: <Azure service connection>
    WebAppName: <name of the function app>
    ResourceGroupName: <name of resource group>
    SourceSlot: staging
    SwapWithProduction: true

YAML pipelines aren't available on TFS.