问题
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.
I went to the monitoring areas on EC2 dashboard and the:
- CPU usage (Instance)
- Latency (ELB)
- Network In/Out (Instance)
Is with higher values. See the prints:
Then, I installed a gem Capistrano Faster Assets, to avoid capistrano precompile assets that is not modified.
Works fine and the deploy (cap production deploy
) is very faster and only the modified assets is precompiled.
But, after several minutes using the site, one page delays a lot to load and then shows the error 504.
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:
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 }
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
Environment info
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.
Edit 1
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.
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.
回答1:
SOLUTION
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.
来源:https://stackoverflow.com/questions/44990957/rails-is-precompile-assets-after-deploy-amazon-ec2