Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing config in 12-factor applications

Tags:

I've enjoyed using Rails on Heroku, and like that I can adjust the configuration property of a Heroku app without having to commit a change to xyz.yml and redeploy.

It would be nice to completely do away with the Yaml config files in my Rails app, and rely as much as possible on storing configuration in ENV. This goes along with the 12-factor config principle.

However, there are some trade-offs in switching from a Yaml-based configuration management to a Heroku/12-factor-based one.

  • While it's true that a proliferation of deployments (qa, stage, prod, dev, demo, labs) can lead to a proliferation of Yaml files, it's very easy to copy-paste to create a new configuration profile. I don't see a way to 'copy' configuration profiles from one deployment to another in Heroku.
  • Storing configuration data in the repo means that, in the case of Heroku, deploying and configuring and application are accomplished in a single operation. If I were to move my configuration out of Yaml files and into ENV variables, I would have to configure my application in a separate step after deployment.

Would like to hear from people who have used 12-factor style configuration in their private applications, and how they have managed lots of configuration variables across lots of deployments.

  • How do you quickly configure a new deployment?
  • Where do you keep your authoritative source of configuration variables, if not the repo? How do you distribute it among developers?

Thanks!

like image 884
maxenglander Avatar asked Jul 04 '12 21:07

maxenglander


People also ask

What are the 12 factor application methodologies?

The Twelve-Factor App methodology is a methodology for building software-as-a-service applications. These best practices are designed to enable applications to be built with portability and resilience when deployed to the web.

Is 12 Factor app still relevant?

The Relevance of the Factors in 2021In general, these twelve factors are still highly relevant today, particularly for building microservices-based and cloud-native applications. Modern programming languages, development environments and frameworks enable easy adoption of these factors.


2 Answers

What I typically use is Yaml using the ENV and provide defaults. For instance, YAML can be ERB'ed happily to include your ENV vars:

foo:
  var: ENV["MY_CONFIG"] || "default_value"

You just need to make sure that you load the Yaml with ERB when you read it:

YAML.load(ERB.new(File.read("#{Rails.root}/config/app_config.yml")).result)

By doing this your code works fine in dev, but also allows you to set config vars in the environment as well.

like image 175
Neil Middleton Avatar answered Oct 12 '22 15:10

Neil Middleton


You can accomplish this relatively easy with some simple shell scripts, iterate existing variables via heroku config or heroku release:info v99, and then set heroku config:set k=v --app

But if its a problem/pain/friction perhaps you have too much inside your env var configuration.

like image 34
Mâtt Frëëman Avatar answered Oct 12 '22 16:10

Mâtt Frëëman