0

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 code from SVN
  2. Compile the program
  3. Deploy to a predefined location on the server
  4. Change DB configurations (& maybe even other configs not identified yet) to point to the appropriate DB
  5. Execute the program
  6. Execute QA process to validate the output

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.

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

Sumit
  • 540
  • 9
  • 20
  • 1
    Configuration files are not strictly source code, so a VCS is not optimal to manage environment-dependent configs. You could keep separate branches for different configs, but merging source code changes to all of them is too time-consuming. Building auto-provision into your app is certainly the better approach in terms of scale-ability and automation, but also has drawbacks like potential security risks (attack surface) and requires a network or internet connection to access centrally stored config data. – NoMad Jul 10 '18 at 21:03

1 Answers1

1

Some approaches:

Properties using Advanced Platforms

Use some web platform like :

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

JRichardsz
  • 14,356
  • 6
  • 59
  • 94
  • Thx @JRichardsz. I already had Point 2 in my mind but wanted to see if there are any standard ways that people have achieved this. Will further investigate on the options in Point 1, although I am skeptical if I would be able to make the required changes into our applications!! – Sumit Jul 11 '18 at 08:51
  • 1
    All is possible with time and coffee. If there is not time, more coffee will be required. What is the applications language? – JRichardsz Jul 11 '18 at 14:50
  • All the programs are in Java / Spring Batch. – Sumit Jul 11 '18 at 20:39
  • 1
    Java and spring are incredibly configurable :D. Your app that reads datbase.xml are developed with spring batch? If your answer is "yes" , approach 1 is highly possible. Even could use spring cloud configuration because is spring. If you can, upload a safe version (hello world maybe) of your application to github and share me the link to help you – JRichardsz Jul 11 '18 at 21:30
  • Thx @JRichardsz. My skepticism was not due to a technical capability of the programs but more on the change management processes we have in our organization :) Anyhow thanks for your help. – Sumit Jul 17 '18 at 10:09