简体   繁体   中英

Disable hooks for Capistrano3?

Is there some way to disable some before / after hooks in Capistrano3?

For example, I want to deploy the code for my (Rails) application, but I don't want to start the application on the first deploy. (Maybe this is not "ideal", but there are a number of reasons I may not want to do so.)

I'm aware of the following options:

  1. Disable the tasks I don't want to run as part of my deploy.rb file, eg, Rake::Task['deploy:compile_assets'].clear_actions .
  2. Remove the appropriate require statements from my Capfile , eg, # require 'capistrano/rails/assets' .

What I would like is to be able to call a specific task OR pass some command line flags to cap [stage] deploy . What I want to do is approximately the same as deploy:setup , but that task is not available in Capistrano3.

What is the best way to do this?

Option 1: Disable require statements with ENV switch

As you already mentioned, removing the require statements is the easiest way to get the result you are looking for. To be able to control this on the command line, I would use a ENV option, like this:

# In Capfile
# Include tasks from other gems included in your Gemfile
unless ENV["CAP_DISABLE_PLUGINS"]
  require "capistrano/bundler"
  require "capistrano/rails"
  # etc.
end

Then run:

CAP_DISABLE_PLUGINS=1 cap production deploy

Option 2: Define a custom task

For more fine-grained control over what tasks are run, define a custom task.

If you run cap [stage] deploy with the --trace option, you will see debug output of all the tasks that are being invoked. Review that output and decide which of those tasks you need, and which you want to skip. Then assemble your choices into a custom task.

For example, this should deploy your code and symlink it to current , but skip running bundler , compiling assets, or migrating the database:

# Place this in config/deploy.rb
namespace :deploy do
  task :setup do
    invoke "deploy:check"
    invoke "deploy:new_release_path"
    invoke "git:create_release"
    invoke "deploy:set_current_revision"
    invoke "deploy:symlink:shared"
    invoke "deploy:symlink:release"
    invoke "deploy:log_revision"
  end
end

Then just run:

cap production deploy:setup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM