Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Skip asset pre-compilation when deploying if the assets didn't change
namespace :deploy do
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 %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
end
@stayhero

This comment has been minimized.

Show comment Hide comment
@stayhero

stayhero Dec 13, 2011

Great, never had time to find out by myself how to do that. BTW: I had to remove vendor/assets path from line 5 because it doesn't exist in my repo, and git returns an error if path does not exist in repo.

Great, never had time to find out by myself how to do that. BTW: I had to remove vendor/assets path from line 5 because it doesn't exist in my repo, and git returns an error if path does not exist in repo.

@MaherSaif

This comment has been minimized.

Show comment Hide comment
@MaherSaif

MaherSaif Jan 6, 2012

Thanks,

Thanks,

@webervin

This comment has been minimized.

Show comment Hide comment
@webervin

webervin Feb 28, 2012

You also probably should check for Gemfile.lock, as some assets are provided by gems.

You also probably should check for Gemfile.lock, as some assets are provided by gems.

@smith

This comment has been minimized.

Show comment Hide comment
@smith

smith Apr 11, 2012

This will fail on the first deploy because current_revision is not yet defined and the command capistrano uses to find current_revision will fail. You can add :on_error => :continue to the task definition and it won't fail, but it will skip it and you'll have to deploy twice on the first go in order to build you assets, which is still kind of hacky.

smith commented Apr 11, 2012

This will fail on the first deploy because current_revision is not yet defined and the command capistrano uses to find current_revision will fail. You can add :on_error => :continue to the task definition and it won't fail, but it will skip it and you'll have to deploy twice on the first go in order to build you assets, which is still kind of hacky.

@olegykz

This comment has been minimized.

Show comment Hide comment
@olegykz

olegykz Nov 15, 2012

Simple workaround for first deploy:
https://gist.github.com/4079213

olegykz commented Nov 15, 2012

Simple workaround for first deploy:
https://gist.github.com/4079213

@Martin91

This comment has been minimized.

Show comment Hide comment
@Martin91

Martin91 Jul 18, 2013

Hi all, is it essential to add lib/*/app/assets to my own list of locations to git log? Currently I have some gems downloaded, located under the /lib directory, and I sometimes need to edit their assets.

Hi all, is it essential to add lib/*/app/assets to my own list of locations to git log? Currently I have some gems downloaded, located under the /lib directory, and I sometimes need to edit their assets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment