Exercise 7: Mastering Deployment Slots
In this exercise, you will look at the advanced features of Azure App Service by creating and managing deployment slots:
- From the Azure portal, open the Configuration blade within your App Service and notice CURRENT_SLOT has been configured to be a slot setting.
This means that regardless of any deployment slot swapping that might occur, this setting will not follow the apps. Whatever app is in the production slot will get this production value. ORIGINAL_SLOT, however, isn’t a slot setting so will follow the app through a swap. You’ll see this momentarily.
- Go to the Deployment slots blade and click Add Slot. Enter
staging
for the name of the deployment slot and choose to clone the settings from the default/production slot (indicated by having just the App Service name), which will copy all of the application settings to the staging slot.You could have also used the following CLI command:
az webapp deployment slot create -g "<resource group>" -n "<app-service>" -s "staging" --configuration-source "<app-service>"
Alternatively, you could have used the following PowerShell command:
New-AzWebAppSlot -ResourceGroupName "<resource group>" -Name "<app-service>" -Slot "staging"
- Select the staging deployment slot and, from within the Configuration blade, change the value of both CURRENT_SLOT and ORIGINAL_SLOT to
Staging
rather thanProduction
. Save and continue.Conceptually, there are some different configurations between the staging and production slots, which you could have also replicated with different code.
- From within VS Code, on the assumption that the
out
folder still remains from the previous exercise when you deployed the code to App Service, open the command palette either by going to View and then Command Palette or using the relevant shortcuts. In Windows, this is Ctrl + Shift + P by default. - Start typing and then select Azure App Service: Deploy to Slot….
- When prompted, select your App Service resource, the new staging slot, browse to and select the
out
folder previously created, and confirm the deployment when the pop-up window appears requesting confirmation. - Once the deployment completes, browse to the production slot URL for App Service (that is,
https: //<app-service>.azurewebsites. net
) and confirm that the production text is there. Now, do the same with the staging URL (that is,https: //<app-service>-staging.azurewebsites. net
) and confirm that the staging text is there. Once confirmed, navigate back to the main/production URL so that you’re ready for the next step.This shows how you could test changes in the staging slot/app before pushing it to production via the staging URL. The documentation also explains how you can use a query string in a link to App Service, which users could use to opt into the staging/beta/preview app experience. Check out the Further Reading section of this chapter for the relevant link.
- From the main App Service (not the staging app) within the Azure portal, open the Deployment slots blade and notice that you can change the percentage of traffic that flows to each slot.
This allows you to control the exposure of the staging slot before making the switch. Rather than using that right now, just click on Swap. Note that you can preview the changes that will be made, which will be the text changing for the ORIGINAL_SLOT application setting. Confirm this by clicking on Swap.
- Go back to the tab/window with the production site showing and periodically refresh the page. There should be no downtime. At some point, the Original slot text will change from
Production
toStaging
, showing that the app that was originally in the staging slot was swapped with production and your changes are now live in the production app:
Figure 2.23: Text showing that the previous staging app is now the production app
- When you’re done with this exercise, feel free to clean up your resources by deleting the resource group containing all the resources created in this chapter.
If you wanted to, you could revert the changes by swapping the slots again.
One final point to note is that although the default behavior is for all the slots of App Service to share the same App Service plan, this can be changed by changing the App Service plan in each slot individually.
With that final point, you have come to the end of our exploration of App Service. A lot of the concepts we’ve discovered here will help with the topics that will be covered throughout this book, as a lot of them will dive deeper or reference concepts we’ve already covered in some detail. If you can understand the concepts discussed in this chapter, you’ll already be ahead of the majority of people who pass the exam.