incubate!(bang) has officially started back up - check incubatebang.com for details

isotope|eleven


About_josh_adams

You should be using environment variables more often.

by: Josh Adams

February 6th, 2012 16:27

So in this post I'd like to talk about storing credentials or other environment-specific bits of data, while avoiding putting them in your repository. I'd like to set the stage first, so that you can relate. That in mind, here goes.

(tl;dr - use environment variables)

Context: The quote app.

We've got an app we're building at present we call "the quote app." It's what we use to build our quotes. It has item templates, so that over time we can perfect our quotes. In project post-mortems, we can review our quote, and if we see that "building a basic api wrapper" was estimated at 10-14 hours and it really took 25, then we can update our item template for that type of task and make stuff better.

Anyway, that's all good, but let's say the customer accepts the quote (they always do, because we're awesome). Now we need to move this data from our application into xrono, our project- and time-tracking system. Of course, we do this via the xrono API.

The problem presents itself.

So now we have to talk to an API, and this means using credentials, and specifying the host endpoint for the API. There are a few ways to go about this, but in general the problems are:

  • I can't store credentials in the repository, obviously.
  • I use a different endpoint in production than in development.

This is a common problem, and the solution is not in any way world-changing. However, way too few people do this correctly, including us frequently.

The answer is obvious.

These are bits of information that change depending on the environment you're in. Holy crap, there's a name for those! Environment variables. We are now storing any and all of these types of things in environment variables. I would propose that you do as well. That's the right place for this data.

One big benefit is that you don't store this stuff in your repository. You just make sure that the user that's running the app has those environment variables set. It's very clean, and it makes your life WAY less miserable than trying to pseudo-database.yml your way out of the problem. Because I know you're doing that.

Oh yeah, open source.

Also, I thought I'd mention that we're open sourcing the quote app as soon as we've got a few more things done on it. We've already got a fantastic feature-set in it, and it's unbelievably better than how we were managing quotes before. If you're interested in it, ping me and I might push to get it released a bit more quickly. Look for it soon! :)

View All Posts