Rails 3.1和Asset Pipeline:使用Capistrano进行部署时出现问题

时间:2011-09-25 23:04:06

标签: ruby-on-rails ruby-on-rails-3 deployment capistrano asset-pipeline

我刚刚从Ruby on Rails 3.0.10切换到3.1.0并且我想使用Capistrano宝石部署我的资产文件(我的本地机器是运行Snow Leopard的MacO,我的远程机器正在运行Ubuntu 10.04 Lucid )。所以,正如Official Guide中所写,我在load 'deploy/assets' Capfile中取消注释:

# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'

现在,当我运行cap deploy命令时,我收到以下错误(错误在底部解释):

...

  * executing "cd /<application_absolute_path>/releases/20110925223032 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["<my_web_site_ip>"]
    [<my_web_site_ip>] executing command
 ** [out :: <my_web_site_ip>] (in /<application_absolute_path>/releases/20110925223032)
*** [err :: <my_web_site_ip>] rake aborted!
*** [err :: <my_web_site_ip>] uninitialized constant Rake::DSL
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:6:in `<module:Rake>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:3:in `<top (required)>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/testtask.rb:4:in `require'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/testtask.rb:4:in `<top (required)>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/testing.rake:2:in `require'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/testing.rake:2:in `<top (required)>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/railtie.rb:12:in `load'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/railtie.rb:12:in `block in <class:TestUnitRailtie>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `call'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `block in load_tasks'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `each'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `load_tasks'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:395:in `block in load_tasks'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application/railties.rb:8:in `each'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application/railties.rb:8:in `all'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:395:in `load_tasks'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:99:in `load_tasks'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
*** [err :: <my_web_site_ip>] /<application_absolute_path>/releases/20110925223032/Rakefile:7:in `<top (required)>'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:2373:in `load'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
*** [err :: ] /usr/local/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/rake.rb:1991:in `run'
*** [err :: <my_web_site_ip>] /usr/local/bin/rake:31:in `<main>'
    command finished in 4301ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /<application_absolute_path>/releases/20110925223032; true"
    servers: ["<my_web_site_ip>"]
    [<my_web_site_ip>] executing command
    command finished in 377ms
failed: "sh -c 'cd /<application_absolute_path>/releases/20110925223032 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on <my_web_site_ip>

所以,我尝试在this question的答案后解决问题:

# Rakefile
require 'rake/dsl_definition'

require File.expand_path('../config/application', __FILE__)

<MyApplicationName>::Application.load_tasks

再次运行cap deploy命令后,我收到以下错误:

...

  * executing "cd /<application_absolute_path>/releases/20110925160036 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["<my_web_site_ip>"]
    [<my_web_site_ip>] executing command
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
 ** [out :: <my_web_site_ip>] (in /<application_absolute_path>/releases/20110925160036)
*** [err :: <my_web_site_ip>] WARNING: Global access to Rake DSL methods is deprecated.  Please include
*** [err :: <my_web_site_ip>] ...  Rake::DSL into classes and modules which use the Rake DSL methods.
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'
*** [err :: <my_web_site_ip>] WARNING: Global access to Rake DSL methods is deprecated.  Please include
*** [err :: <my_web_site_ip>] ...  Rake::DSL into classes and modules which use the Rake DSL methods.
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'

...
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'
...
*** [err :: <my_web_site_ip>] WARNING: DSL method Object#mkdir_p called at /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `mkdir_p'
...

*** [err :: <my_web_site_ip>] rake aborted!
*** [err :: <my_web_site_ip>] stack level too deep
*** [err :: <my_web_site_ip>] /usr/local/lib/ruby/1.9.1/ostruct.rb:92
    command finished in 48421ms

与Capistrano相关的代码错在哪里?如何正确使用load 'deploy/assets'语句以使部署过程正常工作?

1 个答案:

答案 0 :(得分:3)

您是否尝试过定义自己的任务?这就是我所做的when I ran into this issue

task :precompile, :role => :app do  
  run "cd #{release_path}/ && rake assets:precompile"  
end  
after "deploy:finalize_update", "deploy:precompile"

如果您使用RVM

,则需要RVM initialization