David Dollar

Simulating the Heroku Environment in Development

I've been using Heroku quite a bit lately for easy deployment. Things such as DATABASE_URL and S3 credentials are managed through heroku config and show up in your production app as ENV['DATABASE_URL']. This is a great way to keep these configuration details out of your repository.

One downside to this approach is that it can be annoying to get these environment variables set in your local development version of the app. Enter rack-environment. This piece of Rack middleware lets you manage your development environment in a small YAML file that will get loaded in front of your app. Simple, yet effective.

Using rack-environment with Rails

# config/environments/development.rb
config.gem 'rack-environment'
config.middleware.use 'RackEnvironment'

# config/environment.yml
VARIABLE1: value1
VARIABLE2: value2

Using rack-environment with any Rack-based framework

# config.ru
  use RackEnvironment if ENV['RACK_ENV'] == 'development'
  run MyApplication.new