How do I run a rake task from Capistrano?

前端 未结 16 2118
忘了有多久
忘了有多久 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条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 02:38

    There's an interesting gem cape that makes your rake tasks available as Capistrano tasks, so you can run them remotely. cape is well documented, but here's a short overview on how to set i up.

    After installing the gem, just add this to your config/deploy.rb file.

    # config/deploy.rb
    require 'cape'
    Cape do
      # Create Capistrano recipes for all Rake tasks.
      mirror_rake_tasks
    end
    

    Now, you can run all you rake tasks locally or remotely through cap.

    As an added bonus, cape lets you set how you want to run your rake task locally and remotely (no more bundle exec rake), just add this to your config/deploy.rb file:

    # Configure Cape to execute Rake via Bundler, both locally and remotely.
    Cape.local_rake_executable  = '/usr/bin/env bundle exec rake'
    Cape.remote_rake_executable = '/usr/bin/env bundle exec rake'
    

提交回复
热议问题