为什么我的Heroku管道审阅应用程序无法构建并出现以下错误:ActiveSupport :: EncryptedFile :: MissingKeyError

时间:2019-07-18 17:10:56

标签: ruby-on-rails heroku ruby-on-rails-5 pipeline

我正在使用Heroku管道。我的登台应用程序是我的评论应用程序的父级应用程序,因此环境变量相同。

我的登台应用程序每次都在构建,那里没有问题。但是,我所有的评论应用都无法构建。问题似乎是评论应用程序缺少加密密钥。

我已经运行heroku config:set RAILS_MASTER_KEY=##### -a my-app-staging-pr-99来设置评论应用的主密钥,但是仍然遇到相同的构建错误。

注意: -我使用带有凭证的Rails 5.2.3 -我的 production.rb 中有config.read_encrypted_secrets = true -我在 credentials.yml

中设置了我的`secret_key_base

请参阅以下日志:

日志:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       ActiveSupport::EncryptedFile::MissingKeyError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:96:in `handle_missing_key'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:37:in `key'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:41:in `read'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:21:in `read'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:33:in `config'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:38:in `options'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/config/environments/production.rb:102:in `block in <main>'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb:216:in `instance_eval'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb:216:in `configure'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/config/environments/production.rb:1:in `<main>'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/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'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/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'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:602:in `block (2 levels) in <class:Engine>'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:601:in `each'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:601:in `block in <class:Engine>'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `each'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `tsort_each_child'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/config/environment.rb:5:in `<main>'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/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'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/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'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
       /tmp/build_0ef8f846f0fdc1456a3e91ed8dc095e6/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

app.json

{
  "scripts": {
    "postdeploy": "rails db:migrate"
  }
}

数周以来,我一直在尝试解决此问题,但一直无法解决。我是新手,如果我错过这里很明显的东西,我深表歉意。

1 个答案:

答案 0 :(得分:0)

  

一种方法是将RAILS_MASTER_KEY添加到以下环境变量   您的登台应用程序。然后在您的评论应用中,您可以从   登台应用程序。

通过执行生成密钥

rake secret

在您的项目目录中

您可以使用以下命令在登台应用程序上设置config变量

heroku config:set RAILS_MASTER_KEY=<KEY GENERATED BY rake secret> -a my-app-staging

现在在您的app.json中,您可以添加

"env": {
    "RAILS_MASTER_KEY": {
     "required": true
}

通过这种方式,每个新创建的评论应用都将从暂存应用中获取其RAILS_MASTER_KEY

希望有帮助。