srobbin / opsworks_custom_env

This chef cookbook writes custom app configuration values from the OpsWorks stack's custom JSON to a config/application.yml file for each app. The figaro gem can help load those values directly into the application's ENV.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opsworks_custom_env

This cookbook allows Rails apps on Amazon OpsWorks to separate their configuration from their code. In keeping with Heroku's twelve-factor app, the configuration is made available to the app's environment.

To accomplish this, the cookbook maintains a config/application.yml file in each respective app's deploy directory. E.g.:

---
FOO: "http://www.yahoo.com"
BAR: "1001"

Your application can then load its settings directly from this file, or use Figaro to automatically make these settings available in the app's ENV (recommended).

Configuration values are specified in the stack's custom JSON. Example:

{
  "custom_env": {
    "my_app": {
      "FOO": "http://www.yahoo.com",
      "BAR": "1001"
    }
  },
  
  "deploy": {
    "my_app": {
      "symlink_before_migrate": {
        "config/application.yml": "config/application.yml"
      }
    }
  }
}

Note that the symlink_before_migrate attributes are necessary so that OpsWorks automatically symlinks the shared file when setting up release directories or deploying a new version.

Caveats

At the moment, only Unicorn/Nginx-style Rails apps are supported.

Opsworks Set-Up

The opsworks_custom_env::configure recipe should be added as a custom recipe to the Deploy event. It executes a restart Rails app APPNAME resource when the settings have changed, so ensure that this is defined. (In a typical rails layer, this is provided by the rails::configure recipe.)

About

This chef cookbook writes custom app configuration values from the OpsWorks stack's custom JSON to a config/application.yml file for each app. The figaro gem can help load those values directly into the application's ENV.