2

I am trying to find the best solution for storing secret keys (specifically S3 and devise keys are the ones i'm trying to set up) which will enable my app to run both locally and on Heroku. My research so far (almost a whole day on this :( ) shows me a number of options, however i've had issues with each, which i outline below:

  • Option 1) Using the .gitignored rails 4.1 provided secrets.yml file is lovely in development, you simply use Rails.application.secrets._secret_ in the s3 credentials in your model and all is fine. But when pushing to Heroku you need to heroku config:set key=value for each variable, which in itself is fine but then you need to replace the Rails.application.secrets... syntax with ENV['key'] and this renders the rails intended secrets.yml and the corresponding nice syntax unusable. The only way i can see this working is with ENV's set both locally and on heroku, a bit tedious and it wouldn't be utilising the rails intended secrets.yml file.

  • Option 2) Using the gem 'figaro' is all well and good, so the gem sets up an application.yml file for you and .gitignores it for you and provides a handy rake command to bulk create Heroku ENV's. But i cannot see how you are meant to use the same app version for both local development and heroku production environments without again having to set ENV's on each environment. Ok, figaro makes setting ENV's quicker on heroku through its rake command, but it still renders secrets.yml useless and involves setting of ENV's for every key in each environment.

  • Option 3) I found another gem; gem 'heroku_secrets', github: 'alexpeattie/heroku_secrets' which is designed to make our lives easier. This gem, akin with figaro, provides a rake commend to bulk set Heroku ENVs. But i guess it still leaves us with the same issue of ENV's set everywhere. However, i couldn't even get this far with this gem, when attempting to use it I ran into this error message;

    git://github.com/alexpeattie/heroku_secrets.git (at master) is not yet checked out. Run bundle install first.

Neither bundle nor bundle install do anything here and searching on the issue has me trying bundle install --deployment which rather than identifying and solving the problem, it provides a workaround solution through placing all of my gems in the vendor directory, not how id like thing set up, so i scrapped that change.

  • Other Options) dotenv-not tried, foreman-not tried, pre loading a file containing vars before rails.initialize, tried but didn't like.

After all of today searching, playing, trying to implement and re-implement variations of the above and more I am still at a loss as to how to get this app to run on both heroku and local dev environments in a decent way. I would of course like to achieve this whilst using the secrets.yml rails intended set up with without too much customisation, but i will do what i need to do to get this working. I am very much a junior at this developer thing so it is taking me longer than most to get my head around things, but this has really stumped me and has my head firmly in my hands asking for some help, please show me the light oh programming genii.

Here are some of the other links that i found, read and with some tried to implement if of any help with this subject:

Heroku's config man pages: https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application

A closely related question; How do you manage secret keys and heroku with Ruby on Rails 4.1.0beta1?

Article on various solutions; http://www.gotealeaf.com/blog/managing-environment-configuration-variables-in-rails

Another article on various solutions; http://tammersaleh.com/posts/managing-heroku-environment-variables-for-local-development/

Bundle 'not checked out' error; is not checked out... bundle install does NOT fix help!

Yet despite all of this discussion I can't seem to find a way to get this to work in both development local and heroku production environments without manually setting ENVs. Is there a way and if so would you please enlighten me.

Community
  • 1
  • 1
jbk
  • 1,911
  • 19
  • 36

0 Answers0