Ruby on rails 4 有没有办法防止rails在生产环境中预编译资产?
我的项目中有很多资产。服务器中的预编译任务非常慢,会耗尽主机(CPU利用率100%,平均延迟高) 我的想法是预编译本地主机中的所有资产,并将所有已预编译的文件发送到GIT(master) 在部署操作(Ruby on rails 4 有没有办法防止rails在生产环境中预编译资产?,ruby-on-rails-4,amazon-ec2,deployment,capistrano3,Ruby On Rails 4,Amazon Ec2,Deployment,Capistrano3,我的项目中有很多资产。服务器中的预编译任务非常慢,会耗尽主机(CPU利用率100%,平均延迟高) 我的想法是预编译本地主机中的所有资产,并将所有已预编译的文件发送到GIT(master) 在部署操作(cap production deploy)中,避免预编译任务,并在服务器中防止任何预编译任务 服务器使用通过GIT提供的capistrano发送的已预编译文件 可能吗?如果是,怎么办? 如果没有,是否有另一种解决方案来避免服务器资源 以下是我的配置: Gemfile gem 'capistrano
cap production deploy
)中,避免预编译任务,并在服务器中防止任何预编译任务
服务器使用通过GIT提供的capistrano发送的已预编译文件
可能吗?如果是,怎么办?
如果没有,是否有另一种解决方案来避免服务器资源
以下是我的配置:
Gemfile
gem 'capistrano-rails', group: :development
gem 'capistrano-faster-assets', '~> 1.0', group: :development
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 }
Capfile
gem 'capistrano-rails', group: :development
gem 'capistrano-faster-assets', '~> 1.0', group: :development
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 }
config/environments/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
如果您需要更多信息,请在评论中告诉我。简短回答:
替换
require 'capistrano/rails'
与
为什么会这样:
当您需要capistrano/rails
时,实际上包括以下内容():
其中每一项都可以单独包含,以获得这些功能。根据文档:Hello@will\u in\u wi,谢谢您的回答。正如我所看到的,在
cap生产部署中,资产预编译将不会发生。然后我必须在本地预编译资产,发送到git master
,然后进行部署,对吗?对。如果我理解正确,您希望在本地预编译资产,将它们提交给master,然后让Capistrano跳过预编译,因为预编译的资产已经提交。我的回答告诉你如何跳过预编译。谢谢你的解释。我将在明天进行测试,届时我将部署一些更改。您知道在config/environments/production.rb
中将config.assets.compile=true
更改为false
是否是一个好主意吗?是的,您的解决方案很好!现在,我在本地机器中执行rake资产预编译
,并将所有已编译的资产发送到git master
。我按照您的建议更改了Capfile
,部署没有运行预编译。我在config/environments/production.rb
中将config.assets.compile
更改为FALSE,谢谢!