Last active
August 5, 2018 12:03
-
-
Save andrey-skat/10399224 to your computer and use it in GitHub Desktop.
Local assets precompilation on Rails 4 using Capistrano 3
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
# also you need to uncomment next line in Capfile | |
# require 'capistrano/rails/assets' | |
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 'bin/rake assets:precompile' | |
end | |
end | |
within release_path do | |
with rails_env: fetch(:rails_env) do | |
old_manifest_path = "#{shared_path}/public/assets/manifest*" | |
execute :rm, old_manifest_path if test "[ -f #{old_manifest_path} ]" | |
upload!('./public/assets/', "#{shared_path}/public/", recursive: true) | |
end | |
end | |
run_locally { execute 'rm -rf public/assets' } | |
end | |
end | |
end | |
end |
Thank you. This really saves my ass.
Uploading many files (and some non compressed) can be slow.
Try compressing and packaging for uploading:
[Example here] (https://gist.github.com/jairud-garcia/4e9210c4d896b7c56f5fd54164812b8f)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. This is very slow to upload files. Other solutions with rsync may reduce deployment time.
https://gist.github.com/basti/9232976