Read more

Dynamically skip Capistrano hooks

Dominik Schöler
June 10, 2011Software engineer at makandra GmbH

When you have a hook in your Capistrano file that dumps your remote database, you might not want it to dump each time you deploy (say, you're experimenting with staging and don't want ten dumps an hour). How to skip dump creation:

Capistrano 2

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

In your Capistrano file:

before 'deploy:update_code', 'db:dump' unless fetch(:skip_dump, false)

The second parameter of fetch sets a default value if skip_dump is not defined.

In your terminal:

cap staging deploy -S skip_dump=true

The -S must be a capital letter to set skip_dump before loading the recipes.

Capistrano 3

In your Capistrano file:

before 'deploy:updating', 'db:dump' unless ENV['SKIP_DUMP']

In your terminal:

SKIP_DUMP=true cap staging deploy
Posted by Dominik Schöler to makandra dev (2011-06-10 14:19)