Search code examples
javaspring-bootspring-cloud-configspring-profiles

Configure spring cloud config server for each profile group


I have few environments. There are:

  • local
  • dev
  • test
  • qa
  • lod
  • prod

Everything clear if config server connects to all of them.

In my case I need configuration server per group:

  • under dev control
  • under qa control
  • near devops control

Groups are connected to permissions and different environments.

so I need for each client something like:

bootstrap.yml

# default configs for local, dev, test profiles
spring:
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://local-dev-test-configuration-server:8888

---
# **bootstrap-qa.yml**
spring:
  profiles: qa
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://qa-configuration-server:8888

---
# **bootstrap-prod.yml**
spring:
  profiles: prod,lod
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://lod-prod-configuration-server:8888

Where

  • local-dev-test-configuration-server would have access to local, dev and test server configurations;
  • qa-configuration-server would have access to qa configuration;
  • lod-prod-configuration-server would have access to prod and lod configurations only.

Question:

I researched spring boot documentation but I have not faced with bootstrap.yml profiling.

  1. Which way I should follow to cover my needs (manage 3 different config servers and correspond profiles)?
  2. I've detected ability to configure different git resources for same config server. Is this approach the best for my case (I also have to manage few repositories to keep required configs)? I do not think so. I need to have few config servers for different envs because of different visibility. Thus I need configure on each consumer config hostname depending profile.

Solution

  • There are two possible solutions to configure clients for spring-cloud-configuration-servers:

    1. spring-boot supports profiles in bootstrap.yml, so configuration provided in question can be used as solution
    spring:
      application:
        name: discovery-service
      cloud:
        config:
          uri: http://local-dev-test-configuration-server:8888
    ---
    spring:
      profiles: qa
      application:
        name: discovery-service
      cloud:
        config:
          uri: http://qa-configuration-server:8888
    
    ---
    spring:
      profiles: prod,lod
      application:
        name: discovery-service
      cloud:
        config:
          uri: http://lod-prod-configuration-server:8888
    
    1. In case you want to keep bootstrap.yml configuration as simple as it possible:
    spring:
      application:
        name: discovery-service
      cloud:
        config:
          uri: http://local-dev-test-configuration-server:8888
    

    in this case solution is to use -Dspring.cloud.config.uri=http://localhost:8888 parameter overrides required property for example:

    java -Dspring.profiles.active=localhost -Dspring.cloud.config.uri=http://localhost:8888 -jar ./target/discovery-service-0.0.1-SNAPSHOT.jar
    

    P.S.

    Approaches can be mixed.