Spring Cloud Config - bootstraping compositie configuration - spring

Is it possible to bootstrap spring config service with composite configuration.
Example:
Final configuration (placed on the git repo )
spring:
cloud:
config:
server:
composite:
- type: git
uri: <uri1>
- type: git
uri: <uri2>
After I setup env variable to bootstrap:
SPRING_CLOUD_CONFIG_SERVER_BOOTSTRAP = true
and provide setup to fetch configuration from repository spring config is not adding new configuration for additional repositories.
Is it possible to configure spring config server to bootstrap from one repository and then serve configuration from different one(s)?

Related

Spring Cloud Config Client multiple property files retrieve from same repo

I have a requirement to retrieve the property files with environment name distinguishing those.
Config server is listening to this repo (https://github.com/tpande1/spring-cloud-config-repo/tree/master) which has : config-client-dev.properties, config-client-sbx.properties, config-client-test.properties and config-client-prod.properties
In Client Server i have the below config to read from the above github repo. How can i read these different properties with the environment specified in my Client Application?
Sample Rest Code:
#GetMapping("/message") //Pick message(SBX, DEV, Test, PROD) from the propertyfile from github
public String getMessage() {
return message;
}
bootstrap.yml:
spring:
profiles: dev
application:
name: config-client
cloud:
config:
uri: http://localhost:1000 //Config server port
profile: sbx, dev, test, prod
management.endpoints.web.exposure.include: "*"
You can add multiple active profiles in your bootstrap yaml file. In the option where you have spring.profiles.active and in your config server, you can add search patterns for each profile.
As mentioned in the below link in Pattern matching section.
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html

Shared Config(at git) between SPring Boot Services

I am developing spring boot services.
So lets say I have 3 Services A, B, C with dev and prod profiles each. Now I am keeping the configuration for these services at GIT and using config server to fetch the configuration.
So when I run A service in prod mode, the config file A-prod.properties is getting used.
Now I want to keep some common configuration which will be used by all 3 Services say common-prod.properties. How should I do that?
I have tried this:
Config Server :
spring:
cloud:
config:
server:
git:
uri: http://gitPaath/Configs.git
username: <username>
password: <pass>
cloneOnStart: true
searchPaths: "{common}"
My properties are file are in Git Repo in this order :
- A-prod.properties
- A-dev.properties
- B-prod.properties
- A-dev.properties
- C-prod.properties
- C-dev.properties
- common
- common-prod.propeties
- common-dev.properties
You can put all shared properties between services in application-<profile>.properties file.
In your case, make application-prod.properties and application-dev.properties files and put these file on root folder or any folder that is searchable by config server.
You can find more details in "Sharing Configuration With All Applications" section in here.

How can I integrate Spring Cloud with logback?

I have two Spring Boot applications:
cloud-config
It has following file structure:
└───src
└───main
└───environment
└───default
├───application.yml
└───bootstrap.yml
...
application.yml:
server:
port: 8087
spring:
cloud:
config:
server:
git:
uri: ssh://path-to-repository.git
bootstrap.yml:
spring:
application:
name: cloud-config
main-application:
└───src
└───main
└───environment
└───default
├───bootstrap.yml
└───logback.xml
I have application.yml for my main-application in git repository.
Also in git repository I have file with properties: application-default.properties.
I want to move logback.xml to git repository to get it with spring-cloud. How can I do this?
To solve my task I have done following:
add logback.xml to my Spring Cloud repository;
remove logback.xml from main > environment > default directory;
add to bootstrap.yml of main-application module:
logging:
config: http://localhost:8087/main-application/default/master/logback.xml
Documentation: description of logging: config: path: Serving plain text
logging.config=${spring.cloud.config.uri}/guestservices/default/master/logback.xml
works for me.

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://xyz#bitbucket.org/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 ?
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.
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!
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
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.

Spring cloud config directory structure

I have a working Spring cloud config server who provides configuration from a git repository. All configurations are stored in the root directory in the repository. They are named {name}-{profile}.yml.
I have changed the directory structure to {name}/{profile}.yml
When I curl http://configserver:8888/appname/myprofile the config server I get a json response but the propertySources is empty.
My spring cloud server config
spring:
cloud:
config:
server:
git:
uri: http://git#git.host/scm/cas/application-config.git
You need to add cloud.config.server.git.searchPaths to the configuration server application.yml.
cloud:
config:
server:
git:
searchPaths: <directory>

Resources