0

我一直在使用 capistrano 3 部署 rails 4.1 应用程序。它运行良好。但是当我尝试执行 rake 任务时(取消注释需要'capistrano/rails/assets')。我得到这个错误

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:

  * development - set it to false
  * test - set it to false (unless you use a tool that preloads your test environment)
  * production - set it to true

rake aborted!
ArgumentError: Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:261:in `handle_settings'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:98:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/storage.rb:26:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:8:in `block in <top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:5:in `<top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'

config.eager_load 设置为 true。带有 google_storage_access_key_id 的东西,键在初始化器中初始化,值为 config.secrets.yml

require 'fog'
require 'rails'
require 'carrierwave'

CarrierWave.configure do |config|
  config.root = Rails.root.join('tmp')
  config.cache_dir = 'carrierwave'
  config.fog_credentials = {
    :provider                         => 'Google',
    :google_storage_access_key_id     => Rails.application.secrets.storage_access_key,
    :google_storage_secret_access_key => Rails.application.secrets.storage_access_secret
  }
  config.fog_directory = 'yelostore'

end

config.secrets.yml

  storage_access_key: <%= ENV['STORAGE_ACCESS_KEY']%>
  storage_access_secret: <%= ENV['STORAGE_ACCESS_SECRET']%>

我将环境变量存储在 /etc/profile 中。

只有当我执行一些 rake 或执行任务时才会出现问题。如果我删除了初始化程序文件,我会收到另一个错误 Devise.secret_key 未设置。请在您的设计初始化程序中添加以下内容:

config.secret_key = '6b88a299ed1361b5c0275e.....'

这本质上是因为 secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 那时没有被加载。

最后我可以运行我去根路径的所有任务。只有通过 capistarno 进行这些错误才会出现。由于 capistarno 没有获取存储在 /etc/profile 中的 config.scecrets 环境变量

4

2 回答 2

0

capistrano 似乎想从 /etc/environment 而不是 shell 中查看环境变量,因此 bashrc 或 profile 不起作用。

在我升级到 capistrano 3.0rc 到 3.2 后,config.eager_load 问题得到了解决

于 2014-09-10T14:44:40.637 回答
0

该错误与secret_key_base 无关。在 config/initializers/devise.rb 文件中,在 setup 块中添加 config.secret_key='6b88...':

Devise.setup do |config|
  config.secret_key = '6b88a299ed1361b5c0275e...'
  ...
end
于 2014-09-25T21:34:36.760 回答