Slot Swap with Preview enables us to run production specific app setting and database connection string in a slot website. This allows us to completely test the new deployment with actual production setting. Slot Swap with Preview also allows us to execute warm-up code so that website doesn't have any slow perf issues due to cold start.
There are three main phases in Slot Swap with Preview :
- Deploy new code to source slot website
- Apply Slot Config : Source slot website recycles and starts with destination slot specific settings (app setting and database connection string).
- At this time we can run our test and/or execute warm-up code using source slot website URL.
- Note: both destination and source slot website URLs will be running using destination slot specific settings
- Complete Slot Swap : if the test is successful, we can complete the swap. Now destination slot website URL will run source slot code with destination slot settings
- Reset Slot Swap : if the test fails, we can reset the swap. This will restart source slot website and run under source slot settings
We can do Slow Swap with Preview using Azure Portal as shown below. Note : select the right slot for source.
Here are PS cmdlets to execute Slot Swap with Preview
$AzureWebsiteName = "azinsights" $AzureRGName = "InternalConsumptionResourceGroup" $From = "test" $To = "production"
#Switch-AzureWebsiteSlot -Name $AzureWebsiteName -Slot1 $From -Slot2 $To -Force -Verbose
Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction ApplySlotConfig
Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction CompleteSlotSwap
Switch-AzureRmWebAppSlot -ResourceGroupName $AzureRGName -Name $AzureWebsiteName -SourceSlotName $From -DestinationSlotName $To -SwapWithPreviewAction ResetSlotSwap |
Before executing Apply Slot Config PS cmdlets, here are process ID and AppDomain ID of source and destination slot websites :
Production Slot |
Test Slot |
After executing Apply Slot Config PS Cmdlet, test slot website recycled and now using production database. Destination slot is untouched.
Production Slot |
Test Slot |
After executing Complete Slot Swap PS Cmdlet, production slot website has same process id as previous test slot website . And the new test slot website recycled and now using test database.
Production Slot |
Test Slot |
More Info
Azure Web App Deployment Slot Swap with PreviewUsing PowerShell to manage Azure Web App Deployment Slots