Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask Spring Cloud Config server to checkout configuration from specific branch?

I have following Spring cloud config application.yml:

spring: 
  application: 
    name: configserver
  cloud: 
    config: 
      server: 
        git: 
          uri: https://[email protected]/xyz/microservices-configs.git
          username: xyz
          password: xyz
          basedir: target/configs
server:
  port: 8881  

Following is my bootstrap.yml of user microservice:

spring: 
  application: 
    name: userservice
  cloud: 
    config: 
      uri: http://localhost:8881/  

Scenario - 1
When I hit config server in browser like this:
http://localhost:8881/development/userservice-development.yml
It serves file properly. and when I look at basedir i.e. target/config, I see:

- userservice.yml  
- gateway.yml  

Exactly what I wanted, Since I added this two files only in development branch.

Scenario - 2
When I run my userservice microservice project using following command:
mvn clean spring-boot:run -Dspring.profiles.active=development

It fetches the right file from git, but it checkout from master branch ! but not from the development branch as I am expecting. am I expecting right ? (FYI I have both development and production yml in master branch)

So the question is, how do we go for using config server ? Is there any configuration which we can set to fetch yml from that particular branch only ? I believe we need to set some label, because as per documentation, default label is master. Can anyone let me know how do we go for setting label in above scenario ?

like image 276
A Gupta Avatar asked Dec 10 '15 06:12

A Gupta


3 Answers

According to the documentation, the configuration you want to set in your config client is:

spring.cloud.config.label=mybranch

Where mybranch is an existing branch in your git repo.

like image 130
spencergibb Avatar answered Sep 17 '22 15:09

spencergibb


You can specify the default branch (more generally, Git label) that a config server uses if a client does not specify the label, via property spring.cloud.config.server.git.default-label, perhaps this is what you are after? Certainly solves the issue for me!

like image 39
Matthew Wise Avatar answered Sep 17 '22 15:09

Matthew Wise


Config server designed to use profile to separate environment. Example:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

The branching make configuration inconsistency.

Concept of config server is based on 12-factor config (http://12factor.net/config ) .

Check it out for detail reason.

like image 24
Hlex Avatar answered Sep 16 '22 15:09

Hlex