capistrano 3 + rvm1-capistrano3 rails 4.1 secrets.yml environmental variables issue

徘徊边缘 提交于 2019-12-25 05:13:36

问题


I have been deploying rails 4.1 application with capistrano 3. it has been working fine. but when i tried to do rake tasks (uncommenting require 'capistrano/rails/assets'). i get this error

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'

the config.eager_load is set to true. the thing with google_storage_access_key_id the keys are initialized inside a initializer with values 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']%>

i stored my environmental variables in /etc/profile.

there issues arise only if i do some rake or execute tasks. if i removed the initializer file i get another error Devise.secret_key was not set. Please add the following to your Devise initializer:

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

this is essentiall because of secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> not getting loaded at that point.

Finally i can run all tasks i go to the root path. only while doing it through capistarno these errors arise. as capistarno not getting the config.scecrets env variables which is stored in /etc/profile


回答1:


capistrano seems like to look into environmental variables from /etc/environment rather than shell so bashrc or profile didnt't work.

The config.eager_load issue was solved after i upgraded to capistrano 3.0rc to 3.2




回答2:


The Error has nothing to do with the secret_key_base. In the file config/initializers/devise.rb add the config.secret_key='6b88...' within the setup block:

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


来源:https://stackoverflow.com/questions/25766976/capistrano-3-rvm1-capistrano3-rails-4-1-secrets-yml-environmental-variables-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!