如何要求 Spring Cloud Config 服务器从特定分支检出配置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34195002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ask Spring Cloud Config server to checkout configuration from specific branch?
提问by agpt
I have following Spring cloud config application.yml:
我有以下 Spring 云配置 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:
以下是我bootstrap.yml
的用户微服务:
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:
场景 - 1
当我像这样在浏览器中点击配置服务器时:http://localhost:8881/development/userservice-development.yml
它正确地提供文件。当我查看basedir
ie 目标/配置时,我看到:
- userservice.yml
- gateway.yml
Exactly what I wanted, Since I added this two files only in development branch.
正是我想要的,因为我只在 development 分支中添加了这两个文件。
Scenario - 2
When I run my userservice microservice project using following command:mvn clean spring-boot:run -Dspring.profiles.active=development
场景 - 2
当我使用以下命令运行我的 userservice 微服务项目时: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 branchas I am expecting. am I expecting right ? (FYI I have both development and production yml in master branch)
它从 git 获取正确的文件,但它从 master 分支检出!但不是像我期望的那样来自开发分支。我期待对吗?(仅供参考,我在主分支中有开发和生产 yml)
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 ?
所以问题是,我们如何使用 config server ?是否有任何配置可以设置为仅从该特定分支获取 yml?我相信我们需要设置一些标签,因为根据文档,默认标签是 master。谁能让我知道我们如何在上述情况下设置标签?
回答by spencergibb
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.
mybranch
您的 git 存储库中的现有分支在哪里。
回答by Matthew Wise
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!
如果客户端未指定标签,spring.cloud.config.server.git.default-label
您可以通过 property 指定配置服务器使用的默认分支(更一般地说,Git 标签),也许这就是您所追求的?当然可以为我解决问题!
回答by Hlex
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) .
配置服务器的概念基于 12-factor config ( http://12factor.net/config)。
Check it out for detail reason.
检查它的详细原因。
回答by pabloferraz
If only use the branch in a yml file just configure:
如果只使用 yml 文件中的分支,只需配置:
spring:
cloud:
config:
server:
git:
uri: https://gitlab.com/somerepo.git
username: someuser
password: somepass
default-label: branchname