AGupta
AGupta

Reputation: 5734

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 ?

Upvotes: 28

Views: 52717

Answers (4)

pabloferraz
pabloferraz

Reputation: 2166

If only use the branch in a yml file just configure:

spring:
  cloud:
    config:
      server:
        git: 
          uri: https://gitlab.com/somerepo.git
          username: someuser
          password: somepass
          default-label: branchname

Upvotes: 18

Matthew Wise
Matthew Wise

Reputation: 2849

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!

Upvotes: 24

spencergibb
spencergibb

Reputation: 25157

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.

Upvotes: 53

Hlex
Hlex

Reputation: 971

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.

Upvotes: 15

Related Questions