Skip to content

Instantly share code, notes, and snippets.

@zorab47
Created October 10, 2012 18:24
Show Gist options
  • Save zorab47/3867479 to your computer and use it in GitHub Desktop.
Save zorab47/3867479 to your computer and use it in GitHub Desktop.
Capistrano task to precomile assets locally, if necessary
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
assets_path = File.join(release_path, "public/assets")
assets_empty = capture("ls -x #{assets_path}").length == 0
has_current_release = capture("if [ -d #{current_path} ]; then echo -n \"yes\"; fi") == "yes"
compile_assets = false
if has_current_release
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
compile_assets = true
end
end
if compile_assets or assets_empty
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment