Last active
February 9, 2017 13:11
-
-
Save jairud-garcia/4e9210c4d896b7c56f5fd54164812b8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bassed in https://gist.github.com/andrey-skat/10399224