Azure Deployment Slot Database
- Azure Deployment Slots Database
- Azure Deployment Slot Database Example
- Azure Deployment Slot Database Definition
After the slot is created, if you click on the slot, you will be taken to another Web App. So what happens behind the scenes is Azure does create another Web App with some more sugar on top of it so that it can be classified as a deployment slot. You can use this slot to push code to this the same way you have pushed to the original Web App. Create Deployment Slot. To begin, we’ll assume you already have a Web App running on Azure. If not, you might need to start with this article on creating a web app on Azure (.NET, Node.js, PHP, Java, or Python). With your Azure Web App loaded in the Azure Portal, click the option for Deployment Slots and click the Add New button. Select the app URL on the slot's resource page. The deployment slot has its own host name and is also a live app. To limit public access to the deployment slot, see Azure App Service IP restrictions. The new deployment slot has no content, even if you clone the settings from a different slot. I am using github actions for CD of my.net app. My production environments uses deployment slots and I'd like to deploy to the staging slot and the swap after a health check.
When you make use of Azure App Services you can deploy to different deployment slots. You can choose to work with three deployment slots (dev, tst, acc) and use the default one as production, but what can you do best regarding this functionality.
Deployment slots
Deployment slots are live web apps with their own hostnames. Web app content and configurations elements can be swapped between two deployment slots, including the production slot. Deploying your application to a deployment slot has the following benefits:
- You can validate web app changes in a deployment slot before swapping it with the another slot.
- Eliminate downtime on deployment, and automate the swapping.
- Easy to swap a bad deployment back.
Note:”The app (App Service Plan) must be running in the Standard or Premium mode in order for you to enable multiple deployment slots. Everything described in this article is for Azure App Services and then specific Azure Web Apps, Azure API Apps and Azure Mobile Apps.”
Practice
Deployment slots can be deployed/ created easy by making use of the Azure Portal or Azure Resource Templates. Information on deploying Azure Deployment Slots via Azure Resource Templates can be found on a blog post I wrote a few weeks ago:
- Azure Resource Templates and Deployment Slots
Within the Azure Portal (https://portal.azure.com) you need to take the following steps:
- In the Azure Portal, open the blade of your Azure App Service.
- Click Settings, and then click Deployment slots.
- In the “deployment slots” blade click on Add Slot.
- In the “Add a slot” blade, give the slot a name, and select whether to clone web app configuration from another existing deployment slot.
Before creating deployment slots you need to have a useful pattern. In my opinion it is best to use a deployment slot as a pre production environment. This will lead to the following solution architecture.
This solution architecture makes sure that the development/ test / acceptation environment is completely separated from production. Via the pre production deployment slot you are able to test your application against the production SQL database. With this setup you can’t alter any data in pre-production this is why there is a dotted line between the pre production web app and the test / acceptation database. That you could use to test all your CRUD operations. Besides this is also makes sure that the pre production is as close to production as needed for a clear test results.
Considerations
When making use of deployment slots there are a considerations and disadvantages to be aware of:
- The web application and deployment slots are created within the same environment (This is also the case when you create a Azure Web App within the same App Service Plan). This means resources between the two instances are shared, So if you want to do a stress test on pre-production you are certain that it will effect the performance of the production instance.
Besides the above disadvantage also consider the settings that can and can’t be swapped:
Swapped:
- General settings – such as framework version, 32/64-bit, Web sockets.
- App settings (you can configure it to stick to a slot).
- Connection strings (you can configure it to stick to a slot).
- Handler mappings.
- Monitoring and diagnostic settings.
- WebJobs content.
Not swapped:
- Publishing endpoints.
- Custom Domain Names.
- SSL certificates and bindings.
- Scale settings.
- WebJobs schedulers.
I have a handful of web projects that I maintain. Some of these are sites like the one for my films (Hello World Film and Don't Worry, I'm Fine) but some others are community projects like Atlanta Code Camp. I've battled with the best way to develop and deploy these projects for quite a while.
The problem has been that for a long time I've just been checking into a main branch in Git and publishing that on every check-in. That's caused me some down time over the years. Maybe with these small projects it doesn't matter, but I like to keep these up (especially this blog) so I wanted to make a change that would address it.
First thing I did was create a branch in Git for working on the project. I thought about doing Pull Requests but since I'm the only dev on most of these, it felt a little to over-complicated. So instead I have a branch I call 'next' that I do active development into:
I've set up an Action to automatically build and deploy the project on every build. If you're curious how to do this in GitHub Actions, see my blog post about it.
The difference here is that on every 'Next' deployment I'm building a 'next' container. If we look in Azure container registry, we can see that there are tags for latest (my released version) and next (my test version):
With that in place, let's look at slots. Azure slots are a way to have multiple versions of your site running at once. One reason for this is what we're using it for. You can have a separate versions for testing, development, etc. Another common reason is to support A/B testing. It allows you to swap slots instantly (to prevent downtime) for those different scenarios. Let's see what it looks like.
In the App Service for this blog, there is an item for 'Deployment Slots':
Opening this you may get the dreaded 'You're not paying enough for this project' notification:
But if you're on a Standard (or better), you'll be greeted by this page:
Note that your main site is already running as the first 'slot'. It's your 'production' slot and 100% of the traffic is going to it. You can add a new slot and this will make a copy of your project, but it's a completely separate (but related) App Service.
Note: you can use this whether you're using containers or not. Just in this example I'm using container deployment
Let's create a new slot. Click on the 'Add Slot' button:
Enter a name for the slot and Click Add (you can clone the settings from the original site if you are using settings). Each slot gets it's own App Service so separate settings and configuration.
The name of the slot becomes a new AzureWebSites.net address so you can view it directly using that domain. For my use, I use the 'sitename.azurewebsites.net' address as my testing address.
Azure Deployment Slots Database
Once you have a slot configured, it'll look like this:
While, in my case, I'm always leaving the traffic to the main site at 100%, you could also use it to do A/B testing by having two versions of the site running and sharing the traffic to test how well the sites compare.
Now that I have the slot, I just configure it to use my testing (or next) container:
Azure Deployment Slot Database Example
This image is doing a lot of heavy lifting. Note on the top-right that this is showing that it is an App Service Slot. So while it is an App Service it it's own right, it's related to the main App Service.
By looking at the container settings, I'm setting the container to use a 'next' tag so that this is the test version of this blog. I can view it and be sure that I didn't break anything. Now I'm ready to push this to the live version.
To do this, I go back into GitHub and create a Pull Request:
Once I merge the changes from my 'next' branch to 'main', the GitHub actions take over and create a new 'latest' version of my container.
You can see my actions and source code for this blog if you're curious how it works:
Azure Deployment Slot Database Definition
Is this something like what you're already doing in real production environments?