Heroku部署错误;预编译资产失败(注意design.rb中的行)



我在本地机器上有一个运行中的应用程序,实现了google_oauth2和github-oauth。但是,当我将master推送到Heroku时,它被拒绝了,并出现一个错误,说明资产的预编译失败(并表明design.rb有问题(。因此,我在本地运行了生产环境的预编译,并在没有错误的情况下完成了。所以我在Heroku上运行了预编译,收到了一个错误。我被难住了。

以下是日志的相关部分,显示主推送至Heroku被拒绝:

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'

以下是当我尝试在Heroku上预编译资产时(在本地成功预编译后(日志的相关部分(带跟踪(:

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>'

就在昨天,我让omniauth为google_oauth2和github signin工作。这一切似乎都在我的本地机器上工作重要的是,当我在design.rb中注释出以下行时,我能够成功地推送到Heroku(但我不知道这些行是怎么导致资产无法在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), {}

编辑:我刚刚发现是第二行(:google_oauth2行(导致了问题。评论结束后,对Heroku的推动是成功的。

我不认为在检索客户端id和机密时有任何错误——我在rails控制台中测试了这些语句,它们返回了正确的值。

任何帮助都将不胜感激。

我未能在Heroku环境变量设置中设置主密钥。

最新更新