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

时间:2017-07-08 21:37:27

标签: ruby-on-rails-4 nginx amazon-ec2 asset-pipeline passenger

有时我的EC2服务器已关闭。 我从未弄清楚原因。 但是在一些部署操作后的这几天,服务器已关闭。

在部署之后就失败了。我有很多资产要预编译,部署时间太长。

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

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

具有更高的值。见印刷品:

CPU UTILIZATION

Average Latency

Network In

enter image description here

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

工作正常,部署(cap production deploy)非常快,只有经过修改的资产才会被预编译。

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

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

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

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

之后,我要去监控区域,价值更高! 然后我假设预编译耗尽了服务器。

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

的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

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

环境信息

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

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

编辑1

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

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

1 个答案:

答案 0 :(得分:0)

<强>解

阻止在服务器上运行import obj from './object.json'; // obj = { name: 'someName' } describe('Testing a component', () => { it('Some testing', () => { const obj2 = Object.assign({}, obj); //Clone the object obj2.name = 'otherName'; // Muatate the object console.log(obj); // { name: 'otherName' } }); }) 任务。 我发布了other question(已解决)以了解如何执行此操作。 我希望assets precompile任务永远不会在服务器上运行。