Skip to content

Instantly share code, notes, and snippets.

@crmaxx
Forked from ayamomiji/deploy.rb
Created September 9, 2021 13:35
Show Gist options
  • Save crmaxx/1646f62d36493212b99b748cc6780d78 to your computer and use it in GitHub Desktop.
Save crmaxx/1646f62d36493212b99b748cc6780d78 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment