开发者

Rails 3.1 and Asset Pipeline: Trouble on deploying with Capistrano

I just switched from Ruby on Rails 3.0.10 to 3.1.0 and I would like to deploy my asset files by using the Capistrano gem (my local machine is a MacOs running Snow Leopard, my remote machine is running Ubuntu 10.04 Lucid). So, as wrote in the Official Guide, I uncomment the load 'deploy/assets' in my Capfile like this:

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

Now, when I run the cap deploy command I get the following error (the error is explained at the bottom):

...

  * 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>

So, I tried to solve the problem following the answer to this question:

# Rakefile
require 'rake/dsl_definition'

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

<MyApplicationName>::Application.load_tasks

After I run again the cap deploy command I get the following error:

...

  * 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 m开发者_如何学Pythonethod 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

Where the code related to Capistrano is wrong? How to use correctly the load 'deploy/assets' statement in order to make the deployment process to work?


Have you tried simply defining your own task? That's what I did 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"

You do need RVM initialization for this if you use RVM

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜