Capistrano 部署和资产:预编译太慢



"rake assets:precompile"和"cap deploy"每当我调用它时都会消耗极高的时间(通常超过一个小时)。有时部署会挂起。我使用Rails 3.2.13,Ruby 1.9.3,OSX和Backbone的卓别林框架作为前端。如何加快资产预编译和部署任务的速度,什么会导致这种冻结?

我的部署.rb配置:

# -*- encoding : utf-8 -*-
require 'bundler/capistrano'
load 'deploy/assets'
set :application, "eyelashes"
set :rails_env, "production"
set :repository,  "git@github.com:eyelasher/repo.git"
set :scm, :git
set :deploy_via, :checkout
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true

server "75.223.145.3", :app, :web, :db, :primary => true
set :bundle_without,  [:test]
set :user, 'deployer'
set :deploy_to, "/home/deployer/eyelasher"
set :branch, "master" unless exists?(:branch)
set :use_sudo, false
set :rvm_type, :user
set :rvm_ruby_string, :local
set :deploy_via, :checkout
before 'deploy:setup', 'rvm:create_gemset'
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
after "deploy", "deploy:migrate"
after "deploy", "deploy:cleanup"
require 'rvm/capistrano'
require 'thinking_sphinx/deploy/capistrano'
#after 'deploy:update_code', :roles => :app do
  #run "rm -f #{current_release}/config/database.yml"
  #run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml"
#end
namespace :deploy do
  task :restart do
    run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
  end
  task :start do
    run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D;"
  end
  task :stop do
    run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
  end
end

# Thinking Sphinx typing shortcuts
namespace :ts do
  task :conf do
    thinking_sphinx.configure
  end
  task :in do
    thinking_sphinx.index
  end
  task :start do
    thinking_sphinx.start
  end
  task :stop do
    thinking_sphinx.stop
  end
  task :restart do
    thinking_sphinx.restart
  end
  task :rebuild do
    thinking_sphinx.rebuild
  end
end
# http://github.com/jamis/capistrano/blob/master/lib/capistrano/recipes/deploy.rb
# :default -> update, restart
# :update  -> update_code, symlink
namespace :deploy do
  desc "Link up Sphinx's indexes."
  task :symlink_sphinx_indexes, :roles => [:app] do
    run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
  end
  task :activate_sphinx, :roles => [:app] do
    symlink_sphinx_indexes
    thinking_sphinx.configure
    #thinking_sphinx.stop
    #thinking_sphinx.start
  end
  task :copy_images do
    run "cp -R #{shared_path}/public/images #{release_path}/public/images"
  end
  before 'deploy:update_code', 'thinking_sphinx:stop'
  after 'deploy:update_code', 'deploy:activate_sphinx'
  after 'deploy:update_code', 'deploy:copy_images'
end

也许我可以通过更改部署配置来以某种方式加速?

如果您要部署到内存受限的VPS,这听起来很合理。我建议在更快的机器上预编译资产并将它们签入您的存储库。

有各种 Gem 和软件包可以通过平行化来加速资产预编译,但是在您的情况下,这可能会让事情变得更糟!

相关内容

  • 没有找到相关文章

最新更新