{"id":25255,"date":"2018-06-08T17:33:00","date_gmt":"2018-06-08T17:33:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/?p=25255"},"modified":"2019-04-11T05:31:22","modified_gmt":"2019-04-11T12:31:22","slug":"devops-for-vms-with-vsts-and-octopus-deploy","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/devops-for-vms-with-vsts-and-octopus-deploy\/","title":{"rendered":"DevOps for VMs with VSTS and Octopus Deploy"},"content":{"rendered":"<p>In this post, Premier Developer Consultant\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/jafar-jaffery-5664883\/\">Jafar Jaffery<\/a> shares insight into how to deploy web applications to virtual machines using Visual Studio Team Services and Octopus Deploy. You can use Octopus Deploy in conjunction with VSTS to deploy both on-premises or in the cloud in a repeatable and reliable way.<\/p>\n<hr \/>\n<h3><a>Problem Statement<\/a><\/h3>\n<p>The Development team just finished work on its new feature and now needs that feature deployed to the Testing environment so that the Product team can validate the changes. Enter the Operations team. They are going to remote into the individual web servers and download the package with the changes, extract it and copy it to the target folder. After that, they\u2019ll make all of the IIS configuration changes on each individual box. But this raises a few concerns \u2013 how do other team members perform this deployment in a repeatable manner? And how can we make this manual and boring process less error-prone so that we don\u2019t have to troubleshoot simple deployment mistakes? Additionally, do the developers have to wait for the Operations team to handle their deployments every time they have a change, or is there a fire and forget solution they can use to do this automatically whenever they are ready to push their changes? DevOps solves these problems for us by having teams work closer together and introducing these \u201cauto-magic\u201d mechanisms, which is what I\u2019ll be covering that in this post.<\/p>\n<h3><a>Overview<\/a><\/h3>\n<p>In the world of DevOps, <a href=\"https:\/\/www.visualstudio.com\/team-services\/\">Visual Studio Team Services (VSTS)<\/a> offers a very robust and versatile platform that will serve as a foundation for your application deployment and automation needs. It has the capability to do end-to-end pipeline deployments for both on-premises and Azure IaaS Cloud infrastructure. VSTS also has an extensive marketplace of 3<sup>rd<\/sup> party offerings to augment its capabilities.<\/p>\n<p>In this post, I will walk you through an overview of how VSTS is used alongside <a href=\"https:\/\/octopus.com\/\">Octopus Deploy<\/a> to deploy .NET applications to a traditional VM server infrastructure, be it on-premises or in the cloud. This will give you repeatable and reliable deployments of your application every time, to every environment. As a note, this will be a basic setup consisting of a build (MVC web application), unit tests, automated deployment of code to a lower environment (\u201cTesting\u201d in our example), and promotion of that code to an upper environment (\u201cProduction\u201d in our example). Database deployments will be covered in a subsequent post.<\/p>\n<p>VSTS will be handling the build\/CI automation part of the process and will work with Octopus Deploy to handle deployment orchestration. The Octopus ecosystem is comprised of a central deployment server, along with \u201cTentacle\u201d agents that run on any target VMs where deployment will take place. The diagram below illustrates this flow:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image320.png\"><img decoding=\"async\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image_thumb248.png\" alt=\"image\" width=\"745\" height=\"251\" border=\"0\" \/><\/a><\/p>\n<h3><a>VSTS<\/a><\/h3>\n<h4><a>Setting up the VSTS\/Octopus Connection<\/a><\/h4>\n<p>Inside VSTS, install the Octopus extension from the marketplace, and then add a new Service Endpoint for Octopus Deploy. You will need an Octopus API key for the endpoint, which can be generated from the Octopus Deploy web portal. Detailed instructions for these steps can be found <a href=\"https:\/\/octopus.com\/docs\/api-and-integration\/tfs-vsts\/using-octopus-extension#installing-the-extension\">here<\/a>.<\/p>\n<h4><a>Setting up the Build<\/a><\/h4>\n<p>The VSTS build will consist of the following tasks:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image322.png\"><img decoding=\"async\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image_thumb249.png\" alt=\"image\" width=\"289\" height=\"316\" border=\"0\" \/><\/a><\/p>\n<ol>\n<li>Restore NuGet Packages<\/li>\n<li>Build the solution<\/li>\n<li>Run Unit Test<\/li>\n<li>Package the solution into a NuGet package<\/li>\n<li>Upload the package to the Octopus Deploy server. Note that you can alternatively upload to a NuGet repository.<\/li>\n<li>Create the release number string for the Octopus release. We\u2019ll go with a combination of a date\/time stamp and build ID \u2013 [yyyyMMdd].[BuildId]<\/li>\n<li>Create the Octopus release and deploy to the lower environment (\u201cTesting\u201d in this example).<\/li>\n<\/ol>\n<p>For Octopus specific steps, detailed instructions can be found <a href=\"https:\/\/octopus.com\/docs\/api-and-integration\/tfs-vsts\/using-octopus-extension\">here<\/a>.<\/p>\n<p>The build will be triggered using Continuous Integration within VSTS whenever any code changes are committed to the repository. This is significant as this will automatically do the deployment to the lower environment whenever any code is changed and checked in.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image323.png\"><img decoding=\"async\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image_thumb250.png\" alt=\"image\" width=\"459\" height=\"235\" border=\"0\" \/><\/a><\/p>\n<h3><a>Octopus Deploy<\/a><\/h3>\n<h4><a>Key Concepts<\/a><\/h4>\n<p>Before we setup the project that will deploy our application, let\u2019s explore some of the key concepts within Octopus:<\/p>\n<ul>\n<li>Project-specific\n<ul>\n<li>Project \u2013 The set of steps that define how the application is to be deployed. E.g., Deploy Package -&gt; Run Smoke Test -&gt; Notify Users<\/li>\n<li>Release \u2013 This ties a project to a package in order for it to be deployed.<\/li>\n<li>Deployment \u2013 The actual deployment of a created release.<\/li>\n<\/ul>\n<\/li>\n<li>Global\n<ul>\n<li>Environment \u2013 Where you deploy.\u00a0 E.g., Testing \/ Acceptance \/ Production.<\/li>\n<li>Role \u2013 The types of targets you deploy to, such as Web \/ DB \/ etc.<\/li>\n<li>Tenant \u2013 A segment within your environment that can be used for logically sub-dividing your environments into swim lanes. E.g., you might have tenants for different feature releases (parallel development channels), or tenants for different customers.<\/li>\n<li>Lifecycle \u2013 the deployment path through the environments.<\/li>\n<li>Package \u2013 This is the artifacts (collection of DLL&#8217;s, assets, scripts, etc) that will be deployed &amp; promoted through the environments. In this post, we\u2019ll host these on the Octopus Deploy server, but these can be kept on an external repository as well.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Scoping to Environment\/Role\/Tenant, a simple infrastructure might be configured as shown in the diagram below. Note that for our scenario we\u2019ll be deploying to just the Web role, but it\u2019s worth noting that this solution scales well as we add more VMs to our infrastructure.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image324.png\"><img decoding=\"async\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/image_thumb251.png\" alt=\"image\" width=\"744\" height=\"383\" border=\"0\" \/><\/a><\/p>\n<h4><a>Setting up the Octopus Project<\/a><\/h4>\n<ol>\n<li>Create a new Octopus project. More detailed information on Projects can be found <a href=\"https:\/\/octopus.com\/docs\/deployment-process\/projects\">here<\/a>.<\/li>\n<li>Within the Process section, add a new step using the \u201cDeploy to IIS\u201d step template. For this step, configure things like:\n<ol>\n<li>The role (\u201cWeb\u201d) and tenant (\u201cFeature 1\u201d) that this step applies to.<\/li>\n<li>The package name from where the content will be deployed.<\/li>\n<li>IIS specific settings (website\/virtual directory, App Pool, bindings, authentication, etc.)<\/li>\n<li>Config transformation steps to be taken, be it variable substitution or traditional XML transformations.<\/li>\n<li>More detailed information on Steps can be found <a href=\"https:\/\/octopus.com\/docs\/deployment-process\/steps\">here<\/a>.<\/li>\n<\/ol>\n<\/li>\n<li>Within the Channels section, create a new channel for each parallel feature being worked on (Feature 1 &amp; Feature 2 in our scenario). The Channel is the project\u2019s association to the global lifecycles. More detailed information on Channels can be found <a href=\"https:\/\/octopus.com\/docs\/deployment-process\/channels\">here<\/a>.<\/li>\n<\/ol>\n<p><a>Once this is all in place, the VSTS build mentioned <\/a>above will automatically deploy code changes to the Testing environment by first creating the Release for the given Project \/ Environment \/ Tenant \/ Package Version, and in turn deploying that Release. After the release is successfully deployed to the Testing environment, it can then be promoted (i.e., same package version) to the next environment, which in our scenario is Production. Because every environment is deployed to in the same manner, this solution scales well across all environment and to all underlying VMs, regardless of how many as long as they are tagged appropriately with Environment \/ Role \/ Tenant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, Premier Developer Consultant\u00a0Jafar Jaffery shares insight into how to deploy web applications to virtual machines using Visual Studio Team Services and Octopus Deploy. You can use Octopus Deploy in conjunction with VSTS to deploy both on-premises or in the cloud in a repeatable and reliable way. Problem Statement The Development team just [&hellip;]<\/p>\n","protected":false},"author":582,"featured_media":37840,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[22],"tags":[21,250,291,375,50,38],"class_list":["post-25255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","tag-devops","tag-jafar-jaffery","tag-octopus-deploy","tag-virtual-machine","tag-visual-studio-team-services","tag-vsts"],"acf":[],"blog_post_summary":"<p>In this post, Premier Developer Consultant\u00a0Jafar Jaffery shares insight into how to deploy web applications to virtual machines using Visual Studio Team Services and Octopus Deploy. You can use Octopus Deploy in conjunction with VSTS to deploy both on-premises or in the cloud in a repeatable and reliable way. Problem Statement The Development team just [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/25255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=25255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/25255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/37840"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=25255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=25255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=25255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}