What is the best way to change application configurations in a CI environment

后端 未结 1 1982
感动是毒
感动是毒 2020-12-22 11:53

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. Checkout co
相关标签:
1条回答
  • 2020-12-22 12:40

    Some approaches:

    Properties using Advanced Platforms

    Use some web platform like :

    • zookeeper
      • http://www.therore.net/java/2015/05/03/distributed-configuration-with-zookeeper-curator-and-spring-cloud-config.html
    • Spring Cloud
      • https://www.baeldung.com/spring-cloud-configuration
      • This is a java spring framework functionality in wich you can create properties file with configurations and configure your applications to read them.
    • magi-properties-management
      • This is a java web system in which you can create environments and any key:value in each one. You just need configure your application in any language to read this values.
    • cyber-properties-management
      • This is a nodejs application that allows you to store properties files (.properties .yml or .json) and then just consume them as rest endpoint from your applications.

    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.

    Properties from Environment variables

    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')
    

    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

    Properties from Database

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

    Properties from File System

    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.

    Note

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

    Devops Variable Substitution for Frontend js applications

    0 讨论(0)
提交回复
热议问题