capistrano 3 + rvm1-capistrano3 rails 4.1 secrets.yml环境变量问题

时间:2014-09-10 13:38:38

标签: ruby-on-rails rvm capistrano capistrano3 rvm-capistrano

我一直在使用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中。

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

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

这是必要的,因为secret_key_base:&lt;%= ENV [“SECRET_KEY_BASE”]%&gt;那时候没有加载。

最后,我可以运行所有任务,然后转到根路径。只有在通过capistarno这样做时才会出现这些错误。因为capistarno没有得到存储在/ etc / profile

中的config.scecrets env变量

2 个答案:

答案 0 :(得分:0)

capistrano似乎是从/ etc / environment而不是shell查看环境变量,因此bashrc或profile无法正常工作。

在我升级到capistrano 3.0rc到3.2

之后,config.eager_load问题得以解决

答案 1 :(得分:0)

错误与secret_key_base无关。 在文件config / initializers / devise.rb中添加config.secret_key =&#39; 6b88 ...&#39;在设置块中:

Devise.setup do |config|
  config.secret_key = '6b88a299ed1361b5c0275e...'
  ...
end