简体   繁体   English

服务结构中的配置转换?

[英]configuration transforms in service fabric?

When you create an empty Service Fabric application through Visual Studio, the project template will automatically create different configuration files for you such as Node1.XML, Node5.XML, etc. 当您通过Visual Studio创建一个空的Service Fabric应用程序时,项目模板将自动为您创建不同的配置文件,如Node1.XML,Node5.XML等。

We are much less concerned with the number of nodes than with which environment we are targeting. 我们更少关注节点数量而不是我们所针对的环境。

Is it contrary to Service Fabric recommendations to have simply 1 configuration file and create transforms from it? 只需1个配置文件并从中创建转换,与Service Fabric建议相反吗?

For example we might have something like this: 例如,我们可能会有这样的事情:

<?xml version="1.0" encoding="utf-8"?>
<PublishProfile xmlns="http://schemas.microsoft.com/2015/05/fabrictools">
  <!-- ClusterConnectionParameters allows you to specify the PowerShell parameters to use when connecting to the Service Fabric cluster.
       Valid parameters are any that are accepted by the Connect-ServiceFabricCluster cmdlet.

       For a remote cluster, you would need to specify the appropriate parameters for that specific cluster.
         For example: <ClusterConnectionParameters ConnectionEndpoint="mycluster.westus.cloudapp.azure.com:19000" />

       Example showing parameters for a cluster that uses certificate security:
       <ClusterConnectionParameters ConnectionEndpoint="mycluster.westus.cloudapp.azure.com:19000"
                                    X509Credential="true"
                                    ServerCertThumbprint="0123456789012345678901234567890123456789"
                                    FindType="FindByThumbprint"
                                    FindValue="9876543210987654321098765432109876543210"
                                    StoreLocation="CurrentUser"
                                    StoreName="My" />

       Example showing parameters for a cluster that uses Azure Active Directory (AAD) security:
       <ClusterConnectionParameters ConnectionEndpoint="mycluster.westus.cloudapp.azure.com:19000"
                                    AzureActiveDirectory="true"
                                    ServerCertThumbprint="0123456789012345678901234567890123456789" />
  -->
  <ClusterConnectionParameters ConnectionEndpoint="dzimchuk.westeurope.cloudapp.azure.com:19000" AzureActiveDirectory="true" ServerCertThumbprint="F52285B5F344C8D3C0B7ADDE0B421F08CF38CB1A" />
  <ApplicationParameterFile Path="..\ApplicationParameters\Cloud.xml" />
  <UpgradeDeployment Mode="Monitored" Enabled="true">
    <Parameters FailureAction="Rollback" Force="True" />
  </UpgradeDeployment>
</PublishProfile>

As part of our build process, we would like to be able to set the configuration (Debug/Release) and based on this, the configuration would be changed. 作为构建过程的一部分,我们希望能够设置配置(调试/发布),并在此基础上更改配置。 Is it possible to achieve this, or would it be contrary to the SF philosophy? 是否有可能实现这一目标,还是会违背SF理念?

Another configuration example would be this: 另一个配置示例是:

<?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">

  <Section Name="Logging">
    <Parameter Name="IncludeScopes" Value="false" />
    <Parameter Name="LogLevel:Default" Value="Debug" />
    <Parameter Name="LogLevel:System" Value="Information" />
    <Parameter Name="LogLevel:Microsoft" Value="Information" />
  </Section>

  <Section Name="Authentication">
    <Parameter Name="AzureAd:B2C:Instance" Value="e.g https://login.microsoftonline.com/" />
    <Parameter Name="AzureAd:B2C:TenantId" Value="B2C tenant ID" />
    <Parameter Name="AzureAd:B2C:Audience" Value="B2C Application ID" />
    <Parameter Name="AzureAd:B2C:Policy" Value="" />
  </Section>

  <Section Name="ApplicationInsights">
    <Parameter Name="InstrumentationKey" Value="" />
  </Section>

  <Section Name="Redis">
    <Parameter Name="Configuration" Value="" />
    <Parameter Name="InstanceName" Value="BookFast.Booking_" />
  </Section>

  <Section Name="FacilityApi">
    <Parameter Name="ServiceUri" Value="fabric:/BookFast/FacilityService" />
    <Parameter Name="ServiceApiResource" Value="" />
  </Section>

  <Section Name="Test">
    <Parameter Name="FailRandom" Value="false" />
  </Section>

</Settings>

How would we maintain values for for different environments for the above parameters? 对于上述参数,我们如何维护不同环境的值? Are separate files the way to go, or can we do config transforms and then target different build configurations? 单独的文件是可行的,还是我们可以进行配置转换然后定位不同的构建配置?

Is it contrary to Service Fabric recommendations to have simply 1 configuration file and create transforms from it? 只需1个配置文件并从中创建转换,与Service Fabric建议相反吗?

I'm not aware. 我不知道。 If it works for you and your team is happy then that is all that matters. 如果它适合您,您的团队很高兴那么这就是最重要的。 On a slightly different note, I applied App Config transforms to a WPF app (which wasn't a policy and wasn't technically achieveable by default) by a 3rd party tool called SlowCheetah and it worked rather well. 稍微不同的是,我通过名为SlowCheetah的第三方工具将App Config转换应用于WPF应用程序(这不是策略,默认情况下在技术上无法实现),并且它运行得相当好。

As part of our build process, we would like to be able to set the configuration (Debug/Release) and based on this, the configuration would be changed. 作为构建过程的一部分,我们希望能够设置配置(调试/发布),并在此基础上更改配置。 Is it possible to achieve this, or would it be contrary to the SF philosophy? 是否有可能实现这一目标,还是会违背SF理念?

Give SlowCheetah a try. 试试SlowCheetah吧。 To be honest I have not tried it with Service Fabric. 说实话,我还没有尝试使用Service Fabric。

Scott Hanselman: Scott Hanselman:

Folks want to transform their app.configs, or any XML file as part of their builds Tell me more 人们希望将他们的app.configs或任何XML文件转换为他们构建的一部分告诉我更多

OP: OP:

How would we maintain values for for different environments for the above parameters? 对于上述参数,我们如何维护不同环境的值? Are separate files the way to go, or can we do config transforms and then target different build configurations? 单独的文件是可行的,还是我们可以进行配置转换然后定位不同的构建配置?

Configuration Transforms (CT) are a bit of hotly-debated topic. 配置变换 (CT)是一个备受争议的话题。

Whilst I see no problem using CT for dev machines and say test environments, I would advise not to use them for Production . 虽然我发现使用CT开发机器并说测试环境没有问题,但我建议不要将它们用于生产

The reasoning is is that they are the product of a build process and not a static artifact managed by SCM . 原因是它们是构建过程的产物,而不是SCM管理的静态工件

"But Micky" , I hear you say, "EXEs and DLLs are the product of a build process" . “但Micky” ,我听到你说, “EXE和DLL是构建过程的产物”

True. 真正。 But there is no alternative to binaries which are the result of compilation of source code. 但是除了源代码编译结果的二进制文件之外别无选择。 You generally don't "compile" configuration files in the broadest terms in .NET, specifically IIS; 您通常不会在.NET中以最广泛的术语“编译”配置文件,特别是IIS; WCF and even Service Fabric it is not mandatory. WCF甚至Service Fabric都不是强制性的。

When part of a build process, should you need a copy of the configuration for the current version in Production, or say for one of your customer's sites from two builds ago, you need to run the build process again in order to obtain the produced file. 在构建过程的一部分时,如果您需要生产中当前版本的配置副本,或者对于两个版本之前的某个客户站点,则需要再次运行构建过程以获取生成的文件。

The problem with this are: 这个问题是:

  1. The build process may take considerable time 构建过程可能需要相当长的时间
  2. There is zero guarentee that the produced file exactly matches the historical version 没有保证生成的文件历史版本完全匹配
  3. Such transformed files are at the mercy of the transform tool , can you prove that future versions of the tool won't fault or mangle your file? 这些转换后的文件受转换工具的支配 ,你能证明该工具的未来版本不会出错或破坏你的文件吗?

My advice is to manually maintain configuation files for all your production nodes 我的建议是手动维护所有生产节点的配置文件

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

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