首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖Capistrano默认行为

覆盖Capistrano默认行为
EN

Stack Overflow用户
提问于 2012-01-26 19:00:04
回答 1查看 4.8K关注 0票数 2

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

这是我的deploy.rb加载"config/domain.rb“

代码语言:javascript
复制
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, "1.9.2@#{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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-26 19:26:52

我是个笨蛋!我在capfile中加载文件的顺序错误。

之前:

代码语言:javascript
复制
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'

之后:

代码语言:javascript
复制
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

现在它起作用了。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9017136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档