我的项目中有很多资产。服务器中的预编译任务非常慢并耗尽主机(CPU利用率为100%,平均延迟时间很长)。
我的想法是在我的localhost中预编译所有资产,并将已经预编译的所有文件发送给GIT(master)。
在部署操作(cap production deploy
)中,避免预编译任务,并在服务器中阻止任何预编译任务。
服务器使用通过capistrano
发送的已经预编译的文件,可在GIT中找到。
有可能吗?如果有,该怎么办? 如果不是,还有另一种避免服务器预先出现资产的解决方案吗?
在我的配置之下:
的Gemfile
gem 'capistrano-rails', group: :development
gem 'capistrano-faster-assets', '~> 1.0', group: :development
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/faster_assets'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
配置/环境/ production.rb
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
other assets configs in this file is commented
环境信息
OS: Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)
ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
rails -v: 4.2.3
nginx -v: nginx/1.8.0
passenger -v: 5.0.10
如果您需要更多信息,请告诉我评论。
答案 0 :(得分:1)
替换
require 'capistrano/rails'
带
require 'capistrano/rails/migrations'
require 'capistrano/bundler'
当您需要capistrano/rails
时,您确实包含以下内容(source):
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
每个都可以单独包含,以获得这些功能。根据文档:https://github.com/capistrano/rails#usage