简体   繁体   English

具有数据库迁移的Azure Web App部署槽

[英]Azure Web App deployment slots with database migration

I'm currently running a webApp with several deployment slots (eg dev, staging, production). 我目前正在运行带有多个部署插槽的webApp(例如dev,staging,production)。 Every Slot is connected to a database (db_dev, db_staging, db_production). 每个Slot都连接到一个数据库(db_dev,db_staging,db_production)。 I want to deploy to the staging slot and then switch with production. 我想部署到临时插槽,然后切换生产。 How do database migrations fit in here? 数据库迁移如何适应这里?

I mean, if i deploy a new build with db migrations to staging the db_staging gets updated. 我的意思是,如果我将具有db迁移的新构建部署到分段,则db_staging会更新。 What happens if I switch the slots? 如果我切换插槽怎么办? Do the migrations get applied to db_production? 迁移是否应用于db_production? What about downtimes? 停机时间怎么样?

From my understanding only the URLs are switched, so after the switch the app in the staging slot would point to the db_production? 根据我的理解,只有URL被切换,所以在切换后,临时插槽中的应用程序将指向db_production? That does not make sense. 那没有意义。

I could deploy to the staging slot and point to db_production (with migrations), but then the db would be updated and could possibly break the app in the live slot. 我可以部署到临时插槽并指向db_production(使用迁移),但随后数据库将被更新,并且可能会破坏实时插槽中的应用程序。

Instead of hard coding the connecting string in your source code, put them under the connecting strings section of your app service settings and access it as an environment variable. 不要在源代码中对连接字符串进行硬编码,而是将它们放在应用服务设置的连接字符串部分下,并将其作为环境变量进行访问。 It's not only safer as it will allow you to have just one code for any environment and by checking the setting as a "slot setting" no matter if you swap or not, for that slot, the configuration remains fixed. 它不仅更安全,因为它允许您只为任何环境提供一个代码,并通过将设置检查为“插槽设置”,无论您是否交换,对于该插槽,配置保持固定。

在此输入图像描述

More info here: 更多信息:

https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/ https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

Update : 更新

In the case of a database update, ie, necessary scripts that need to be run in order to update the database schema for the new app version, you can use the applicationInitialization section of your web.config. 对于数据库更新(即,为了更新新应用程序版本的数据库架构而需要运行的必需脚本),可以使用web.config的applicationInitialization部分。 Usually used to warm-up the app, but should work for your case as well. 通常用于预热应用程序,但也适用于您的情况。

<system.webServer>  
  <applicationInitialization >  
    <add initializationPage="/init-script.php" hostName="xxxxxx.azurewebsites.net"/>  
  </applicationInitialization>  
<system.webServer> 

The AppInit module will wait until this code completes before finishing the swap process which is basically allowing production traffic to the app. AppInit模块将等到此代码完成后再完成交换过程,这基本上允许应用程序的生产流量。 Basic logic would be checking if the database is running the expected version and if not some other logic would be executed in sequence. 基本逻辑将检查数据库是否正在运行预期版本,如果不是,则将按顺序执行某些其他逻辑。

I have been pondering this too, and as far as I can see the only sensible process is as follows: 我一直在思考这个问题,据我所知,唯一明智的过程如下:

  1. Stop Prelive stites 停止Prelive stites
  2. Clone live DB back to a new staging DB 将实时DB克隆回新的临时数据库
  3. Run scripts to make data safe (clear information which may contact real users etc) 运行脚本以确保数据安全(可以联系真实用户的明确信息等)
  4. Change staging slot sticky connection string to point at this database 将staging slot粘连连接字符串更改为指向此数据库
  5. Run DBUP aganst staging DB (now an upgraded version of live-ish) 运行DBUP aganst staging DB(现在是live-ish的升级版本)
  6. Deploy to staging slot 部署到临时插槽
  7. Restart prelive sites 重新启动prelive站点
  8. Test staging until satisfied 测试升级直到满意为止
  9. Backup live DB 备份实时数据库
  10. Run DBUP against live (if they are non-breaking changes, site can stay up) 针对实时运行DBUP(如果它们是非破坏性更改,则站点可以保持运行状态)
  11. Swap live and prelive slots 交换现场和前置插槽
  12. Check live 现场检查

If you can keep your db updates non-breaking, then rollback can be simple as swapping the slots back. 如果您可以保持数据库更新不中断,那么回滚可以很简单,就像交换插槽一样。 If not, you are back in the familiar pain of rollback scripts or restoring snapshots. 如果没有,您将回到熟悉的回滚脚本或恢复快照的痛苦中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Web 应用部署槽 web.config - Azure Web App deployment slots web.config Azure Web应用程序-其他部署插槽会影响生产插槽吗? - Azure web app - Additional deployment slots affect production slot? Azure部署插槽和数据库迁移 - Azure deployment slots and database migrations Azure:Azure应用服务的部署插槽的定价 - Azure: Pricing of deployment slots for an Azure App Service 一个 azure function 应用程序会触发所有部署槽吗? - An azure function app will trigger all the deployment slots? 使用部署槽将复杂的IIS网站移动到Azure Web应用程序 - Moving a complex IIS web site to Azure Web app using deployment slots Azure Web 应用部署槽,我可以将槽应用换成主生产,然后删除旧的吗? - Azure Web App deployment slots, can I swap a slot app for the main production, then delete the old one? Web App上到不同资源组的部署位置 - Deployment slots on Web App to different resource groups 部署后预热 Azure Web App(不使用部署槽) - Warming up Azure Web App after deploy (without using deployment slots) 交换 Azure Web App 部署槽会注销 ASP.NET Core RC2 中的所有用户 - Swapping Azure Web App deployment slots logs out all users in ASP.NET Core RC2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM