I have an app on Rails 5.2 and it was previously hosted on DigitalOcean, but I need to host it on heroku. I’ve been reading that heroku can’t read Credentials.yml of because it’s on gitignore and of course I don’t want it public.
So my key variables are like this (and example with redis):
host: Rails.application.credentials.redis_host,
password: Rails.application.credentials.redis_password
Heroku can’t read this. So my question is what is the best approach to change that in to heroku ENV variables? Do I need to edit all my current keys (there about 340) to ENV[‘SOMEKEY’]?
I’ll appreciate you help!
2
Answers
Create credentials.yml and master key:
Edit credentails:
WORKING WITH VIM:
EXAMPLE OF HOW CREDENTIALS.YML can look:
FIND A CREDENTIAL:
or if an env variable is used
The credentials.yml file should NOT be in gitignore.
The master key that decrypts the credentials SHOULD be in gitignore.
To set your master key in production:
or
That’s all you need to know about credentials in Ruby on Rails. Good luck 🙂
Update: I’ve created a screencast covering the topic 🙂
Rails 6 introduced built-in support for multiple environment credentials
It can be very convenient to keep different secrets for different environments
To create credentials for production environment, we can run the following command
The above command does the following:
creates
config/credentials/production.key
if missing (don’t commit this file, add to.gitignore
if such record is absent)creates
config/credentials/production.yml.enc
if missing (cmmit this file)decrypts and opens the production credentials file in vim (you can specify other editor)
And finally we can use these secrets on Heroku