Envforcer: a Ruby gem that enforces environment variable requirements in Rails applications.

by Courtney Fanning
February 16, 2016

While working on a recent project together, my coworker Adam and I managed a complex application that had numerous environment variable requirements. Deploying and running the app without the proper configuration resulted in unpredictable, if not dangerous, results.

As features were added that required new environment variables, it became increasingly difficult to make sure our numerous staging and QA servers were kept up to date.

After a particularly rough deploy, we asked ourselves: What if we could prevent our application from booting if the proper configuration variables weren’t set on the target server? Enter Envforcer.

Envforcer is a Ruby gem that enforces environment variable requirements in Rails applications. By checking that the proper configuration is set during application initialization, app boot is blocked if a required value has not been set.

Adding Envforcer to your project couldn’t be easier. Simply add an .envforcer.yml file to the root directory with the required keys, like so:

```
- STRIPE_KEY
- AWS_PUBLIC_KEY
- AWS_SECRET

```

When deploying to Heroku, Envforcer will execute when the app is initialized for asset precompilation, rejecting the push if one of the required keys has not been set.

An added benefit we’ve seen from this approach is that it eliminates the need for an often out-of-date .env.sample file, instead directly informing developers of any missing configuration values when they try and boot their local development environment, thus streamlining the onboarding process for new team members.

Note: If you aren’t having Heroku compile your assets, the push will succeed, but your app will fail to boot.

 

Jobs at MojoTech

Colorado startup guides

LOCAL GUIDE
Best Companies to Work for in Denver & Boulder
LOCAL GUIDE
Coolest Tech Offices in Denver & Colorado Tech
LOCAL GUIDE
Best Perks at Colorado Tech Companies
LOCAL GUIDE
Women in Colorado Tech