Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

12 factor app config and Java

I was reading the 12 factor app manifesto http://12factor.net/. The manifesto recommends storing the configuration data for the application in Enviornment variables. Does this mean that properties like the DB username / password, resource URL should be stored as a part of Java Env variables rather than as property files ? Is this a secure way of storing the information ? To me this seems to be a pretty clunky way of storing the information. Are there any best practices / experiences around this that can be shared ?

One option that I can think of is to have a separate configuration service running in the landscape, and use Env property to connect to the config service and then query the config service for further detailed configuration data.

like image 824
mithrandir Avatar asked Aug 15 '14 16:08

mithrandir


People also ask

Is 12 factor still relevant?

Containers, Kubernetes, and cloud-native are now mainstream technologies that enable you to create portable, scalable, and robust applications. Even so, the 12 Factors remain relevant in today's ecosystem.


3 Answers

12 factor apps are designed to run on platforms that orchestrate isolated UNIX processes. UNIX processes are configured via environment variables. While property files are a well-established Java convention, UNIX processes are a language-agnostic way to configure processes.

To support multiple configuration methods, a good best practice is to:

  • Read from process environment with System.getenv('CONFIG'), if null
  • Read from property file with properties.getProperty('CONFIG'), if null
  • Fall back to a default value

For more details, see Heroku's instructions on defining config vars for Java apps.

like image 178
gabrtv Avatar answered Oct 21 '22 11:10

gabrtv


We can use Spring Centralized Configuration to do that, using centralized configuration we can commit configuration of all of our projects into a single repository and later on while writing build scripts we can override our local configuration from that repository to use that centralised configuration.

By clicking on below link you will find getting started guide to do so

https://spring.io/guides/gs/centralized-configuration/

like image 21
Naresh Joshi Avatar answered Oct 21 '22 09:10

Naresh Joshi


This piece on How To Implement 12 Factor Configuration In Java maybe helpful: https://blog.codacy.com/12-factor-config-for-java/

It's published by Codacy, the automated code review tool.

like image 1
CodeHer22 Avatar answered Oct 21 '22 10:10

CodeHer22