How do I run a rake task from Capistrano?

前端 未结 16 2152
忘了有多久
忘了有多久 2020-11-28 02:18

I already have a deploy.rb that can deploy my app on my production server.

My app contains a custom rake task (a .rake file in the lib/tasks directory).

I\

16条回答
  •  旧时难觅i
    2020-11-28 02:33

    I personally use in production a helper method like this:

    def run_rake(task, options={}, &block)
      command = "cd #{latest_release} && /usr/bin/env bundle exec rake #{task}"
      run(command, options, &block)
    end
    

    That allows to run rake task similar to using the run (command) method.


    NOTE: It is similar to what Duke proposed, but I:

    • use latest_release instead of current_release - from my experience it is more what you expect when running a rake command;
    • follow the naming convention of Rake and Capistrano (instead of: cmd -> task and rake -> run_rake)
    • don't set RAILS_ENV=#{rails_env} because the right place to set it is the default_run_options variable. E.g default_run_options[:env] = {'RAILS_ENV' => 'production'} # -> DRY!

提交回复
热议问题