CI with Azure Web Apps for Linux, GitHub, DockerHub and Azure Functions

I am currently working on a project built with Node & Typescript and decided I would use Azure Web Apps for Linux as my hosting platform. I choose Azure Web Apps for Linux mainly because it has built in Docker Container configuration which meant that I could build my solution inside a Docker container and deploy it by pushing the Docker build to Docker hub.

Azure Web Apps for Linux allows you to configure a Docker repository right inside the web app settings and Azure automatically goes off and pulls your Docker build from your repository and runs the container.  You can configure it as shown below to pull from a DockerHub repository.


Continuous Integration


Unfortunately there doesn’t seem to be any way to integrate this with a CI build of your code. Azure only seems to pull a latest build from DockerHub when any of the above configurations are changed. I believe the Azure team have stated that some form of CI would be coming with support for Docker Containers in the future but no real idea on when.

On top of this the documentation says that a pull from DockerHub should be kicked off if the Web App is stopped and started again but I couldn’t get this to work at all.  The only way I could get Azure to pull a new build from DockerHub is to change one of the configuration settings above. This got me thinking of a way to integrate a CI build with GitHub, DockerHub and Azure.


Tagging your Docker Build


If you do a manual push to DockerHub after building from your Docker file you can also tag the build with a version number.  Like so:

docker build -t leedale/dronefly .

docker tag leedale/dronefly leedale/dronefly:0.7.3

docker login -u leedale

docker push leedale/dronefly:0.7.3

You can then go into the Azure Docker Container settings and modify the version number assigned to the repository name and this is enough to force Azure to go off to DockerHub and pull that version of the build.

This got me so far but I wanted to go further and have the build automatically updated when I committed my code to a GitHub repository.


GitHub and DockerHub Integration.


There is a feature on DockerHub that allows you to link your GitHub account and have automated builds be triggered when code is commitred to your GitHub repository.

What I wanted is for a specific tag to be assigned to a commit and for that tag also be assigned to the Docker repository when the automated build is kicked off.

First I went to DockerHub and created an automated build:


I choose GitHub and then selected the repository I wanted to configure for an automated build. As long as you have a Dockerfile in the repository the automated builds will work.

You then need to configure the build settings for the automated build. This is the crucial part, you need to create a build from a tag and have the tag be assigned to the Docker build. My I configured my setting as shown below:


You can use the {sourceref} token to make the Docker Tag name the same as the GitHub tag.

Now I am at the point where I can use the commands below to push a tagged commit to my GitHub repo and have DockerHub automatically build my docker image and assign the GitHub tag to the repository name.

git add .

git commit -m"My Commit"

git tag 0.7.3

git push --set-upstream origin 0.7.3

Updating Azure Docker Settings automatically


What I need to do now is somehow have my Azure Docker Containers settings updated with the latest build number assigned to the repository name. This will force Azure to pull the latest tagged docker build from Docker hub and run the latest code.

I choose to use a Azure Function for this task and the idea is to use the Management Libraries within my Azure Function to automatically update the app settings of my Azure Web App to the latest build number.

The final CI build flow looks like the diagram below:


The Azure Function code is hosted up on GitHub for anyone to reuse, go check it out. You just need to deploy this to your Azure subscription and modify the App Settings to point to the web app you want to update.

You will need to configure a Azure AD app with the sufficient permissions to allow your Azure Function to update the target web app settings from the Azure Management Libraries.

DockerHub WebHooks


The final part of the puzzle is to configure a WebHook within DockerHub to call your Azure Function when a build has been successful.

Go to your automated build on DockerHub and click on the WebHook settings and configure your WebHook to point to your Azure Function HTTP endpoint as shown below:


As you can see I am appending the Resource Group and App Service name to the Azure Function call so that it can identify which web app to update.

Once a successful build has been pushed to the DockerHub repo the WebHook will call this Azure Function which will in turn update the Docker Container repository settings with the new tag name and this will force Azure to in turn pull the latest build from DockerHub resulting in the new build running in the Azure Web Apps for Linux instance.


And that it!

Microservices architecture


I see this CI flow being useful in the ever popular microservice architecture world where a service could be stood up using Docker Containers and your CI approach could be truly modular in its build process. Each service having it own GitHub repo and DockerHub repo then individually being built and deployed using Docker Containers to isolate each one into it own version and app service on Azure.

One thought on “CI with Azure Web Apps for Linux, GitHub, DockerHub and Azure Functions

  1. Pingback: My first Alexa Skill with Node & Typescript. | Lee Dale

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s