【问题标题】:How to ask Spring Cloud Config server to checkout configuration from specific branch?如何要求 Spring Cloud Config 服务器从特定分支签出配置?
【发布时间】:2016-03-15 16:21:58
【问题描述】:

我有以下 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  

以下是我的用户微服务bootstrap.yml

spring: 
  application: 
    name: userservice
  cloud: 
    config: 
      uri: http://localhost:8881/  

场景 - 1
当我像这样在浏览器中点击配置服务器时:
http://localhost:8881/development/userservice-development.yml
它正确地提供文件。当我查看basedir 即目标/配置时,我看到:

- userservice.yml  
- gateway.yml  

正是我想要的,因为我只在开发分支中添加了这两个文件

场景 - 2
当我使用以下命令运行我的 userservice 微服务项目时:
mvn clean spring-boot:run -Dspring.profiles.active=development

它从 git 获取正确的文件,但 它从 master 分支结帐!不是从开发分支,正如我所期望的那样。我期待对吗? (仅供参考,我在 master 分支中有开发和生产 yml)

所以问题是,我们如何使用配置服务器?是否有任何配置可以设置为仅从该特定分支获取 yml ?我相信我们需要设置一些标签,因为根据文档,默认标签是主标签。谁能告诉我在上述场景中我们如何设置标签?

【问题讨论】:

    标签: spring git spring-mvc spring-boot spring-cloud


    【解决方案1】:

    根据documentation,您要在配置客户端中设置的配置是:

    spring.cloud.config.label=mybranch
    

    mybranch 是您的 git 存储库中的现有分支。

    【讨论】:

    • 谢谢。我将标签全部设置到配置服务器中。那么这一切都与配置客户端应用程序中的绑定有关吗?在服务器或客户端的 spring.cloud.config 属性之间做出选择并不令人困惑。
    • 我的分支有一个斜杠(/),那么我该如何配置呢?我试过spring.cloud.config.label=release/1.0.0,release_1.0.0,release(_)1.0.0,但不起作用
    • 我想通了。应该是release(_)1.0.0
    • 对我来说,上面提到的属性不起作用,当我改为关注它时,它工作正常 spring.cloud.config.server.git.default-label = BranchName 。我正在使用 Spring Boot 版本 2.1.3.RELEASE 和 spring-cloud-config-server 版本 2.1.1.RELEASE。
    • 谁称分支为“标签”?就叫它一个分支应该是spring.cloud.config.branch
    【解决方案2】:

    如果客户端未指定标签,您可以通过属性spring.cloud.config.server.git.default-label 指定配置服务器使用的默认分支(更一般地说,Git 标签),也许这就是您所追求的?肯定能帮我解决问题!

    【讨论】:

      【解决方案3】:

      配置服务器旨在使用配置文件来分离环境。 示例:

      /{application}/{profile}[/{label}]
      /{application}-{profile}.yml
      /{label}/{application}-{profile}.yml
      /{application}-{profile}.properties
      /{label}/{application}-{profile}.properties
      

      分支导致配置不一致。

      配置服务器的概念基于 12 因素配置 (http://12factor.net/config)。

      查看详细原因。

      【讨论】:

        【解决方案4】:

        如果只使用 yml 文件中的分支,只需配置:

        spring:
          cloud:
            config:
              server:
                git: 
                  uri: https://gitlab.com/somerepo.git
                  username: someuser
                  password: somepass
                  default-label: branchname
        

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-13
        • 2016-06-26
        • 2016-11-26
        • 2015-10-28
        • 1970-01-01
        • 2020-07-09
        • 2019-01-07
        相关资源
        最近更新 更多