提问者:小点点

Rails是部署后预编译的资产-Amazon EC2


有时我的EC2服务器停机。我一直没弄明白原因。但是这些天在执行了一些部署操作之后,服务器关闭了。

部署完成后,它就停机了。我有很多资产要预编译,部署时间太长。

我去了EC2仪表板上的监控区域:

  • CPU使用率(实例)

具有更高的值。见照片:

然后,我安装了gem Capistrano更快的资产,以避免Capistrano未修改的预编译资产。

良好的工作和部署(帽生产部署)是非常快的,只有修改的资产是预编译。

但是,在使用该站点几分钟后,一个页面的加载延迟很大,然后显示错误504。

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

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

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'.

之后准备去监控区数值更高!然后我假设预编译耗尽了服务器。

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

宝石文件

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.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

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

我刚刚通过capistrano向服务器发送了一些修改。没有对资产进行任何修改,cap生产部署忽略了rake资产预编译任务。

但是我访问了NGINXerror.log,没有错。当我访问特定的URL时,页面未加载,并且资产scss警告出现在控制台上(换句话说,资产预编译在加载页面后运行)。几分钟后,浏览器向我显示HTTP ERROR 504。CPU利用率和Avarege延迟再次提高。


共1个答案

匿名用户

解决方案

防止资产预编译任务在服务器上运行。我发布了其他问题(已解决),以了解如何做到这一点。我希望资产预编译任务永远不会在服务器上运行。