Capistrano 投掷装置 secret_key 未设置

Capistrano throwing devise secret_key not set

我正在使用 Capist运行o 3.1.4,带有 capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/faster_assets'
require 'capistrano/rails/migrations'

我已经将我的 gems 设置为使用 figaro 和 devise。当我 ssh 到盒子时,运行(with .bash_profile export RAILS_ENV=production)

bundle install # works fine
bundle exec rake db:migrate # works fine

但是当我执行时:

cap production deploy:compile

我收到错误消息,指出未设置设计密钥,是因为服务器上的 bash -login 不是 运行 吗?

** Invoke deploy:compile_assets (first_time)
** Invoke deploy:set_rails_env 
** Execute deploy:compile_assets
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
DEBUG [05812cf9] Running /usr/bin/env if test ! -d /home/user1/rails/releases/20150507175646; then echo "Directory does not exist '/home/user1/rails/releases/20150507175646'" 1>&2; false; fi as user1@example.com
DEBUG [05812cf9] Command: if test ! -d /home/user1/rails/releases/20150507175646; then echo "Directory does not exist '/home/user1/rails/releases/20150507175646'" 1>&2; false; fi
DEBUG [05812cf9]    stdin: is not a tty
DEBUG [05812cf9] Finished in 0.458 seconds with exit status 0 (successful).
DEBUG [4713c277] Running /usr/bin/env ls -xr /home/user1/rails/releases as user1@example.com
DEBUG [4713c277] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/bin/env ls -xr /home/user1/rails/releases )
DEBUG [4713c277]    stdin: is not a tty
DEBUG [4713c277]    20150507175646  20150507175448  20150507173408  20150507171913  20150507162459
DEBUG [4713c277]    20150507161419  20150507155316  20150507153253  20150507151908  20150507150428
DEBUG [4713c277]    20150507145904  20150507142928  20150507104745  20150504061059  20150504051818
DEBUG [4713c277]    20150429060420  20150417025054
DEBUG [4713c277] Finished in 0.404 seconds with exit status 0 (successful).
INFO [f226806f] Running /usr/bin/env ls /home/user1/rails/releases/20150507175448/assets_manifest_backup as user1@example.com
DEBUG [f226806f] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/bin/env ls /home/user1/rails/releases/20150507175448/assets_manifest_backup )
DEBUG [f226806f]    stdin: is not a tty
DEBUG [f226806f]    ls: 
DEBUG [f226806f]    cannot access /home/user1/rails/releases/20150507175448/assets_manifest_backup
DEBUG [f226806f]    : No such file or directory
DEBUG [f226806f]    
INFO [07c227d5] Running /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile as user1@example.com
DEBUG [07c227d5] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [07c227d5]    stdin: is not a tty
DEBUG [07c227d5]    rake aborted!
DEBUG [07c227d5]    Devise.secret_key was not set. Please add the following to your Devise initializer:
DEBUG [07c227d5]    
DEBUG [07c227d5]      config.secret_key = '2b23a31ec3325533df50c4384f2b0d62fa8430c606adb7d24259cbdadd329e3d659a2c0dd2b42c19cc7761b836e9200ed413a3d0d1ab530369bf20198d9c39c7'
DEBUG [07c227d5]    
DEBUG [07c227d5]    Please ensure you restarted your application after installing Devise or setting the key.
DEBUG [07c227d5]    /home/user1/rails/shared/bundle/ruby/2.1.0/gems/devise-3.3.0/lib/devise/rails/routes.rb:483:in `raise_no_secret_key'
DEBUG [07c227d5]    /home/user1/rails/shared/bundle/ruby/2.1.0/gems/devise-3.3.0/lib/devise/rails/routes.rb:209:in `devise_for'
DEBUG [07c227d5]    /home/user1/rails/releases/20150507175646/config/routes.rb:91:in `block in <top (required)>'
DEBUG [07c227d5]    /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
DEBUG [07c227d5]    /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
DEBUG [07c227d5]    /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
DEBUG [07c227d5]    /home/user1/rails/releases/20150507175646/config/routes.rb:1:in `<top (required)>'
...

原来我的figaro任务没有在assets:precompile之前执行。我将我的活动更改为之前:更新以解决问题。这是 config/deploy.rb

中工作的 figaro 示例

cap production deploy --trace # 对调试很有用

更多关于 capistrano flow

namespace :figaro do
    desc "SCP transfer figaro configuration to the shared folder"
    task :setup do
        on roles(:app) do
            upload! "config/application.yml", "#{shared_path}/application.yml", via: :scp
        end
    end

    desc "Symlink application.yml to the release path"
    task :symlink do
        on roles(:app) do
            execute "ln -sf #{shared_path}/application.yml #{release_path}/config/application.yml"
        end
    end

end

namespace :deploy do
    before :updated, "figaro:setup"
    before :updated, "figaro:symlink"
end