2013-10-25 80 views
0

“耙资产:预编译”和“帽​​部署”每当我打电话时(通常多于一个小时)消耗非常高的时间量。有时部署挂在一起。 我使用Rails 3.2.13,Ruby 1.9.3,OSX和Backbone的Chaplin Framework for frontend。 如何加快资产预编译和部署任务以及会导致此类冻结的原因?Capistrano部署和资产:预编译太慢

我deploy.rb配置:

# -*- encoding : utf-8 -*- 
require 'bundler/capistrano' 
load 'deploy/assets' 

set :application, "eyelashes" 
set :rails_env, "production" 

set :repository, "[email protected]: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 

也许我能以某种方式通过在配置更改部署加速比?

回答

0

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

有许多宝石和软件包可以加快资产预编译的速度,但是在您的情况下,这可能会让事情变得更糟!

+0

感谢您的回复。但是,我的Leaseweb VDS速度非常快。 –

+0

*速度*没有太大的区别!它主要是内存约束。您可能会尝试删除“初始化预编译”。它会导致rails为每个要重新编译的文件启动整个框架。 –

+0

我在生产配置中设置了initialize_on_precompile = false,但仍然很慢。 –

相关问题