2012-01-26 119 views
2

我正在使用capistrano来部署我的rails应用程序。我想覆盖deploy:assets:precompile任务,但我无法做到这一点。任何人都知道为什么这不起作用?如果这是不可能的,是否有可能跳过deploy:assets:precompile每次运行deploy任务时都运行?忽略Capistrano默认行为

这是我deploy.rb 负荷 “配置/ domain.rb”

set :application, DOMAIN 
set :repository, "..." 
set :use_sudo, false 
set :deploy_to, "/var/www/#{application}" 
set :deploy_via, :remote_cache 
set :user, "yomama" 
set :port, 1337 
set :scm, :git 
set :normalize_asset_timestamps, false 

role :web, "123.123.123.123" 
role :app, "123.123.123.123" 
role :db, "123.123.123.123", primary: true 

# RVM bootstrap 
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) 
require "rvm/capistrano" 
set :rvm_ruby_string, "[email protected]#{application}" 
set :rvm_type, :system 
set :rvm_bin_path, "/usr/local/bin" 

# bundler bootstrap 
require "bundler/capistrano" 

namespace :deploy do 
    desc "Zero-downtime restart of Unicorn" 
    task :restart, :except => { :no_release => true } do 
    run "kill -s USR2 `cat #{shared_path}/pids/unicorn.pid`" 
    end 

    desc "Start unicorn" 
    task :start, :except => { :no_release => true } do 
    run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D -E production" 
    end 

    desc "Stop unicorn" 
    task :stop, :except => { :no_release => true } do 
    run "kill -s QUIT `cat #{shared_path}/pids/unicorn.pid`" 
    end 

    desc "symlink shared files between releases" 
    task :symlink_shared, :roles => :app do 
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" 
     run "ln -nfs #{shared_path}/assets #{release_path}/assets" 
    run "ln -nfs #{shared_path}/public/uploads #{release_path}/public/uploads" 
     # run "ln -nfs #{shared_path}/log/production.log #{release_path}/log/production.log" 
    end 

    namespace :assets do 
    desc "Precompile assets only if it is needed" 
    task :precompile, :roles => :web, :except => { :no_release => true } do 
     from = source.next_revision(current_revision) 
     run "cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l" 
     if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 
     run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} 
     else 
     logger.info "Skipping asset pre-compilation because there were no asset changes" 
     end 
    end 
    end 
end 

desc "tail production log files" 
task :tail_logs, :roles => :app do 
    run "tail -f #{shared_path}/log/production.log" do |channel, stream, data| 
    trap("INT") { puts 'Interupted'; exit 0; } 
    puts # for an extra line break before the host name 
    puts "#{channel[:host]}: #{data}" 
    break if stream == :err 
    end 
end 

after "deploy:update_code", "deploy:symlink_shared" 

回答

4

我笨!我以错误的顺序加载文件,我的capfile文件。

前:

load 'deploy' if respond_to?(:namespace) # cap2 differentiator 
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } 
load 'config/deploy' # remove this line to skip loading any of the default tasks 
# Uncomment if you are using Rails' asset pipeline 
load 'deploy/assets' 

后:

load 'deploy' if respond_to?(:namespace) # cap2 differentiator 
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } 
# Uncomment if you are using Rails' asset pipeline 
load 'deploy/assets' 
load 'config/deploy' # remove this line to skip loading any of the default tasks 

现在,它的工作原理。