If you've ever needed to run a custom rake command on the server, then you'll know how helpful it would be to run it along side your capistrano deployment process. Here's how:Add this to your deploy.rb:namespace :deploy do
# ....
# @example
# bundle exec cap uat deploy:invoke task=users:update_defaults
desc 'Invoke rake task on the server'
task :invoke do
fail 'no task provided' unless ENV['task']
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, ENV['task']
end
end
end
end
endThen you can run your command from the terminal:bundle exec cap uat deploy:invoke task=users:update_defaultsThe great thing about this is that if you are using capistrano/rbenv and capistrano/bundler, the execute command will automatically take care over everything for you under the hood.