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"