Continuous Deployment on Azure App Services - The Intro

Post Tags: azure, azure app services, continuous deployment

Today I want to talk about one of my favorites topics in Software Development: Continuous Deployment. And since talking only about one topic would be pretty boring I want to mix it with another topic I like pretty much: Microsoft Azure. Azure Websites or Azure App Services as they are called nowdays to be more precise.

In this post I want to make sure the terminology is clear and I will talk about how to setup continous deployment for a basic ASP.NET web site. In the following blog posts I want then proceed to more advanced topics when it comes to continuous deployment on Azure App Services. So let's start with some terms.

What is Continous Deployment about?

Well the base idea is to deploy every change as fast as possible to production. The idea behind this concept is that small change = low risk to break anything. When you deploy lot of features at the same time, the risk to break anything is just bigger than when deploying only a small portion at a time. And well if something breaks it's clear which feature introduced it and it's also fairly easy to rollback to a previous version. However continuous deployment doesn't come for free. There are some requirements your code must have before you can start with continuous deployment:

  • Build, installation and deployment including changes to the database must be fully automated. And this is valid for every step of the installation of the web site, even if it only would take 10 seconds to do manualy. Just automate everyting!
  • Automated tests are not voluntary. Idealy there are Unit Tests for logic and Integration Tests for functionality. The minimum is that there is some sort of tests.
  • There must be simple way to rollback the deployed code. The challenge here is to have the database in sync with code. The best way is to never introduce breaking changes on database level. Never delete a column or table, never rename a column or table, never change the type of column. Create a new one and copy the data is often the better solution when working in a continuous deployment environment. The other possibility is to have database migrations which when applied doesn't care if the database is behind or in front of the current code.
  • You need to have your source code cleanly versioned in a VCS. Git is highly recommended here.

And what are Azure App Services?

Azure App Services which were called Azure Websites previously are the PaaS from Microsoft. They provide an super easy way to host ASP.NET, Node.JS, PHP, etc... web applications. In addition of hosting applications, Azure App Services provides a lot more features needed when operating a web application: Monitoring, Performance Analysis, Analytics, automated deployment, everything can be done directly from the Azure Portal. And the coolest thing is that you can have 10 Azure App Services running for free. So if if you haven't an Azure account yet, you should start directly by creating a new one at https://tryappservice.azure.com/

Enough terminology, I want to have my code deployed!

Ok, so for this demo I will use the new Azure Portal located at http://portal.azure.com/. You can create an new website with New => Web + Mobile => Web App
New Web App Enter the details here. You can select a free website here:
New Web App Details

And now the fun begins. Open you fresh website in the portal and select "Setup Continuous Deployment"
Setup CD

Choose your Git or Mercurial repository here, depending on where it is hosted. You can fork my demo ASP.NET website from Github if you need one to test. Now Azure will automatically build and deploy the website. Of course a NuGet restore will be done before the build is started.
And the collest thing of this whole stuff: anytime you commit something to master it will automatically deployed to your website!

Conclusion and Future

So now with only a few clicks we have a working continuous deployment environemnt on Azure! Of course this example was very basic and for real world projects some customization can be needed. So more posts about Continuous Deployment and Azure App Services. The next topics will be:

  • Customize the deployment process
  • Rollback a deployment
  • Add a staging environment
  • Automate the setup
  • Add test environments for different branches

Follow me on Twitter to stay updated when a new post is out!

comments powered by Disqus