Created
June 18, 2019 21:22
-
-
Save itolosa/b335f3270f7c3912abbef45ae4126b3e to your computer and use it in GitHub Desktop.
Execute rake tasks including arguments using capistrano (based on: https://github.com/sheharyarn/capistrano-rake/blob/master/lib/capistrano/tasks/invoke.rake)
This file contains hidden or 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
require 'shellwords' | |
namespace :invoke do | |
# Defalut to :app roles | |
set :rake_roles, :app unless fetch(:rake_roles) | |
desc "Execute a rake task on a remote server (cap invoke:rake TASK=db:migrate)" | |
task :rake do | |
if ENV['TASK'] | |
on roles(fetch(:rake_roles)) do | |
within current_path do | |
with rails_env: fetch(:rails_env) do | |
execute 'bundle', 'exec', 'rake', Shellwords.escape(ENV['TASK']) | |
end | |
end | |
end | |
else | |
puts "\n\nFailed! You need to specify the 'TASK' parameter!", | |
"Usage: cap <stage> invoke:rake TASK=your:task" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
cap production invoke:rake TASK=some:customtask[argument1,argument2]