Skip to content

Instantly share code, notes, and snippets.

@ayamomiji
Last active October 19, 2021 18:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ayamomiji/10802760 to your computer and use it in GitHub Desktop.
Save ayamomiji/10802760 to your computer and use it in GitHub Desktop.
capistrano 3: precompile assets on local machine then upload
namespace :deploy do
namespace :assets do
Rake::Task['deploy:assets:precompile'].clear_actions
desc "Precompile assets on local machine and upload them to the server."
task :precompile do
run_locally do
execute 'RAILS_ENV=production bundle exec rake assets:precompile'
end
on roles(:web) do
within release_path do
asset_full_path = "#{release_path}/public/#{fetch(:assets_prefix)}"
asset_parent_path = File.dirname(asset_full_path)
execute "mkdir -p #{asset_full_path}"
upload! "./public/#{fetch(:assets_prefix)}", asset_parent_path, recursive: true
end
end
run_locally do
execute "rm -r ./public/#{fetch(:assets_prefix)}"
end
end
end
end
@mjacobus
Copy link

mjacobus commented Oct 9, 2017

Thank you! That task helped me a lot!

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