This post explains some of the not so well-known features and configurations settings of the Azure App Service deployment slots. These can be used to modify the swap logic as well as to improve the application availability during and after the swap. Here is what you can do with them:
Swap based on the status code
During the swap operation the site in the staging slot is warmed up by making an HTTP request to its root directory. More detailed explanation of that process is available at How to warm up Azure Web App during deployment slots swap. By default the swap will proceed as long as the site responds with any status code. However, if you prefer the swap to not proceed if the application fails to warm up then you can configure it by using these app settings:
WEBSITE_SWAP_WARMUP_PING_PATH
: The path to make the warm up request to. Set this to a URL path that begins with a slash as the value. For example, '/warmup.php'. The default value is /.WEBSITE_SWAP_WARMUP_PING_STATUSES
:Expected HTTP response codes for the warm-up operation. Set this to a comma-separated list of HTTP status codes. For example: '200,202' . If the returned status code is not in the list, the swap operation will not complete. By default, all response codes are valid.
The deployment slots feature for Azure Websites allows validating a version of your site with full content and configuration updates on the target platform before directing customer traffic to this version. The expectation is that a deployment slot would be fully configured in the desired target format before performing a swap.
You can mark those two app setting as 'Slot Settings' which would make them remain with the slot during the swap. Or you can have them as 'non-sticky' settings meaning that they would move with the site as it gets swapped between slots.
- Azure Websites Slots, four queens newest slots, casino craps table odds, casinos near sugar land texas MasonSlots Casino is again a relatively new online casino that is well put together. This online casino has chosen a nice theme that is everywhere.
- Deployment slots or Azure slots are actually instances of Azure Web Apps which are tied to that website. A deployment slot will carry the name of the Azure Web App + SlotName. For example, if my Azure Web App is called DebDemo and I create a slot called staging, then my slot will be an Azure Web App with the name DebDemo(staging) and its url.
- Simple staging slots for Azure Storage Static Websites While most of our deployments tend to use Azure App Service staging slots for easy swapping of new and old versions of code in our backend, there has been a lack of similar functionality for our static frontend hosted in Azure Storage.
Minimize random cold starts
In some cases after the swap the web app in the production slot may restart later without any action taken by the app owner. This usually happens when the underlying storage infrastructure of Azure App Service undergoes some changes. When that happens the application will restart on all VMs at the same time which may result in a cold start and a high latency of the HTTP requests. While you cannot control the underlying storage events you can minimize the effect they have on your app in the production slot. Set this app setting on every slot of the app:
WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG
: setting this to '1' will prevent web app's worker process and app domain from recycling when the App Service's storage infrastructure gets reconfigured.
The only side effect this setting has is that it may cause problems when used with some Windows Communication Foundation (WCF) application. If you app does not use WCF then there is no downside of using this setting.
Control SLOT-sticky configuration
Originally when deployment slots functionality was released it did not properly handle some of the common site configuration settings during swap. For example if you configured IP restrictions on the production slot but did not configure that on the staging slot and then performed the swap you would have had the production slot without any IP restrictions configuration, while the staging slot had the IP restrictions enabled. That did not make much sense so the product team has fixed that. Now the following settings always remain with the slot:
- IP Restrictions
- Always On
- Protocol settings (Https Only, TLS version, client certificates)
- Diagnostic Log settings
- CORS
If however for any reason you need to revert to the old behavior of swapping these settings then you can add the app setting WEBSITE_OVERRIDE_PRESERVE_DEFAULT_STICKY_SLOT_SETTINGS
to every slot of the app and set its value to '0' or 'false'.
swap Diagnostics detector
If a swap operation did not complete successfully for any reason you can use the diagnostics detector to see what has happened during the swap operation and what caused it to fail. To get to it use the 'Diagnose and solve problems' link in the portal:
Azure Microsoft.web/sites/slots
From there click on 'Check Swap Operations' which will open a page showing all the swaps performed on the webapp and their results. It will include possible root causes for the failures and recommendations on how to fix them.
Deployment slots have been an invaluable feature for Azure Web Apps for a long time. To find out how to create slots for Azure Web Apps, you can visit the official documentation [here](https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-staged-publishing' target='_blank). So what makes deployment slots so useful? I summarize some of the benefits below but this is by no means the exhaustive list:
- [Testing in Production - A/B Testing](https://cmatskas.com/azure-websites-testing-in-production/' target='_blank)
- Hot deployments that allow deployment to production with no downtime
- UAT testing targeting a near live environment
- Easy roll out and roll back
- Full or incremental swapping
- DevOps integration with slots (VSTS deployment directly to slot)
- many more
There are also some important caveats that you need to be aware of when using slots:
- Shared resources with the live deployment
- Setting persistence
- Load/Performance testing on slots can affect the live site
- Slots are only available on the Standard and Premium tier
- some more
As long as you're aware of the caveats and treat deployment slots, you can significantly improve the way you perform your testing and deployment to Azure. And now Azure Functions can benefit from this awesome feature, which is currently in Preview like [Proxies](https://azure.microsoft.com/en-gb/updates/announcing-azure-functions-proxies-in-public-preview/' target='_blank)
Enable Function Deployment Slots
As soon as you log in to your Azure subscription and navigate to your Functions blade you'll be met with a new item in the navigation pane: Places in england.
To start using slots you need to enable the feature first (one-time setting). When you press the + you'll be presented with the following message:
Click on the link to enable the feature in the app settings section:
Notice the message above the (On/Off) buttons. This is one-time opt-in on the Function app that cannot be disabled. Feel free to ignore this as slots can be safely ignored if you don't want to use them.
Creating and using slots
I'll use the portal to showcase how to create and use deployment slots.
I haven't seen any updates to the CLI and PoSH cmd-lets with regards to Azure Function slots . I'll update the blog post once I know for sure.
Let's go ahead and create our first slot. Click on the + button next to the Slots item. Enter a name for your slot (make it meaningful as the slot name will be appended to the Function URL. Press Create to go ahead an create that slot. The slot creation is instantaneous.
Azure Function Deployment Slot
With the slot in place, we can deploy our code. It's important to notice that the slot operates on the whole Function app and not individual functions. This means that if you plan on using this feature for testing, you'll need to replicate the whole 'live' Function code. For my example, I went against my own advice as I'm only showcasing the feature and I don't care about my 'live' code.
Azure App Service Slot
You'll notice that my new slots comes with it's own unique URL. This is fantastic because I can access this slot in isolation and test it independently from other slots or the code deploying in my 'Production' slot which is the default/live slot. The slot URLs have the following format:
https://yourwebsitename-.azurewebsites.net
Swapping slots
Assuming that all our tests pass and everyone has signed off the new code, we can now swap the Production and Beta slots. To do this, you need to use the Swap button which is a new addition to the UI.
This will kick off the wizard that will guide you through the swap steps
You need to choose the source and destination slots and the type of swap (simple or with preview). If you want to find the different between simple and swap with preview, check the complete documentation [here](https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-staged-publishing#swap-with-preview-multi-phase-swap' target='_blank). Howwever, if you want the gist of it, see below:
- Keeps the destination slot unchanged so existing workload on that slot (e.g. production) is not impacted.
- Applies the configuration elements of the destination slot to the source slot, including the slot-specific connection strings and app settings.
- Restarts the worker processes on the source slot using these aforementioned configuration elements.
- When you complete the swap: Moves the pre-warmed-up source slot into the destination slot. The destination slot is moved into the source slot as in a manual swap.
- When you cancel the swap: Reapplies the configuration elements of the source slot to the source slot.
Once the swap is complete, you end up with something that looks like this:
With a couple of steps we were able to deploy our code safely to production. I believe that deployment slots are a great addition to Functions and massive Kudos to the team for integrating this feature to the service.
I would urge you to give them a go and see how you can benefit your own work flow and deployment process. As always, feel free to let me know in the comments if you have any questions or issues with this feature.