Spring Cloud Config (scc) is a tool that provides support to externalize application configuration in a REST Service. The big picture is:
- Add a SCC client your application so when your application starts, it can fetch its configuration from SCC server.
- Setup a SCC server, which is a Java REST Service (more specifically is a Spring-Boot application).
The following image offers a overview of how Spring Cloud Config fits in you application architecture.
Some benefits of this strategy are:
- You decouple the evolution of your application from the evolution of the configuration, that is: you application will be the same in every environment while the configuration will be different in each environment. At the same time the change rate of your application is different from the change rate of the configuration.
- Your application forgets about where the configuration it stored because it delegates that concern to SCC server.
- SCC server supports several storage options: Git, File System, Vault, Database, ConfigMaps, etc. The default option is Git which is great because it «force» you to have your configuration versioned.
- SCC provides several common features related to configuration management like: check the current configuration values, configuration reloading, encryption of secrets and support for different configuration formats among other things.
While working with SCC I faced some issues regarding how to specify its configuration so I want to share some details here.
To make SCC Server read configuration from a remote Git repository:
spring.cloud.config.server.git.uri=https://.....
(this would work fine for public repositories, but if you need to use a private repository, which is a common case, you will need to specify some more parameters like strictHostKeyChecking and privateKey that are very well explained in the official documentation). When SCC server starts, it will clone the remote repository into a local directory whose location will be generated randomly at runtime (but it is also possible to specify the clone location).
To make it work with a local git repository (which contains a .git subdirectory), just use:
cloud.config.server.git.uri=file:///your/local/git/repo
To make ir work with a local «plain» directory we need to specify active profile as «native» which makes SCC server to read the config from a plain local directory (not a git directory)
spring.profiles.active=native spring.cloud.config.server.native.searchLocations=file:/your/directory
It worth mentioning that even when Spring Cloud Config is built on Java, you can use any client technology to consume it because it exposes a REST API. The Spring team provides a Java client, but there are also clients for other technologies.