App设置 – Azure应用服务(多个环境)

huangapple go评论74阅读模式
英文:

App Settings - Azure App Service (Multiple environments)

问题

I am trying to set up connectivity from azure app service to azure sql db using managed identity (System assigned)

Here is the set up: Two azure app services one for app and one for api in one service plan. I have a SQL server in Azure with two azure sql db. The app services have their system assigned managed identity turned on. I have app settings for multiple environments in both the project (app and api).
appsettings.json appsetings.Development.json appsettings.Acceptance.json appsettings.Production.json

When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.

The configuration -> application setting in Azure app service just has the app insight instrumentation key which I add (IaC) in template while provisioning app service in Azure. In this situation:

If all the app settings file are pushed (as seen in Kudu), which app setting will be read? appsettings.json or any other environment specific? As I understand it should be appsettings.json. Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)? Or any other way is better, easy, and secure? I am not sure how can I make use of secrets manager for multiple environments.

英文:

I am trying to set up connectivity from azure app service to azure sql db using managed identity (System assigned)

Here is the set up: Two azure app services one for app and one for api in one service plan. I have a SQL server in Azure with two azure sql db. The app services have their system assigned managed identity turned on. I have app settings for multiple environments in both the project (app and api).

appsettings.json
appsetings.Development.json
appsettings.Acceptance.json
appsettings.Production.json

When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.

The configuration ->application setting in Azure app service just has the app insight instrumentation key which I add (IaC) in template while provisioning app service in Azure. In this situation:

If all the app settings file are pushed (as seen in Kudu), which app setting will be read? appsettings.json or any other environment specific? As I understand it should be appsettings.json. Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)? Or any other way is better, easy, and secure? I am not sure how can I make use of secrets manager for multiple environment.

答案1

得分: 1

如我所提到的,应用程序设置的读取将基于环境。

  • 如果我们希望Azure应用程序选择特定的配置文件,那么我们需要使用特定值(Development/Production/Acceptance)设置键ASPNETCORE_ENVIRONMENT

>当我在将我的应用程序从YAML管道部署到应用服务后,在Kudu中探索时,我看到所有的应用程序设置文件都可用。

是的,当我们发布应用程序时,所有可用的配置文件都会部署到Azure应用服务中。

你也可以在我的应用程序中看到同样的情况。

KUDU控制台:

App设置 – Azure应用服务(多个环境)

  • 正如你所说,你是从yaml管道部署你的应用服务,那么你在yaml文件中指定的配置将会被使用。

  • 即使你在KUDU控制台中看到所有文件,实际上只有在yaml文件中指定的配置将会被应用程序使用。

  • 据我所知,仅在yaml文件中转换的应用程序设置才会被读取。

  • 你可以在PipelineAzure应用服务部署任务中找到这个选项。

App设置 – Azure应用服务(多个环境)

App设置 – Azure应用服务(多个环境)

App设置 – Azure应用服务(多个环境)

  • 你可以在Azure应用服务配置中看到yaml的配置=>应用程序设置

更多关于XML转换的信息,请参考MSDoc

>csharp >处理不同环境的应用程序设置的最佳方法是只在解决方案/仓库中保留appsettings.json和appsettings.development.json,然后在配置Azure应用程序服务(IaC模板)时,不同环境的参数文件可以包含所需的设置(存储为密钥保管库中的秘密并进行读取)? >

要使用Azure密钥保管库来存储密钥,我们在Azure管道任务中有一个选项。

App设置 – Azure应用服务(多个环境)

感谢@rahulpnath清晰解释了不同环境中配置文件的工作原理

英文:

As I have mentioned, reading of App settings will be based on the Environment.

  • If we want the Azure App to pick any particular configuration file, then we need to set the key ASPNETCORE_ENVIRONMENT with the specific value (Development/Production/Acceptance).

>When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.

Yes, when we publish the Application, all the available configuration files are deployed to Azure App Service.

You can see the same for my application too.

KUDU Console:

App设置 – Azure应用服务(多个环境)

  • As you said you are deploying your app service from yaml pipeline, then the configurations which you have specified in the yaml file only will be used.

  • Even though you see all the files in the KUDU Console, the configurations which are only specified in the yaml file be used in the App.

  • AFAIK, the application setting which are only transformed in the yaml file are only read.

  • You can find the option in Azure App Service deploy Task in the Pipeline.

App设置 – Azure应用服务(多个环境)

App设置 – Azure应用服务(多个环境)

App设置 – Azure应用服务(多个环境)

  • You can see the configurations of yaml in the Azure App Service => Configuration => Application settings.

Refer MSDoc for more information on XML Transformations.

>csharp
>Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)?
>

To Use Azure Key Vault for storing secrets we have an option in Aure Pipeline Task.

App设置 – Azure应用服务(多个环境)

Thanks @rahulpnath for the clear explanation on how configuration file works in different environment.

huangapple
  • 本文由 发表于 2023年4月17日 12:56:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定