We've moved discussions to Discord

Deployment to Heroku failing with Redis issue

Ruben Portz
I've followed all instruction and got it working super fine locally. But when deploying to Heroku something's off. I did add the psql and redis add-ons, but that isn't doing it. Any trouble-shooting suggestions welcome.

2019-07-25T20:17:18.394877+00:00 heroku[web.1]: Starting process with command `bundle exec rails s`
2019-07-25T20:17:20.208121+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-25T20:17:20.143748+00:00 app[web.1]: bash: bundle: command not found
2019-07-25T20:17:20.191090+00:00 heroku[web.1]: Process exited with status 127
2019-07-25T20:17:25.305717+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stormy-harbor-54816.herokuapp.com request_id=ddb18d29-6668-4fe1-8690-251434eae23a fwd="2.219.90.101" dyno= connect= service= status=503 bytes= protocol=https
2019-07-25T20:17:27.402188+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=stormy-harbor-54816.herokuapp.com request_id=c1bb62f8-c4e5-4ab7-b76e-d438fc57417c fwd="2.219.90.101" dyno= connect= service= status=503 bytes= protocol=https
2019-07-25T20:19:11+00:00 app[heroku-redis]: source=HEROKU_REDIS_YELLOW addon=redis-curved-98773 sample#active-connections=1 sample#load-avg-1m=0.075 sample#load-avg-5m=0.06 sample#load-avg-15m=0.045 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664220kB sample#memory-free=14138868kB sample#memory-cached=415612kB sample#memory-redis=308864bytes sample#hit-rate=1 sample#evicted-keys=0
Chris Oliver
Hmm, "bash: bundle: command not found"

Maybe you need to change the Procfile to just do "rails s". 

I would expect Heroku to have bundler in the path though...
Ruben Portz
Okay, let me try. Just got another error regarding class:ConnectedAccount

2019-07-25T21:19:08.432671+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-25T21:19:08.432675+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-25T21:19:08.432678+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'
Chris Oliver
That error sounds like you're missing an access token encryption key in your production credentials.

Comes from "Rails.application.credentials.access_token_encryption_key"
Ruben Portz
I see, thanks, Chris. Actually just ran heroku db:migrate that got rid off it, but put me back into an issue with Redis that I seem to be getting back at again and again:

2019-07-25T21:24:33.808881+00:00 heroku[run.5829]: Awaiting client
2019-07-25T21:24:34.079544+00:00 heroku[run.5829]: State changed from starting to up
2019-07-25T21:24:33.830271+00:00 heroku[run.5829]: Starting process with command `bundle exec rake db:migrate`
2019-07-25T21:24:45.527931+00:00 heroku[run.5829]: State changed from up to complete
2019-07-25T21:24:45.513585+00:00 heroku[run.5829]: Process exited with status 0
2019-07-25T21:24:58.686177+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stormy-harbor-54816.herokuapp.com request_id=50dd7df0-9e33-405a-8e2e-ad28df177d74 fwd="2.219.90.101" dyno= connect= service= status=503 bytes= protocol=https
2019-07-25T21:25:00.684224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=stormy-harbor-54816.herokuapp.com request_id=708de59e-e5b9-4f10-8960-917b53e93932 fwd="2.219.90.101" dyno= connect= service= status=503 bytes= protocol=https
2019-07-25T21:25:03+00:00 app[heroku-redis]: source=HEROKU_REDIS_YELLOW addon=redis-curved-98773 sample#active-connections=1 sample#load-avg-1m=0.07 sample#load-avg-5m=0.085 sample#load-avg-15m=0.065 sample#read-iops=0 sample#write-iops=0.066667 sample#memory-total=15664220kB sample#memory-free=14090700kB sample#memory-cached=421856kB sample#memory-redis=308864bytes sample#hit-rate=1 sample#evicted-keys=0

Chris Oliver
I don't see any error in these logs, aside from the same H10 as before. 
Ruben Portz
Okay, where and what can I do with "Rails.application.credentials.access_token_encryption_key"

Is this in the tutorial video or documentation by any chance and I missed it? Sorry to be such a pain in the ass.
Chris Oliver
It should be in config/credentials/production.yml.enc automatically when you create your production credentials.

rails credentials:edit --environment=production
Ruben Portz
The error seems to happen if I call Base64.decode64(nil). The method, however, is strictly expecting a String object here.
Seems like I'm calling the method with some variable that is usually supposed to be a String but is currently nil for some reason.
But the "Rails.application.credentials.access_token_encryption_key" in connected_account.rb is set automatically in both production.yml and development.yml

2019-07-26T06:53:18.797137+00:00 app[web.1]: Exiting
2019-07-26T06:53:18.797439+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-26T06:53:18.797443+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-26T06:53:18.797445+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'

Any suggestion on what variable might be missing?

Further details:
- I don't use any of the login providers via OmniAuth
- I only changed Stripe and added the public and private keys to dev and production.yml
- Redis and Postgresql set in Heroku
- Bundler, Imagemagick, Yarn and Foreman installed
- heroku-buildpack-activestorage-preview is added
- using ruby '2.6.3' and rails  '~> 6.0.0.rc1'
- working fine in local environment

Full trace:
2019-07-26T06:52:15+00:00 app[heroku-redis]: source=HEROKU_REDIS_YELLOW addon=redis-curved-98773 sample#active-connections=1 sample#load-avg-1m=0.155 sample#load-avg-5m=0.15 sample#load-avg-15m=0.14 sample#read-iops=0 sample#write-iops=0.16393 sample#memory-total=15664220kB sample#memory-free=13269280kB sample#memory-cached=541384kB sample#memory-redis=308864bytes sample#hit-rate=1 sample#evicted-keys=0
2019-07-26T06:53:03.426734+00:00 heroku[web.1]: State changed from crashed to starting
2019-07-26T06:53:10.898224+00:00 heroku[web.1]: Starting process with command `bundle exec rails s`
2019-07-26T06:53:17.657593+00:00 app[web.1]: => Booting Puma
2019-07-26T06:53:17.657621+00:00 app[web.1]: => Rails 6.0.0.rc2 application starting in production
2019-07-26T06:53:17.657623+00:00 app[web.1]: => Run `rails server --help` for more startup options
2019-07-26T06:53:18.797137+00:00 app[web.1]: Exiting
2019-07-26T06:53:18.797439+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-26T06:53:18.797443+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-26T06:53:18.797445+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'
2019-07-26T06:53:18.797449+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-26T06:53:18.797451+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-26T06:53:18.797454+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-26T06:53:18.797474+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-26T06:53:18.797476+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-26T06:53:18.797480+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/kernel.rb:16:in `require'
2019-07-26T06:53:18.797483+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:351:in `const_get'
2019-07-26T06:53:18.797501+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:351:in `block (2 levels) in eager_load'
2019-07-26T06:53:18.797503+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:662:in `block in ls'
2019-07-26T06:53:18.797507+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:659:in `foreach'
2019-07-26T06:53:18.797509+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:659:in `ls'
2019-07-26T06:53:18.797512+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:346:in `block in eager_load'
2019-07-26T06:53:18.797514+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:338:in `synchronize'
2019-07-26T06:53:18.797517+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:338:in `eager_load'
2019-07-26T06:53:18.797520+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:449:in `each'
2019-07-26T06:53:18.797524+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:449:in `eager_load_all'
2019-07-26T06:53:18.797527+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
2019-07-26T06:53:18.797530+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/initializable.rb:32:in `instance_exec'
2019-07-26T06:53:18.797532+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/initializable.rb:32:in `run'
2019-07-26T06:53:18.797535+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/initializable.rb:61:in `block in run_initializers'
2019-07-26T06:53:18.797538+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
2019-07-26T06:53:18.797547+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
2019-07-26T06:53:18.797548+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
2019-07-26T06:53:18.797551+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
2019-07-26T06:53:18.797553+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
2019-07-26T06:53:18.797556+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
2019-07-26T06:53:18.797558+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
2019-07-26T06:53:18.797560+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
2019-07-26T06:53:18.797566+00:00 app[web.1]: from /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
2019-07-26T06:53:18.797569+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/initializable.rb:60:in `run_initializers'
2019-07-26T06:53:18.797571+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application.rb:363:in `initialize!'
2019-07-26T06:53:18.797573+00:00 app[web.1]: from /app/config/environment.rb:5:in `<main>'
2019-07-26T06:53:18.797576+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-26T06:53:18.797577+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-26T06:53:18.797580+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-26T06:53:18.797582+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-26T06:53:18.797585+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-26T06:53:18.797586+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/kernel.rb:23:in `require'
2019-07-26T06:53:18.797589+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:322:in `block in require'
2019-07-26T06:53:18.797592+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:288:in `load_dependency'
2019-07-26T06:53:18.797595+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:322:in `require'
2019-07-26T06:53:18.797598+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `require_relative'
2019-07-26T06:53:18.797601+00:00 app[web.1]: from config.ru:3:in `block in <main>'
2019-07-26T06:53:18.797604+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
2019-07-26T06:53:18.797606+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
2019-07-26T06:53:18.797609+00:00 app[web.1]: from config.ru:in `new'
2019-07-26T06:53:18.797612+00:00 app[web.1]: from config.ru:in `<main>'
2019-07-26T06:53:18.797615+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval'
2019-07-26T06:53:18.797617+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string'
2019-07-26T06:53:18.797620+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file'
2019-07-26T06:53:18.797623+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config'
2019-07-26T06:53:18.797625+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:219:in `app'
2019-07-26T06:53:18.797628+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app'
2019-07-26T06:53:18.797631+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/server.rb:283:in `start'
2019-07-26T06:53:18.797650+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/commands/server/server_command.rb:39:in `start'
2019-07-26T06:53:18.797652+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/commands/server/server_command.rb:147:in `block in perform'
2019-07-26T06:53:18.797655+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/commands/server/server_command.rb:138:in `tap'
2019-07-26T06:53:18.797658+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/commands/server/server_command.rb:138:in `perform'
2019-07-26T06:53:18.797662+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
2019-07-26T06:53:18.797681+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
2019-07-26T06:53:18.797682+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
2019-07-26T06:53:18.797685+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/command/base.rb:65:in `perform'
2019-07-26T06:53:18.797687+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/command.rb:46:in `invoke'
2019-07-26T06:53:18.797690+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.0.rc2/lib/rails/commands.rb:18:in `<main>'
2019-07-26T06:53:18.797693+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-26T06:53:18.797696+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-26T06:53:18.797699+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-26T06:53:18.797702+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-26T06:53:18.797705+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-26T06:53:18.797707+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:322:in `block in require'
2019-07-26T06:53:18.797709+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:288:in `load_dependency'
2019-07-26T06:53:18.797712+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/dependencies.rb:322:in `require'
2019-07-26T06:53:18.797715+00:00 app[web.1]: from bin/rails:9:in `<main>'
2019-07-26T06:53:18.883599+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-26T06:53:18.864634+00:00 heroku[web.1]: Process exited with status 1
Ruben Portz
My intuition says a different yml file or environment variable needs to be set with Heroku. Has anyone deployed with Heroku and can confirm this?
Chris Oliver
Have you created and committed the config/credentials/production.yml.enc to git, deployed that code, and then added the production.key file as RAILS_MASTER_KEY in your Heroku ENV vars?
Ruben Portz
That sorted it out!

heroku config:set RAILS_MASTER_KEY=<your-master-key>
Notifications
You’re not receiving notifications from this thread.