ruby-yui-compressor icon indicating copy to clipboard operation
ruby-yui-compressor copied to clipboard

Asset precompile works on development but fails on staging/production

Open mmustala opened this issue 10 years ago • 2 comments

Im using JRuby and got tired of slow asset precompiling with the :uglifier and :sass compilers. I installed yui-compiler (0.12.0) and tried precompiling in development mode and it ran pretty fast. Everything was ok. Then when I deployed into our staging server with capistrano it threw an error.

  * executing "cd /home/staging/releases/20141218122233 && bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile"
    servers: ["5.9.144.199"]
    [5.9.144.199] executing command
*** [err :: 5.9.144.199] rake aborted!
*** [err :: 5.9.144.199] YUI::Compressor::RuntimeError: Command 'java -jar /home/staging/shared/bundle/jruby/1.9/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge /tmp/yui_compress20141218-31554-1h3vduh' returned non-zero exit status
*** [err :: 5.9.144.199] (in /home/staging/releases/20141218122233/app/assets/javascripts/application.js)
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:106:in `compress'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:141:in `streamify'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:86:in `compress'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/yui_compressor.rb:19:in `evaluate'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/context.rb:197:in `evaluate'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/context.rb:194:in `evaluate'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/bundled_asset.rb:25:in `initialize'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/base.rb:377:in `build_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/index.rb:94:in `build_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/caching.rb:58:in `cache_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/index.rb:93:in `build_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/base.rb:287:in `find_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/index.rb:61:in `find_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:211:in `find_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:257:in `benchmark'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:210:in `find_asset'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:119:in `compile'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:118:in `compile'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `define'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-2.11.0/lib/rake/sprocketstask.rb:146:in `with_logger'
*** [err :: 5.9.144.199] /home/staging/shared/bundle/jruby/1.9/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `define'
*** [err :: 5.9.144.199] Tasks: TOP => assets:precompile
*** [err :: 5.9.144.199] (See full trace by running task with --trace)
    command finished in 20347ms
*** [deploy:update_code] rolling back

I have JAVA_HOME set in the capistrano deploy.rb and also in the .profile file.

set :default_environment, {
    'JAVA_HOME' => '$HOME/java'
}

What could cause that in development environment the same file is successfully compressed but in other environment is not?

mmustala avatar Dec 18 '14 13:12 mmustala

I'd go straight to the command that returned non-zero exit status and troubleshoot that. Log into the troublesome machine as the same user that you use to run this deploy script and run:

java -jar /home/staging/shared/bundle/jruby/1.9/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge /tmp/yui_compress20141218-31554-1h3vduh

My guess is you'll find that java doesn't exist on the path.

stevecrozz- avatar Jan 12 '15 03:01 stevecrozz-

I have the same error on my production server when deploy with capistrano. When I run the command as @stevecrozz suggestion. It show error:

java.io.FileNotFoundException: /tmp/yui_compress20150521-2184-1p6a0d3 (No such file or directory)

I am sure my java is not missing.

$java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

I try to create /tmp/yui_compress20150521-2184-1p6a0d3 file then rerun the command above and it works. I think maybe it is bug

minhhahl avatar May 21 '15 10:05 minhhahl