March 6, 2017

Serverless Computing with Azure Functions Part-2 – Continuous Integration

If you are looking for an introduction to Serverless Computing with Azure Functions, I suggest that you read my introductory blog post to Serverless Computing in this series to get you started.

Setting Up Continuous Integration

In this article let’s look at how to configure continuous integration for your Azure functions. Before you begin this tutorial you need an Azure account and a GitHub account to host your code, you can use your favorite version control system but this tutorial will be based on GitHub.

As of writing this article, Azure Functions supports the following repository types to host your code.

  • Visual Studio Team Services
  • OneDrive
  • Local Git Repository
  • GitHub
  • Bitbucket
  • Dropbox
  • External Repository (Git/Mercurial hosted on your servers)

In addition to the Azure, GitHub accounts you need to have Visual Studio Code IDE, and GIT installed locally. Download and install them before continuing.

Building on top of what I have covered from my previous post. Let’s look at connecting the Celsius to Fahrenheit conversion function that we wrote to a GitHub repository so that we can easily manage versioning and deployment.

Setting Up the Connection to GitHub

The first step in setting up Continuous Integration is to set up the connection to your code repository, To do this go to the Function app settings on your Azure Function app and click on configure continuous integration. (See screenshot below)

Function App Settings
Function App Settings

Once you are in the configuration section for CI you would see the deployments window on your right, hit setup from the top menu options. (See screenshot below)

Function App Deployments
Function App Deployments

Now from the list of available repository types, select GitHub.

Function App Deployment Source
Function App Deployment Source

Now click authorize.

Deployment Source Authorization
Deployment Source Authorization

You will be taken to GitHub to provide authorization to Azure to pull repositories from your GitHub account, hit Authorize Application to continue.

GitHub Authorization
GitHub Authorization

You would see the following message once successfully authorized.

Connected to GitHub Successfully
Connected to GitHub Successfully

Next step is to select your repository and the branch from the available options.

Repository Branch Selection
Repository Branch Selection

Once completed you can start pushing code to GitHub for Function Apps to start auto deploying your code.

Folder structure for your function app and functions.

Note that your repository must be structured properly for things to work, the root of the branch you selected during the connection configuration serves as the root for your Function App whereas a sub-folder within this named with the exact same name as the Function (in this example HttpTriggerCSharp1) will serve as the root folder where the files would reside for that particular function. See example below.

Repository Root (Function App)
│ 
├───HttpTriggerCSharp1 (Function - 1)
│        function.json
│        run.csx
│ 
└───HttpTriggerMyOtherFunction (Function - 2)
         function.json
         run.csx

Copy the code from run.csx, function.json and create the files in a folder named HttpTriggerCsharp1 in your repository.

Notice that you once you configure continuous integration the web interface warns you that run.csx is now read-only.

Code is Read-Only
Code is Read-Only

For ease of development, I have configured Visual Studio Code with the GitHub repository so that I can make changes and push to GitHub with a few clicks.

Deploying Changes Directly From Visual Studio Code
Deploying Changes Directly From Visual Studio Code

Once you commit your changes and push your code to GitHub observe how Azure function’s auto deploys your code.

Deployment Logs on Azure
Deployment Logs on Azure

So there you have it, now you have configured continuous integration for your Azure Function App.

 

Related posts: