Skip to content

Instantly share code, notes, and snippets.

@aroc
Created July 25, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroc/3178608 to your computer and use it in GitHub Desktop.
Save aroc/3178608 to your computer and use it in GitHub Desktop.
Rails post deploy asset compiling
# Checks to see if the release you're deploying and the last version's "assets" directories have
# the same lines (content). If they do, don't run the asset precompilation.
#
# Notes on this at the delicious stackoverflow.com:
# http://stackoverflow.com/questions/9016002/speed-up-assetsprecompile-with-rails-3-1-3-2-capistrano-deployment
#
# @note This fucks things up when you add stuff to the precompile list. It won't precompile
# those new items 'cause it doesn't think there is anything new. A little bit manual but is a
# gotcha so would be nice to handle with this as well.
#
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %{rm -rf #{latest_release}/public/assets/*}
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment