How do I run a rake task from Capistrano?

前端 未结 16 2144
忘了有多久
忘了有多久 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:34

    Previous answers didn't help me and i found this: From http://kenglish.co/run-rake-tasks-on-the-server-with-capistrano-3-and-rbenv/

    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
    
    end
    

    to run your task use

    bundle exec cap uat deploy:invoke task=users:update_defaults
    

    Maybe it will be useful for someone

提交回复
热议问题