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

4

28

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 ?

Carbine answered 10/12, 2015 at 6:18 Comment(0)
B
53

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.

Bengurion answered 10/12, 2015 at 18:2 Comment(9)
Thanks. I was setting label all into config server. so is it all about the binding in config client application ? it was little confusing to decide between server's or client's spring.cloud.config property.Carbine
My branch has a slash (/), so how do I configure that? I tried spring.cloud.config.label=release/1.0.0,release_1.0.0,release(_)1.0.0 but does not workTouchmenot
I figured out. It should be release(_)1.0.0Touchmenot
@Bengurion - Any idea about having native profile, how to handle label in that case? Any pointers?Handsaw
For me above mentioned property didn't work and when I changed to following it worked fine spring.cloud.config.server.git.default-label = BranchName . I am using Spring Boot version 2.1.3.RELEASE and spring-cloud-config-server version 2.1.1.RELEASE.Unmoor
it should be spring.cloud.config.server.git.default-label=branchname and also, the branchname should not contain '/' - sLuminesce
Who calls a branch a "label"? Just call it a branch should be spring.cloud.config.branchOsteitis
because other repositories, such as jdbc or vault have no concept of branchBengurion
It can also be used for a tag or a commit id, so not limited to just a branch. cloud.spring.io/spring-cloud-config/multi/…Parade
T
24

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!

Turpitude answered 6/1, 2017 at 11:41 Comment(0)
W
17

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
Weidner answered 27/2, 2019 at 19:36 Comment(3)
Branchname also should not contain slashes /, otherwise it will not workLuminesce
Then what should we replace the slashes with, in the branchname?Bodoni
@Bodoni #43436397Alarum
D
15

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.

Dania answered 10/12, 2015 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.