Rails是部署后的预编译资产-Amazon EC2 [英] Rails is precompile assets after deploy - Amazon EC2

查看:102
本文介绍了Rails是部署后的预编译资产-Amazon EC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我的EC2服务器已关闭. 我从不知道原因. 但是这些天在执行一些部署操作后,服务器已关闭.

Sometimes my EC2 server is down. I never figured out the reason. But these days after some deployments actions, the server is down.

并且在部署后关闭.我有很多资产需要预编译,并且部署花费的时间太长.

And is down after the deploy. I have a lot of assets to precompile and the deploy takes too long.

我去了EC2仪表板上的监视区域,并且:

I went to the monitoring areas on EC2 dashboard and the:

  • CPU使用率(实例)
  • 延迟(ELB)
  • 网络输入/输出(实例)

具有更高的值.查看照片:

Is with higher values. See the prints:

然后,我安装了一个 Capistrano Faster Assets 的宝石,以避免capistrano预编译未修改的资产.

Then, I installed a gem Capistrano Faster Assets, to avoid capistrano precompile assets that is not modified.

工作正常,部署(cap production deploy)速度更快,并且仅对修改后的资产进行预编译.

Works fine and the deploy (cap production deploy) is very faster and only the modified assets is precompiled.

但是,在使用该网站几分钟后,一页加载延迟很多,然后显示错误504.

But, after several minutes using the site, one page delays a lot to load and then shows the error 504.

我通过SSH连接EC2,进入LOGs文件夹(/var/log/nginx)并运行命令:tail -f error.log

I connect my EC2 via SSH, going to LOGs folder (/var/log/nginx) and run the command: tail -f error.log

令我惊讶的是,资产在那一刻正在预编译. 我在控制台中看到了这一点:

For my surprise, the assets is precompiling in that moment. I saw this in console:

App 1938 stderr: You probably don't mean to use the color value `orange' in interpolation here.
App 1938 stderr: It may end up represented as #ffa500, which will likely produce invalid CSS.
App 1938 stderr: Always quote color names when using them as strings (for example, "orange").
App 1938 stderr: If you really want to use the color value here, use `"" + $palette'.
App 1938 stderr: 
App 1938 stderr: WARNING on line 15, column 16 of /home/ubuntu/my_app/releases/20170708194653/app/another/assets/folder/colors.scss:
App 1938 stderr: You probably don't mean to use the color value `purple' in interpolation here.
App 1938 stderr: It may end up represented as #800080, which will likely produce invalid CSS.
App 1938 stderr: Always quote color names when using them as strings (for example, "purple").
App 1938 stderr: If you really want to use the color value here, use `"" + $palette'.
App 1938 stderr: 
App 1938 stderr: WARNING on line 15, column 16 of /home/ubuntu/my_app/releases/20170708194653/app/another/assets/folder/colors.scss:
App 1938 stderr: You probably don't mean to use the color value `black' in interpolation here.
App 1938 stderr: It may end up represented as #000000, which will likely produce invalid CSS.
App 1938 stderr: Always quote color names when using them as strings (for example, "black").
App 1938 stderr: If you really want to use the color value here, use `"" + $palette'.

之后,我要转到监视区域,并且该值更高! 然后,我假设预编译已耗尽服务器.

After that, I am going to the monitoring area and the values is higher! Then I assume the precompile is exhaust the server.

但是,为什么预编译在部署后运行? 在我的配置下面:

But, why the precompile runs after deploy? Below my configs:

宝石文件

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 }

config/environments/production.rb

config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true

此文件中的其他资产配置已被注释

环境信息

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

如果您需要更多信息,请在评论中告诉我.

If you need more information, tell me on the comments.

我刚刚通过capistrano向服务器发送了一些修改. 资产没有任何修改,cap production deploy忽略了rake assets precompile任务.

I just sent some modifications to the server via capistrano. No modification in assets and the cap production deploy ignored the rake assets precompile task.

但是我访问了NGINX error.log,没有错. 当我访问特定的URL时,页面未加载,并且控制台上出现了 assets scss警告(换句话说, assets precompile 在页面加载后正在运行).几分钟后,浏览器显示HTTP ERROR 504. CPU利用率和Avarege Latency再次更高.

But I accessed the NGINX error.log and nothing wrong. When I accessed the specific URL, the page not load and the assets scss warnings appeared on the console (in other words, assets precompile is running after load page). After few minutes the browser shows me the HTTP ERROR 504. The CPU utilization and the Avarege Latency is higher again.

推荐答案

解决方案

防止assets precompile任务在服务器上运行. 我发布了其他问题 (已解决)以了解如何执行此操作. 我希望assets precompile任务不再在服务器上运行.

Prevent the assets precompile task runs on the server. I posted other question (solved) to know how to do this. I hope the assets precompile task never more runs on the server.

这篇关于Rails是部署后的预编译资产-Amazon EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆