简体   繁体   中英

How to achieve zero downtime deployment to Azure web app with database updates?

I'm trying to achieve zero downtime deployments of an Azure web app where database schema updates need to be applied as part of the deployment.

I have the following setup:

Production web app with production-db connection string.

Staging deployment slot with staging-db connection string.

My pseudo-deployment process is something like:

  1. Make a copy of the production-db database
  2. Configure the Staging slot to use the database copy
  3. Deploy code to the Staging slot
  4. Apply schema updates to the database copy
  5. Test-run the app in the Staging slot (with the updated database) and pre-warm it
  6. If everything works, perform a hot swap so that the pre-warmed app in the Staging slot goes live, ie becomes the production slot, still using the updated database

In other words, after the hot swap, I want both the new code and the updated database to be live.

If something goes wrong at this point, I can simply swap slots again, making the old production app (and its database) go live.

As I understand it now, when I swap slots, the app will use the connection string of the production slot, restarting the app and forcing me to apply the database schema updates after the updated code goes live.

I hope I'm describing this properly. :) This seems like it should be a fairly common scenario?

Any help or pointers are greatly appreciated!

PS. I've looked at Azure seamless upgrade when database schema changes , but that answer isn't valid, as I can't apply the schema updates without affecting the application.

Edit: Just a thought: perhaps I should skip putting the connection string as a portal setting, and instead just keep it in web.config. That way, when swapping, the app won't need to restart, and since web.config will be included in the swap, the new production slot will use the updated database.

Edit 2: I think I was mistaken about the app restart when app settings or connection strings differ between slots. It seems I can indeed set a different connection string (pointing to the database copy) for the deployment slot, and then swap without an app restart affecting website visitors.

Could you not make the connection string sticky to the slot?

在此处输入图片说明

Full details are here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM