Canary deployment with Microsoft Azure Web Apps

Javier Hertfelder
Crowdbotics
Published in
2 min readMay 6, 2020
Photo by Andreas P. on Unsplash

Blue-green deployment allows services to be swapped with zero downtime but what about the possible errors in the new deployments. Microsoft Azure allows to traffic-route your audience from production to staging, making sure that you don’t have an important bug in the new deployment.

In this article I will show how to achieve a canary deployment with a simple script that can be integrated within your favorite devops tool. For the record, a very good article was written by Scott Hanselman but he used PowerShell.

With az webapp traffic-routing command I have created a small script that given:

  • web app name
  • resource group
  • minutes that last the canary deployment
  • percentage change step

it allows you to route the traffic in a controlled manner.

Here is the code:

https://gist.github.com/javitoHertfy/a277092b33aff18195bd083f4b7faf96

Finally all you have to do is to integrate this script in your favorite devops pipeline. Since we use Azure DevOps I will show how our release pipeline is configured.

We have 3 steps:

  • PRO step, deploys the app in the staging slot, warms up the application and run some integration and load tests.
  • Traffic-routing step, only contains the code I shared above but removing the last line that makes the swap.
  • Finally, the Swap task only swaps the two slots.
Steps in the build

This is how the traffic-routing step looks like.

Traffic-routing Azure CLI step

Troubleshooting

  • Since is a bash script better if you run it over a Linux Agent Job.
  • I found some weird issues with the File Format of the bash script, using vscode and windows just change End Of Line sequence from CRLF to LF and saving the file should do the trick.
Changing from CRLF to LF

Hope you found it useful!

--

--