Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
deploy/asset.rb
# -*- encoding : utf-8 -*-
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \
specify additional environment variables to pass to rake via the \
asset_env variable. The defaults are:
set :rake, "rake"
set :rails_env, "production"
set :asset_env, "RAILS_GROUPS=assets"
set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
DESC
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} #{assets_dependencies.join ' '} | 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
@supairish

This comment has been minimized.

Copy link

supairish commented Sep 7, 2012

When I use this and the default assets:precompile task isn't run on deploy. I get errors about, ____ isn't precompiled. Does this assume we're symlinking our public/assets directory outside of the current deploy directory? Thanks!

@supairish

This comment has been minimized.

Copy link

supairish commented Sep 7, 2012

Well to answer my own question, yes this does require that you symlink your public/assets directory outside of the current deploy. This works like a charm though, thanks for sharing!

@ndbroadbent

This comment has been minimized.

Copy link

ndbroadbent commented Oct 3, 2012

Hi there,

I've just written a gem to solve this problem inside Rails, called turbo-sprockets-rails3. It speeds up your assets:precompile by only recompiling changed files, and only compiling once to generate all assets. This works out of the box for capistrano, and is a much more bullet-proof solution.

If you are interested, it would be awesome if you could help me test out the turbo-sprockets-rails3 gem, and let me know if you have any problems. It currently only supports Rails 3.2.x, so I apologize if your app is running 3.1.x.

@tomaswitek

This comment has been minimized.

Copy link

tomaswitek commented Oct 25, 2012

I've tested the gem. It works like a charm. GREAT WORK !!!

@namick

This comment has been minimized.

Copy link

namick commented Oct 30, 2012

turbo-sprockets-rails3 is working great for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.