This is part 28 of azure tutorial. In this video, we'll discuss how to auto
swap deployment slots in azure. If you're wondering why auto swap ? Well, auto swap
allows us to deploy our app continuously with zero downtime. When auto swap is configured,
for example from staging to production deployment slot, every time we push code into staging slot,
it is automatically swapped into the production slot without any manual intervention and that
too after it is warmed up in the source slot. This means, you're able to deploy with zero downtime.
How to configure auto swap? Well, it's straightforward. In the azure portal,
navigate to your app service. As you can see, I'm already on the app service page. Now,
let's navigate to deployment slots and we do that by clicking on this "Deployment slots"
option under "Deployment". As you can see, we have three slots here - production, testing and
staging. We're going to configure auto swap from staging to production. So, this means every time
we push code into the staging slot, it'll be automatically swapped with the production slot.
We'll see that in action in just a bit. If you're wondering, why do we need this testing slot? Well,
here's the plan, we're going to make code modifications on our local development machine.
Once we make those changes, we will push them to this testing slot, so we get the opportunity to
test our changes in azure, make sure everything is good. Once we are happy with the changes,
we'll then push a build into the staging slot which will be automatically swapped with the
production slot and we'll see that in action in just a bit. So, the first order of business
here is to configure auto swap from staging to production. So, our source slot for auto swap
is staging and the target is production. So, let's navigate to the source slot, in our case staging.
Click on "Configuration" which you can find under "Settings"
and then click on "General Settings" scroll a bit down
By default, as you can see "Auto swap" is turned off. We want to enable it, so select
this "On" radio button. Remember we want to auto swap from staging to production. So,
every time we push code into the staging slot, we want to swap it with production,
so our source slot as you can see here is our staging slot and our target is production. So,
select production from this drop down list and very important, don't forget to save changes.
That's it, we have auto swap configured.
Now, in the interest of time, here is what I have done in the background.
I have deployed the same version of the app on all the three deployment slots that is production,
testing and staging. So, if we take a look at our testing URL, notice this is our testing URL,
we can say that because in the URL we have the word testing. All the five quotes are displayed
with a red background color and the same is true even with our staging and production URLs. Notice,
here we have our staging and production URLs side by side. On the left, we have our staging URL,
again we can say that because we see the word staging in the URL and on the right we have
our production URL and these quotes again are displayed with the same red background color
for all quotes and what we want to do is, display the alternate quotes with a different color
and the change itself is pretty straightforward. It is the default page, that displays these quotes
and instead of using other danger for both the item template and alternating item template,
let's use a different color for alternating item template and for that, all we have to
do is use a different bootstrap class. Let's save our changes and push these changes to our testing
deployment slot. So, from this drop down list select the testing slot and then click publish.
There we go, on our testing URL we see alternate quotes with a different background color
as expected. So, we are happy with our changes and we want to push these changes
into our staging slot. So, let's go back to visual studio
and from this drop down list, let's select our staging slot and click publish.
There we go, deployment to the staging slot is complete and for comparison I have both the URLs
side by side, staging on the left and production on the right and we have just pushed a code change
into the staging slot and we see the alternating quotes with a different background color
as expected. Remember, we configured auto swap from staging to production. So, in a few seconds
these deployment slots should be automatically swapped, this means if we refresh these two pages,
we should see the colors swapped. Let's do one by one, first staging and then production.
There we go, these slots are swapped as expected. That's it in this video. Thank you for listening.