在 CI 环境中更改应用程序配置的最佳方法是什么 [英] What is the best way to change application configurations in a CI environment

查看:31
本文介绍了在 CI 环境中更改应用程序配置的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Jenkins 管道上进行 POC,以了解如何在 CI 环境中配置我的产品.管道的要求是:

I am currently doing a POC on Jenkins pipeline to figure out how to configure my product in a CI environment. The requirements of the pipeline are:

  1. 来自 SVN 的结帐代码
  2. 编译程序
  3. 部署到服务器上的预定义位置
  4. 更改数据库配置(甚至可能是其他尚未识别的配置)以指向适当的数据库
  5. 执行程序
  6. 执行 QA 流程以验证输出

我目前难以实现上述第 4 点.所有与 DB 相关的配置都驻留在每个程序的 database.xml 文件中一个程序可以连接到 1 个或多个 DB.

I am currently having difficulty in achieving Point 4 above. All DB-related configurations reside in a database.xml file per program & a program can connect to 1 or more DBs.

鉴于开发人员可以自由签入任何数据库配置,我仍然希望我的 CI 环境指向一个预定义的数据库进行测试.我不确定如何动态更改这些配置文件来实现这一点.

Given that developers are free to check-in any DB configurations, I would still like my CI environment to point to a predefined DB to test against. I am unsure on how to dynamically change these configuration files to achieve this.

如果有其他人也使用标准方法来实现相同的目标,请告诉我.

Please let me know if there are standard methods that others are also using to achieve the same.

TIA

推荐答案

一些方法:

使用一些网络平台,如:

Use some web platform like :

  • 动物园管理员
    • 这是一个 Java 网络系统,您可以在其中创建环境和每个环境中的任何键:值.您只需要以任何语言配置您的应用程序即可读取这些值.
    • 这是一个 nodejs 应用程序,它允许您存储属性文件(.properties .yml 或 .json),然后将它们用作应用程序的其余端点.

    使用这种方法,当需要更改配置时,您只需更新系统中的值并重新启动应用程序.甚至可以在 Java 应用程序中进行热重载.

    With this approaches , when a change of configurations is required, you just need update the value in the system and restart your application. It is even possible a hot reload in java applications.

    您可以在启动应用程序之前将您的 key:value 属性导出为环境变量:

    You can export your key:value properties as environment vars before starting the application :

    export DATABASE_HOST=10.100.200.300
    export LOG_DIR_LOCATION=/logs
    

    并在应用程序启动后阅读:

    And read it after after the application has started:

    Java >> System.getEnv("DATABASE_HOST"); 
    node.js >> process.evn.LOG_DIR_LOCATION
    php >> getenv('DATABASE_HOST')
    

    来自 SCM 的属性

    • 创建一些名为 development-configurations
    • 的 svn 存储库
    • 上传带有开发值的database.xml
    • 在您的应用程序中,放置一个带有虚拟值的 database.xml:localhost 等
    • 创建一个 jenkins 作业并将环境作为参数.
    • 在同一个作业中下载您的应用程序的 svn 源代码.
    • 下载名为 $environment-configurations 的 svn 存储库.$environment 将成为您的论据
    • 将应用程序中的 database.xml 替换为 $environment-configurations 存储库的 database.xml.
    • 只需创建另一个用于测试、uat 和生产的存储库.作业必须以接收环境作为参数来选择正确的 database.xml
    • Properties from SCM

      • Create some svn repositoty called development-configurations
      • Upload your database.xml with development values
      • In your application, put a database.xml with dummy values : localhost, etc
      • Create a jenkins job and put the environment as an argument.
      • In the same job download svn source code of your application.
      • download svn repository called $environment-configurations. $environment will be your argument
      • replace the database.xml inside of your application with database.xml of $environment-configurations repository.
      • Just create another repositories for testing, uat and production. Job must be receive environment as an argument to choose the right database.xml
      • 修改您的应用程序以从某些数据库而不是 xml 文件中读取配置

        Modify your applications to read configurations from some database instead of xml file

        修改您的应用程序以读取外部 database.xml 而不是源代码中的 database.xml.使用这种方法,您只需将 database.xml 放在服务器的某个路径中,然后从应用程序源代码中删除它.

        Modify your application to read an external database.xml instead of the database.xml inside of your source code. With this approach you just need put the database.xml in some path of your server and delete it from your application source code.

        您不仅可以将这些方法用于后端应用.您可以将它们用于前端应用程序:

        You can use these approaches not only for backend apps. You can use them for frontends applications:

        前端js应用的Devops变量替换

        这篇关于在 CI 环境中更改应用程序配置的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆