Ocelot: Multiple ocelot.json configuration

Created on 3 Jan 2019  路  1Comment  路  Source: ThreeMammals/Ocelot

Multiple ocelot.json configurations

Steps to Reproduce the Problem

  1. have development, qa and production environments
  2. I am working with docker containers
  3. when I create a docker image i want that ocelot only take ocelo.{environment}.json depending on ASPNETCORE_ENVIRONMENT variable

Is there any way of doing this?... I tried with merging files but does not working because I have the same UpstreamPathTemplate and I only change the DownstreamHostAndPorts, Ocelot only take a ocelot.json or look for files that match the pattern (?i)ocelot.([a-zA-Z0-9]*).json and then merge these together.

I also tried adding only the corresponding file to the environment:

.ConfigureAppConfiguration((host, config) =>
            {
                config
                    .SetBasePath(host.HostingEnvironment.ContentRootPath)
                    .AddJsonFile("appsettings.json", true, true)
                    .AddJsonFile($"appsettings.{host.HostingEnvironment.EnvironmentName}.json", true, true)
                    .AddJsonFile($"ocelot.{host.HostingEnvironment.EnvironmentName.ToLower()}.json")
                    .AddOcelot(host.HostingEnvironment)
                    .AddEnvironmentVariables();
            }).UseStartup<Startup>();

but still does not working, thanks in advance.

Specifications

Most helpful comment

I have a module that I plan on pushing that will address this issue, but it is currently in progress. It will allow you to treat DownstreamHostAndPorts as a ServiceName instead and you can load the service hosts as an environment specific configuration. Until then, there are a couple of workarounds:

  • Use DNS and make sure the DNS entries return environment specific servers
  • Use DNS and pass in DNS host entries as docker variables (if running in docker)
  • Put config files in folders named for the environment, load the configuration from the folder based on the ASPNETCORE_ENVIRONMENT
  • Implement your own service provider

>All comments

I have a module that I plan on pushing that will address this issue, but it is currently in progress. It will allow you to treat DownstreamHostAndPorts as a ServiceName instead and you can load the service hosts as an environment specific configuration. Until then, there are a couple of workarounds:

  • Use DNS and make sure the DNS entries return environment specific servers
  • Use DNS and pass in DNS host entries as docker variables (if running in docker)
  • Put config files in folders named for the environment, load the configuration from the folder based on the ASPNETCORE_ENVIRONMENT
  • Implement your own service provider
Was this page helpful?
0 / 5 - 0 ratings