{"id":29325,"date":"2017-04-10T08:00:59","date_gmt":"2017-04-10T15:00:59","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/?p=29325"},"modified":"2019-02-14T15:55:38","modified_gmt":"2019-02-14T23:55:38","slug":"considerations-on-using-deployment-slots-in-your-devops-pipeline","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/considerations-on-using-deployment-slots-in-your-devops-pipeline\/","title":{"rendered":"Considerations on using Deployment Slots in your DevOps Pipeline"},"content":{"rendered":"<p>The goal of DevOps is to continuously deliver value.\u00a0 Using deployment slots can allow you to do this with zero downtime. In the Azure Portal, in the Azure App Service resource blade for your Web App, you can add a deployment slot by navigating to \u201cDeployment slots,\u201d adding a slot, and giving the slot a name. The deployment slot has its own hostname and is a live app.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/2017-04-10_8-02-58.png\"><img decoding=\"async\" width=\"218\" height=\"217\" class=\"alignnone size-full wp-image-29366\" alt=\"2017-04-10_8-02-58\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2017\/04\/2017-04-10_8-02-58.png\" \/><\/a><\/p>\n<p>Deployment slots are extremely powerful, but care must be taken when you start to integrate them into your DevOps Pipeline.\u00a0 The goal of this post is to focus on best practices and anti-patterns.<\/p>\n<p>Often when I see people using deployment slots in their pipelines, they attempt to swap across environments. This can lead to undesirable results.\u00a0 One example I witnessed had two deployment slots: Dev and QA.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/2017-04-03_9-35-36.png\"><img decoding=\"async\" width=\"278\" height=\"124\" class=\"alignnone size-full wp-image-29335\" alt=\"2017-04-03_9-35-36\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2017\/04\/2017-04-03_9-35-36.png\" \/><\/a><\/p>\n<p>The thinking was they would copy the files to Dev, then swap to QA, and finally swap into Production.\u00a0 On paper, this seems logical. However, rarely are you only dealing with the web application.\u00a0 You also must deploy the database and other dependencies. In the Dev and QA environments, you will also want to run tests such as load and performance tests.<\/p>\n<p>First, we will address testing. Each slot of the web application shares the same resources. Therefore, if you were to run load tests against the QA slot, it would impact the performance of the Production slot as well. Therefore, if you intend to run load tests you need two separate web applications with matching App Service Plans. Matching the level of the App Service Plan is important so that you will be using comparable sized resources.<\/p>\n<p>Second, I want to address restarting an environment deployment. Like many deployment products, Visual Studio Team Services allows you to restart a failed deployment. If you swap deployment slots\u00a0and deploy a database in your production environment, you may have to restart the deployment if the database fails.\u00a0 When you restart your deployment, you would swap the slots again. This would swap the desired code back out of Production when you restart the deployment.<\/p>\n<p><strong>Rolling back with slots <\/strong><\/p>\n<p>Many users of slots get excited when they realize they can swap in both directions to \u201croll back\u201d a change.\u00a0 Although this is true,\u00a0you need to consider that\u00a0rarely are you only dealing with the web application. In the cases where you also deployed a database, simply swapping the slots back might leave you in a worse place. You must remember that you are only swapping the web application and not all its dependencies.\u00a0 You must only make changes to your database that\u00a0do not break the current version of the application.\u00a0So, to be able to roll back the web application, you must engineer your database deployments to always be at least one version backwards compatible. This will allow you to swap your slots and allow your previous version to function as expected. You may also have to support multiple API versions for web services as well.<\/p>\n<p><strong>Never do anything for the first time in Production<\/strong><\/p>\n<p>When I use deployment slots, I do so in every environment. If we return to the Dev, QA, and Production example, I would create three different web applications, each with a Stage and Production slot.\u00a0 Notice in the images below that everything I intend to do in production is also done in Dev and QA.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/2017-04-07_10-20-02.png\"><img decoding=\"async\" width=\"300\" height=\"160\" class=\"alignnone size-medium wp-image-29345\" alt=\"2017-04-07_10-20-02\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2017\/04\/2017-04-07_10-20-02-300x160.png\" \/><\/a><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/2017-04-07_10-20-29.png\"><img decoding=\"async\" width=\"300\" height=\"160\" class=\"alignnone size-medium wp-image-29355\" alt=\"2017-04-07_10-20-29\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2017\/04\/2017-04-07_10-20-29-300x160.png\" \/><\/a> <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/2017-04-07_10-22-32.png\"><img decoding=\"async\" width=\"300\" height=\"160\" class=\"alignnone size-medium wp-image-29365\" alt=\"2017-04-07_10-22-32\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2017\/04\/2017-04-07_10-22-32-300x160.png\" \/><\/a><\/p>\n<p>The reason I do this is so each environment is the same. This allows me to verify all my deployment tasks in Dev and QA before I attempt to deploy to Production. If anything is going to fail, it should fail in Dev and\/or QA where I can resolve without impacting Production. If you do something for the first time in your Production deployment, the only time you will know if it will work or not is in Production.<\/p>\n<p>For more information on deployment slots see the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/app-service-web\/web-sites-staged-publishing#add-a-deployment-slot\">Azure Documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The goal of DevOps is to continuously deliver value.\u00a0 Using deployment slots can allow you to do this with zero downtime. In the Azure Portal, in the Azure App Service resource blade for your Web App, you can add a deployment slot by navigating to \u201cDeployment slots,\u201d adding a slot, and giving the slot a [&hellip;]<\/p>\n","protected":false},"author":220,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-29325","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"acf":[],"blog_post_summary":"<p>The goal of DevOps is to continuously deliver value.\u00a0 Using deployment slots can allow you to do this with zero downtime. In the Azure Portal, in the Azure App Service resource blade for your Web App, you can add a deployment slot by navigating to \u201cDeployment slots,\u201d adding a slot, and giving the slot a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/29325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/220"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=29325"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/29325\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=29325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=29325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=29325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}