Managing config in 12-factor applications
Asked Answered
C

3

20

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!

Conservatoire answered 4/7, 2012 at 21:4 Comment(0)
S
5

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.

Sedberry answered 5/7, 2012 at 17:12 Comment(1)
I don't work with Heroku, but I consider that 12 factor could be applied to any SaaS application. I can create a custom shell script to create that configuration on my enviroments. But, after this background, my question is: there is no security concern in make my config vars, like database access' data, become env vars?Quincuncial
G
11

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.

Gump answered 5/7, 2012 at 14:40 Comment(0)
S
5

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.

Sedberry answered 5/7, 2012 at 17:12 Comment(1)
I don't work with Heroku, but I consider that 12 factor could be applied to any SaaS application. I can create a custom shell script to create that configuration on my enviroments. But, after this background, my question is: there is no security concern in make my config vars, like database access' data, become env vars?Quincuncial
K
1

A bit of a late answer, but I believe this is what you are looking for.

I developed a gem called settei, allowing you to use YAML files to configure the app. However the gem will serialize the YAML file as one environment variable during deploy. This way one get the best of both worlds: YAML for ease of management/creating derivative environment, and ENV for 12-factor compliance.

Kowalski answered 9/3, 2018 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.