Skip to content

Instantly share code, notes, and snippets.

@beanieboi
Created February 19, 2013 17:37
Show Gist options
  • Save beanieboi/4988048 to your computer and use it in GitHub Desktop.
Save beanieboi/4988048 to your computer and use it in GitHub Desktop.
asset deployment with ruby on rails and rsync only if they changed
before 'deploy:create_symlink', 'deploy:upload_assets'
before 'deploy:update_code', 'deploy:compress_assets'
after 'deploy:update_code', 'deploy:custom_symlink'
namespace :deploy do
desc "symlinks"
task :custom_symlink do
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
desc "compress assets locally"
task :compress_assets do
if assets_changed?
run_locally("rm -rf public/assets/*")
run_locally("bundle exec rake assets:precompile")
end
end
desc "Upload assets"
task :upload_assets do
if assets_changed?
find_servers_for_task(current_task).each do |current_server|
run_locally("rsync --delete -avz -e ssh 'public/assets' '#{user}@#{current_server}:#{shared_path}'")
end
run_locally("rm -rf public/assets/*")
end
end
def assets_changed?
@changed_lines ||= begin
deployed_sha1 = capture("cd #{current_path} && git log -1 --name-status | head -1 | awk '{print $2}'").chop
version_to_deploy = run_locally("git ls-remote #{repository} master | awk '{print $1}'").chop
run_locally("git log #{deployed_sha1}..#{version_to_deploy} vendor/assets/ app/assets/ | wc -l").to_i
end
@changed_lines > 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment