ref: https://spring.io/projects/spring-cloud-config
- Spring Cloud Config Server features:
- HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)
- Encrypt and decrypt property values (symmetric or asymmetric)
- Embeddable easily in a Spring Boot application using @EnableConfigServer
- Config Client features (for Spring applications):
- Bind to the Config Server and initialize Spring Environment with remote property sources
- Encrypt and decrypt property values (symmetric or asymmetric)
- demo
使用官网的spring initialzar生成config依赖。主要的pom依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId></dependency><dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId></dependency>
在resources目录下面配置需要的信息。(application-jenkins-dev.yml)
# jenkins configjenkins:
config:
proxy: xxx.xxx.xxx
url: jaymz.jenkins.com
# tool
custom:
tool:
name:
maven:
version: maven-3.3.9
url: xxx.xxx.xxx
IA:
version: InstallAnywhere_2018
url: xxx.xxx.xxx
JDK:
version: openjdk-8u171
url: xxx.xxx.xxx
然后我们启动springboot,访问:
http://localhost:8888/spring-config-demo/jenkins-dev,如下图所示:
为了让结果readable,我们用shell:
curl -k url |jq .
如下
配置中心的雏形出来了。下面就是整合散落在各个地方的config(application,infra等)。
未来还需要take actions:
- 整合需要移到配置中心的config(并翻译成yml)
- config server长活(加入到k8s中)
- 修改需要获取配置的代码
- 针对特殊场景(一旦code freeze,需要将配置中心的关于pipeline的代码作相应的更改,否则定时的job不受code freeze的规则约束)
网友评论