4
votes

I received the error "An unhandled lowlevel error occurred" when deploying my app for the first time on Heroku, and heroku logs shows:

Missing secret_key_base for 'production' environment, set this value in config/secrets.yml

1) The default secrets.yml specifies secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> for production

2) I generated a secret using rails secret, then added this to my app's Heroku config via heroku config:set SECRET_KEY_BASE='(the key)'

3) heroku config shows this value set for SECRET_KEY_BASE

4) Perhaps most importantly, based on older questions regarding this error, .gitignore does not include secrets.yml--it's the default .gitignore generated for a Rails 5 app. Therefore, secrets.yml should have been deployed with my app, which specifies that the secret be loaded via an environment variable in the production environment.

5) I've also run heroku ps:restart, in case the app needed some extra help for the environment variable setting to take effect

I read older posts, but the past answer seemed to be ensuring secrets.yml was not included in .gitignore, but as mentioned, this does not apply to the default Rails 5 .gitignore.

What else can I try? Thx.

Edit: When I set the config value at the command line, I also receive the Heroku message:

Setting SECRET_KEY_BASE and restarting (the app)... done

1
check the accepted solution on this postuser6427415
@jeramaedybohol Thanks, that was one of the sources I consulted, and it specifies setting an environment variable to the secret key value. On Heroku this is done as follows: devcenter.heroku.com/articles/config-vars. I had done that, and heroku config shows that this variable is set. I've also used the Web UI, clicked 'Reveal Config Vars' under 'Config Variables' and see it listed there. Anything else I should try? I also tried setting RAILS_ENV to production prior to generating the key a second time, and updating the Heroku config with this new value (and again verifying).SexxLuthor

1 Answers

2
votes

Okay, I see what happened. Running heroku run bash and checking which files were deployed has been enlightening.

It is true that secrets.yml was not in the .gitignore file for my local repo, but it seems that someone--possibly malicious hackers, possibly gremlins--had added secrets.yml to my global .gitignore (.gitignore_global), and so this file was in fact not being pushed to Heroku.

I've removed the secrets file from my global .gitignore, offloaded the dev and test environment secret keys to dotenv for management, and can run my deployed app successfully.

I thought about deleting the question, but will leave it in case others run into this problem, or even a similar one where using heroku run bash may be helpful when diagnosing issues with apps on Heroku.