New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access environment variables from config/database.yml in Rails app #32

Closed
repent opened this Issue Aug 19, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@repent
Copy link

repent commented Aug 19, 2016

I am having much the same problem described in this Stack question: Rails 4.2 database.yml not reading rbenv-vars variables

rbenv vars yields my SECRET_KEY_BASE as expected and I can access it from the rails console, but not from within database.yml.

I realise this may be a problem with the order in which Rails sets up its environment rather than a bug in rbenv-vars, but it would still be super-helpful if rbenv-vars could provide help on how to configure a Rails app so that they work together.

I'm using Rails 4.2.6 and Ruby 2.3.1.

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Aug 19, 2016

Generally, database.yml should have access to environment variables. But, for the sake of clear communication, let's first remember that database.yml doesn't evaluate itself; rather, the process that starts Rails loads database.yml and evaluates variables within it. So, my question for you is, who/what starts that process and how?

How are you starting your Rails app and determining that database.yml is broken? Are you using rails server, or bundle exec, or unicorn, or something else? For the command that you're using, can you run which -a <command> and tell me the result? Are you using any other rbenv plugins? Thanks

@repent

This comment has been minimized.

Copy link

repent commented Aug 19, 2016

Thanks a lot for the quick response. My app is being run by Passenger/Apache, which is started as a Debian service. Does that mean that rbenv is not a viable tool for this purpose?

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Aug 19, 2016

No, that's just means that you have to teach Passenger to start your Rails app through rbenv, so rbenv plugins such as this one can have effect, and so that the correct local version of Ruby can be used:

PassengerDefaultRuby /home/repent/.rbenv/shims/ruby

If your RBENV_ROOT is custom or something other than $HOME/.rbenv of the user that the Passenger process runs at, then it needs to be reflected in the line above, and RBENV_ROOT also needs to be configured within Apache config file too (somehow).

@repent

This comment has been minimized.

Copy link

repent commented Aug 19, 2016

Thanks! I had PassengerRuby set to /home/repent/.rbenv/versions/2.3.1/bin/ruby within the Apache config for that particular app. I can't remember where I took that from. Anyway, switching to /home/repent/.rbenv/shims/ruby has fixed the problem. I will post this info on that StackOverflow question.

@repent repent closed this Aug 19, 2016

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Aug 20, 2016

Glad you solved it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment