Skip to content

Instantly share code, notes, and snippets.

@jairud-garcia
Last active February 9, 2017 13:11
Show Gist options
  • Save jairud-garcia/4e9210c4d896b7c56f5fd54164812b8f to your computer and use it in GitHub Desktop.
Save jairud-garcia/4e9210c4d896b7c56f5fd54164812b8f to your computer and use it in GitHub Desktop.
namespace :deploy do
namespace :assets do
Rake::Task['deploy:assets:precompile'].clear_actions
desc 'Precompile assets locally and upload to servers'
task :precompile do
on roles(fetch(:assets_roles)) do
run_locally do
with rails_env: fetch(:rails_env) do
execute 'rm -rf public/assets'
execute 'bin/rake assets:precompile'
# Compress any non gz file
execute 'find public/assets -type f|grep -v ".gz"|xargs gzip -f -9'
# Delete any non gz file
execute 'find public/assets -type f|grep -v ".gz"|xargs rm'
# Pack everything in tar
execute 'tar -cvvf assets.tar public/assets'
end
end
within release_path do
with rails_env: fetch(:rails_env) do
# Upload the packaged tar (is faster than upload every file)
upload!('assets.tar', ".")
old_manifest_path = "#{shared_path}/public/assets/manifest*"
execute :rm, old_manifest_path if test "[ -f #{old_manifest_path} ]"
# Unpack tar
execute "tar xvvf assets.tar -C #{shared_path}"
# Create non gzip file versions
execute "find #{shared_path}/public/assets -type f|grep '.gz'|xargs gunzip -f -k; echo Done"
# Deletes package
execute "rm assets.tar"
end
end
run_locally { execute 'rm -rf public/assets' }
end
end
end
end
@jairud-garcia
Copy link
Author

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