Deploying to Production using Local Cache and Swap with Preview

 










Note: This article applies to Windows App Service Plan only as both Local Cache and Swap with Preview are not available for Linux App Service Plan’s. Additionally, Slot Swap feature is available for sites running in Standard or higher pricing tiers.




 


Scenario: There is a site in production which is running on 2 instances and has Local Cache enabled. We need to deploy new content to it with minimal downtime.


 


Pre-requisites:



  1. The App Service Plan is using Windows OS.

  2. The production slot has Local Cache enabled.

  3. The staging slot where the new content/code is being deployed doesn’t have Local Cache enabled.


 


Steps to deploy:



  1. If not already created, then create a new staging slot.

  2. Deploy the code to the staging slot.

  3. Navigate to Deployment slots and click on Swap.

  4. Select the Source and the Target slots and select the checkbox “Perform swap with preview“.

    Swapwithpreview1.jpg

     





  1. You can review the changes that will be applied and then click on Start Swap button. This will initiate Phase one of the swap.

  2. This will perform a restart of the application so that the prod settings can be applied to the application and also to initialize Local Cache. This completes Phase one of the swap.

  3. Once the app has been restarted, browse the slot to review the changes that were made to the new code base for this application.

  4. In order to proceed with Phase two, we need to wait for Local cache initialization to complete. Follow the below steps to determine if the Local Cache has been initialized.


    1. Browse to the KUDU Console of the slot.

    2. Click on Process Explorer menu.

    3. You will see a list of process. Right click the process that doesn’t have the SCM tag against it and click on properties.
      ProcExp.jpg

    4. Click on Environment variables and find environment variable WEBSITE_LOCALCACHE_READY. If the value of this variable is set to TRUE, then Local Cache has been initialized, if it is False, then Local Cache initialization is still in progress.
      ProcProperties2.jpg

       













NOTE: You can call the KUDU api to automate the above process. Review the documentation here.




 



  1. Once the process environment variable WEBSITE_LOCALCACHE_READY is set to TRUE, browse the slot and if everything looks good, set the Swap action to Complete Swap and click on Complete Swap button. If you need to revert the change, then set the Swap action to Cancel Swap and click on Cancel Swap button.

    Swapwithpreview2.jpg

  2. The Complete Swap will now promote the staging slot to production. Since its already running against Local Cache, the site will not encounter additional restarts and will be serving production traffic.


 


Further Reading:


Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.