I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.
In this series, I will cover as below:
- Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
- Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
- Remote debugging App Service using visual Studio, monitoring and configuring alerts
- Diagnostic logs, live stream, process explorer and KUDU
- How to use Azure SQL Database in Dot.net Applications
- How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
- How to use Visual Studio Team Service to do continuous Integration and continuous delivery
- Azure storage data services types and how to store files in azure storage account 1/2
- Azure storage data services types and how to store files in azure storage account 2/2
- How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
- How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2
If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.
2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
At this point, you have successfully created the App Service Plan, App service and published the changes to the Azure using Visual Studio and Azure SDK. Let us move to exciting part of remote debugging and monitoring, fire up your visual studio if you have not opened it before and open the project we created in recently.
Figure 1 App Service Deployment Slot
Let us talk about Deployment Slot, this is feature provided by App service, this basically enable you to deploy your code to different containers i.e. QA, Staging or Production, in this way you will make sure that your code is fully tested and ready to move to production. This approach support setting up different App Settings and connection strings for the Databases for each slot, which will enable us to test and deploy our changing with ease.
I know you are excited about this feature lets, let us open web.config and add a new App Setting
value=“Welcome to Azure Development!“/>
Figure 2 Add new App settings in web.config
Now show this setting in our index page, Views | Home | Index.cshtml and edit it as shown below:
ViewBag.Title = “Home Page”;
class=”btn btn-primary btn-lg”>Learn more »</a></p>
Figure 3 Edit Index file
Now after this change just press F5 to lunch and see the change.
Figure 4 App setting message is showing
Now publish your solution to the Azure App service as we did in our previous post. You can see that new changes publish.
Figure 5 Publishing Changes to Azure App Service
We will override the changes in our App Service Settings; go to Azure Portal and then App Service | Settings | Application Settings, here we will add the key and value to override the default one, please note that we can also use this interface to add new keys as well, this interface is not limited to just overriding key values.
Figure 6 Override Application Settings in Azure Portal
Now refresh to see that message is changed as expected.
Figure 7 Override setting display
Now let us create slots for staging slot. Go to Azure Portal and then App Service, Deployment | Deployment Slots | Click Add Slot and name it as staging, in configuration Source choose the main app and click ok. It could take few minutes depending upon application size.
Figure 8 Add new Staging Deployment Slot
Once deployment slot is added successfully, click on it to see the settings.
Figure 9 Deployment Slot is added successfully.
Change the “WelcomeMsg” to “Welcome message from staging” and tick “slot setting” check box, as when we swap this deployment slot with production this setting will not move and will stay with this slot. This way we will be able to retain the settings that are slot specific.
Figure 10 Change App settings on Staging Deployment Slot
Now question arise how we are going to deploy our source code to staging slot, the answer is very simple Publish Profile, click on Over view and then click on Get Publish Profile and save it to local system.
Figure 11 Get Publish Profile Setting
Go back to visual studio | Publish and click on Create new profile, select Existing check box, click on import profile, click ok, select the staging profile that we got in previous step and click ok.
Figure 12 Import Profile
Figure 13 Import profile and publish
For testing purposes open Index.cshtml file and update it as below
class=”lead”>We have update the project</p>
Figure 14 Update for staging
Publish the changes to staging slot by just clicking on publish; we can see that our recent changes have been published successfully.
Figure 15 Publish changes to staging slot
All these steps lead us to the exciting part of Deployment Slot Swap, Go to Azure Portal and then App Service, click on swap and click ok.
Figure 16 Slot Swap
Figure 17 Choose Swap Slot
Swapping operation will take some time to complete, in side-by-side comparison you can see that staging code is swapped to production and production code is swapped to staging. Remember that user will be experience any downtime in this operation will continue to use the application as they were before swap.
Figure 18 Production and Staging slot swapping
With this congratulation, you have successfully created new staging slot, deployed your code to staging slot, used sticky slot settings, and swapped production with staging.