如何在Azure中设置部署,以便根据环境使用不同的数据库?

时间:2023-01-31 23:52:34

You can easily swap two deployments between staging and production environment in the Azure Management Portal by swapping their VIP. When working on a staging version of the services we want to use a staging database as well so we don't risk clobbering actual customer data. However, after swapping staging and production services the now-production (and formerly staging) deployment should obviously work on the production database.

您可以通过交换其VIP来轻松地在Azure管理门户中的登台和生产环境之间交换两个部署。在处理暂存版本的服务时,我们也希望使用临时数据库,因此我们不会冒险破坏实际的客户数据。但是,在交换分段和生产服务之后,现在生产(以及之前的分段)部署显然应该在生产数据库上运行。

So essentially the database to use would depend on whether the instance runs in the Staging or Production environment. Is there a good way of achieving that? Relying on the VIP and hard-coding the database switching based on that is probably not the best idea, I guess.

所以基本上要使用的数据库取决于实例是在Staging还是Production环境中运行。有没有一个很好的方法来实现这一目标?我想,依靠VIP和硬编码数据库切换基于这可能不是最好的主意。

3 个解决方案

#1


11  

My recommendation would be to stop using the "staging slot" of a service for the function you used a traditional "staging environment" for. When I'm speaking to folks about Windows Azure, I strongly recommend they use the staging slots only to smoke test a new deployment before it goes live. If they want a more protracted sort of testing, the kind many of us are used to having on-premises, then use a separate service and possibly even a separate subscription (the later is great if you want cost transparency).

我的建议是停止使用服务的“临时插槽”来实现您使用传统“临时环境”的功能。当我与人们谈论Windows Azure时,我强烈建议他们仅使用暂存插槽在新部署上线之前对其进行冒充测试。如果他们想要进行更长时间的测试,那么我们很多人都习惯使用内部部署,然后使用单独的服务,甚至可能使用单独的订阅(如果您希望成本透明,则后者很好)。

All this said, your only real options are to have a second service configuration that is specific for production that you update to before you execute the VIP swap, or you write some code that allows the service to detect which slot it's in and pull the appropriate of two configuration settings.

所有这些说,你唯一真正的选择是在执行VIP交换之前有一个特定于你更新的生产的第二个服务配置,或者你写了一些代码,允许服务检测它所在的插槽并拉出适当的两个配置设置。

However, as I outlined in the first paragraph, I think there's a better way to do things. :)

但是,正如我在第一段中所概述的那样,我认为有更好的方法可以做到。 :)

#2


6  

In a recent release of Azure Websites, the story here has changed. You may now specify that any app setting or connection string is a "slot setting", pinning it to the particular slot. To solve your issue, you would simply set the connection string(s) in each slot and take care to check 'Slot Setting'.

在最近发布的Azure网站中,这里的故事发生了变化。您现在可以指定任何应用程序设置或连接字符串是“插槽设置”,将其固定到特定插槽。要解决您的问题,您只需在每个插槽中设置连接字符串,并注意检查“插槽设置”。

I'm less clear if this is an advisable approach now. Database schema migration and rollback aren't baked in, and I'm unsure how to handle that correctly. Also only app settings and connection strings work this way, so, for example, system.net.mail settings cannot be pinned to a slot. For that, you'd need to change code to get mail server info, etc. from app settings or else use some other approach.

如果现在这是一个可行的方法,我不太清楚。数据库模式迁移和回滚未被烘焙,我不确定如何正确处理它。此外,只有应用程序设置和连接字符串以这种方式工作,因此,例如,system.net.mail设置无法固定到插槽。为此,您需要更改代码以从应用程序设置获取邮件服务器信息等,或者使用其他方法。

#3


2  

Re: "When working on a staging version of the services we want to use a staging database as well so we don't risk clobbering actual customer data." There is not a built-in way to do this.

Re:“在处理暂存版本的服务时,我们也希望使用临时数据库,因此我们不会冒险破坏实际的客户数据。”没有内置的方法来做到这一点。

If you wish to test without risk to production data, consider doing this testing in another Azure account - one that doesn't even have access to the production database. Then, when you think the system is tested and ready to go live, only then bring it up into the staging slot next to your production instance for a final smoke test.

如果您希望在没有生产数据风险的情况下进行测试,请考虑在另一个Azure帐户中进行此测试 - 该帐户甚至无法访问生产数据库。然后,当您认为系统已经过测试并准备好上线时,只需将其放入生产实例旁边的临时插槽中进行最终的烟雾测试。

I can imagine scenarios where you'd also want to a run through a few scenarios on the staging instance before doing a VIP Swap, but don't want to pollute production data. For this, many companies use special accounts - data associated with these accounts is known (or marked somehow) to be not from real customers so can be skipped in reporting and billing and such.

我可以想象在执行VIP交换之前您还希望在登台实例上运行几个场景但不想污染生产数据的场景。为此,许多公司使用特殊帐户 - 与这些帐户相关联的数据已知(或以某种方式标记)不是来自真实客户,因此可以在报告和计费等中跳过。

Re: "Relying on the VIP and hard-coding the database switching based on that is probably not the best idea, I guess." If by hard-coding, you mean reading it from a config file, that is probably not a bad idea, if you use an approach as mentioned above. I have heard of some folks going with a "figure out if we are in a staging slot and do something different in the code" approach, but I rather recommend what I described above.

回复:“我认为,依靠VIP和硬编码数据库切换可能不是最好的主意。”如果通过硬编码,你的意思是从配置文件中读取它,这可能不是一个坏主意,如果你使用上面提到的方法。我听说有些人会“弄清楚我们是否处于一个临时插槽并在代码中采取不同的做法”,但我更推荐上面所述的内容。

#1


11  

My recommendation would be to stop using the "staging slot" of a service for the function you used a traditional "staging environment" for. When I'm speaking to folks about Windows Azure, I strongly recommend they use the staging slots only to smoke test a new deployment before it goes live. If they want a more protracted sort of testing, the kind many of us are used to having on-premises, then use a separate service and possibly even a separate subscription (the later is great if you want cost transparency).

我的建议是停止使用服务的“临时插槽”来实现您使用传统“临时环境”的功能。当我与人们谈论Windows Azure时,我强烈建议他们仅使用暂存插槽在新部署上线之前对其进行冒充测试。如果他们想要进行更长时间的测试,那么我们很多人都习惯使用内部部署,然后使用单独的服务,甚至可能使用单独的订阅(如果您希望成本透明,则后者很好)。

All this said, your only real options are to have a second service configuration that is specific for production that you update to before you execute the VIP swap, or you write some code that allows the service to detect which slot it's in and pull the appropriate of two configuration settings.

所有这些说,你唯一真正的选择是在执行VIP交换之前有一个特定于你更新的生产的第二个服务配置,或者你写了一些代码,允许服务检测它所在的插槽并拉出适当的两个配置设置。

However, as I outlined in the first paragraph, I think there's a better way to do things. :)

但是,正如我在第一段中所概述的那样,我认为有更好的方法可以做到。 :)

#2


6  

In a recent release of Azure Websites, the story here has changed. You may now specify that any app setting or connection string is a "slot setting", pinning it to the particular slot. To solve your issue, you would simply set the connection string(s) in each slot and take care to check 'Slot Setting'.

在最近发布的Azure网站中,这里的故事发生了变化。您现在可以指定任何应用程序设置或连接字符串是“插槽设置”,将其固定到特定插槽。要解决您的问题,您只需在每个插槽中设置连接字符串,并注意检查“插槽设置”。

I'm less clear if this is an advisable approach now. Database schema migration and rollback aren't baked in, and I'm unsure how to handle that correctly. Also only app settings and connection strings work this way, so, for example, system.net.mail settings cannot be pinned to a slot. For that, you'd need to change code to get mail server info, etc. from app settings or else use some other approach.

如果现在这是一个可行的方法,我不太清楚。数据库模式迁移和回滚未被烘焙,我不确定如何正确处理它。此外,只有应用程序设置和连接字符串以这种方式工作,因此,例如,system.net.mail设置无法固定到插槽。为此,您需要更改代码以从应用程序设置获取邮件服务器信息等,或者使用其他方法。

#3


2  

Re: "When working on a staging version of the services we want to use a staging database as well so we don't risk clobbering actual customer data." There is not a built-in way to do this.

Re:“在处理暂存版本的服务时,我们也希望使用临时数据库,因此我们不会冒险破坏实际的客户数据。”没有内置的方法来做到这一点。

If you wish to test without risk to production data, consider doing this testing in another Azure account - one that doesn't even have access to the production database. Then, when you think the system is tested and ready to go live, only then bring it up into the staging slot next to your production instance for a final smoke test.

如果您希望在没有生产数据风险的情况下进行测试,请考虑在另一个Azure帐户中进行此测试 - 该帐户甚至无法访问生产数据库。然后,当您认为系统已经过测试并准备好上线时,只需将其放入生产实例旁边的临时插槽中进行最终的烟雾测试。

I can imagine scenarios where you'd also want to a run through a few scenarios on the staging instance before doing a VIP Swap, but don't want to pollute production data. For this, many companies use special accounts - data associated with these accounts is known (or marked somehow) to be not from real customers so can be skipped in reporting and billing and such.

我可以想象在执行VIP交换之前您还希望在登台实例上运行几个场景但不想污染生产数据的场景。为此,许多公司使用特殊帐户 - 与这些帐户相关联的数据已知(或以某种方式标记)不是来自真实客户,因此可以在报告和计费等中跳过。

Re: "Relying on the VIP and hard-coding the database switching based on that is probably not the best idea, I guess." If by hard-coding, you mean reading it from a config file, that is probably not a bad idea, if you use an approach as mentioned above. I have heard of some folks going with a "figure out if we are in a staging slot and do something different in the code" approach, but I rather recommend what I described above.

回复:“我认为,依靠VIP和硬编码数据库切换可能不是最好的主意。”如果通过硬编码,你的意思是从配置文件中读取它,这可能不是一个坏主意,如果你使用上面提到的方法。我听说有些人会“弄清楚我们是否处于一个临时插槽并在代码中采取不同的做法”,但我更推荐上面所述的内容。