Skip to content

Instantly share code, notes, and snippets.

@lxcid
Created January 18, 2013 15:54
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 lxcid/4565541 to your computer and use it in GitHub Desktop.
Save lxcid/4565541 to your computer and use it in GitHub Desktop.
Replaces deploy:assets:precompile task to do assets precompilation locally.
# Base on http://stackoverflow.com/a/12839484/379604 and https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/assets.rb
namespace :deploy do
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task locally. 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"
DESC
task :precompile, :roles => assets_role, :except => { :no_release => true } do
run_locally "#{rake} RAILS_ENV=#{rails_env.to_s.shellescape} #{asset_env} assets:precompile"
run_locally "cd -- public && tar -zcvf #{assets_prefix}.tar.gz #{assets_prefix}"
top.upload "public/#{assets_prefix}.tar.gz", "#{shared_path.shellescape}", :via => :scp
run "cd -- #{shared_path.shellescape} && tar -zxvf #{assets_prefix}.tar.gz && rm -- #{assets_prefix}.tar.gz"
run_locally "rm -- public/#{assets_prefix}.tar.gz && rm -rf -- public/#{assets_prefix}"
run "cp -- #{shared_path.shellescape}/assets/manifest.yml #{current_release.shellescape}/assets_manifest.yml"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment