Reputation: 684
I have what appears to be a working application on my local machine with google_oauth2 and github oauth implemented. But when I push the master to Heroku it is rejected with an error stating that precompiling of assets failed (and indicating a problem with devise.rb). So, I ran precompile of my production environment locally and that completed without error. So then I ran precompile on Heroku and received an error. I am stumped.
Here are relevant portions of the log showing the push of master to Heroku rejected:
remote: Bundle completed (1.76s)
remote: Cleaning up the bundler cache.
remote: -----> Installing node-v12.16.2-linux-x64
remote: -----> Installing yarn-v1.22.4
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
...
remote: rake aborted!
remote: NoMethodError: undefined method `[]' for nil:NilClass
remote: /tmp/build_ae858012/config/initializers/devise.rb:276:in `block in <main>'
remote: /tmp/build_ae858012/vendor/bundle/ruby/2.7.0/gems/devise-4.7.2/lib/devise.rb:307:in `setup'
remote: /tmp/build_ae858012/config/initializers/devise.rb:11:in `<main>'
...
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to aristutor.
remote:
To https://git.heroku.com/aristutor.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/aristutor.git'
Here are relevant portions of the log (with trace) when I tried to precompile assets on Heroku (after successfully precompiling locally):
Everything's up-to-date. Nothing to do
rabs-MacBook-Pro-2:lms rab$ heroku run RAILS_ENV=production rake assets:precompile --trace
Running RAILS_ENV=production rake assets:precompile --trace on ⬢ aristutor... up, run.1642 (Free)
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke yarn:install (first_time)
** Invoke webpacker:yarn_install (first_time)
** Execute webpacker:yarn_install
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
...
remote: Bundle complete! 39 Gemfile dependencies, 99 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into `./vendor/bundle`
remote: Removing bundler (2.0.2)
remote: Bundle completed (1.76s)
remote: Cleaning up the bundler cache.
remote: -----> Installing node-v12.16.2-linux-x64
remote: -----> Installing yarn-v1.22.4
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: rake aborted!
remote: NoMethodError: undefined method `[]' for nil:NilClass
remote: /tmp/build_ae858012/config/initializers/devise.rb:276:in `block in <main>'
remote: /tmp/build_ae858012/vendor/bundle/ruby/2.7.0/gems/devise-4.7.2/lib/devise.rb:307:in `setup'
remote: /tmp/build_ae858012/config/initializers/devise.rb:11:in `<main>'
I just yesterday got the omniauth working for google_oauth2 and github signin. It all appears to be working on my local machine. Importantly, I was able to successfully push to Heroku when I commented out the following lines in devise.rb (but I don't know what about those lines is causing the assets to fail to precompile on Heroku):
config.omniauth :github, Rails.application.credentials[:github][Rails.env.to_sym][:client_id], Rails.application.credentials[:github][Rails.env.to_sym][:client_secret], scope: 'user,public_repo'
config.omniauth :google_oauth2, Rails.application.credentials.dig(:google_oauth2, :client_id), Rails.application.credentials.dig(:google_oauth2, :client_secret), {}
Edit: I just discovered it is the second line (the :google_oauth2 line) that is causing the problem. With it commented out, the push to Heroku is successful.
I don't believe there is any error in retrieving the client id's and secrets - I tested those statements in the rails console and they returned the correct values.
Any help will be appreciated.
Upvotes: 1
Views: 337
Reputation: 684
I had failed to set the master key in Heroku environment variable settings.
Upvotes: 1