0

I just recently worked with an api and with security in mind, have it placed in the bin/rails secrets file. I have it listed below like

development:
  google_api_key: abcd1234
production:
  google_api_key: abcd1234

However when I push everything to heroku, I get application errors. When I look at the logs I see.

2020-08-04T22:34:28.529917+00:00 app[web.1]: /app/config/environment.rb:5:in `<top (required)>'
2020-08-04T22:34:28.529918+00:00 app[web.1]: config.ru:3:in `require_relative'
2020-08-04T22:34:28.529918+00:00 app[web.1]: config.ru:3:in `block in <main>'
2020-08-04T22:34:29.113486+00:00 heroku[web.1]: Process exited with status 1
2020-08-04T22:34:29.152963+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-04T22:34:29.605524+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=downtown-inventory-app.herokuapp.com request_id=1a1f61ec-458d-46c7-ada0-38ff05280586 fwd="107.77.206.194" dyno= connect= service= status=503 bytes= protocol=https
2020-08-04T22:34:30.628910+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=downtown-inventory-app.herokuapp.com request_id=d65ed41c-368e-451b-b70f-480b160e4c45 fwd="107.77.206.194" dyno= connect= service= status=503 bytes= protocol=https
2020-08-04T22:37:15.442465+00:00 app[api]: Set RAILS_MASTER_KEY config vars by user email@gmail.com
2020-08-04T22:37:15.442465+00:00 app[api]: Release v77 created by user email@gmail.com
2020-08-04T22:37:15.616389+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-04T22:37:20.612387+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2020-08-04T22:37:22.765114+00:00 app[web.1]: Puma starting in single mode...
2020-08-04T22:37:22.765140+00:00 app[web.1]: * Version 3.12.6 (ruby 2.5.8-p224), codename: Llamas in Pajamas
2020-08-04T22:37:22.765143+00:00 app[web.1]: * Min threads: 5, max threads: 5
2020-08-04T22:37:22.765147+00:00 app[web.1]: * Environment: production
2020-08-04T22:37:26.041214+00:00 app[web.1]: ! Unable to load application: ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
2020-08-04T22:37:26.041370+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.5.0/bin/puma)
2020-08-04T22:37:26.041449+00:00 app[web.1]: ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
2020-08-04T22:37:26.041494+00:00 app[web.1]: /app/config/environment.rb:5:in `<top (required)>'

I feel like the most important errors in the logs are

Unable to load application: ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage

and

ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage

I also see /app/config/environment.rb:5 in the logs which is

# Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!

I'm (praying) that someone else would have any ideas on what I can do here? I'm pretty new at working with deploying applications to heroku and so i'm not super sure what to do here.

kdweber89
  • 1,984
  • 2
  • 19
  • 29

1 Answers1

1

You have to set these keys on heroku:

heroku config:set GITHUB_USERNAME=joesmith

In this case GITHUB_USERNAME ist the set variable and you have to use that in your code so heroku knows what it should insert.

heroku docs: "Configuration and Config Vars"

ruby guides: "How To Use Environment Variables in Ruby"


I also found this guide:

arkency blog: "How to safely store API keys in Rails apps"

Sebi
  • 398
  • 3
  • 10