Last Updated: February 25, 2016
·
1.384K
· danbt79

Prompt on Capistrano multistage deployments

Using development/staging/production deployments with Capistrano? Want to double-check that you really want to deploy to a particular environment?

Add this to your /config/deploy/[stage].rb

# Make sure we really want to target this environment!
puts "\e[0;35m =======================\e[0m\n"
puts "\e[0;35m Really deploy to PRODUCTION?\e[0m\n"
puts "\e[0;35m =======================\e[0m\n"

# Fetch user response
response = Capistrano::CLI.ui.ask "\e[0;32m [y]es or [n]o?\e[0m\n"

# Abort if required
unless response.to_s == 'y'
  puts "\e[0;31m Aborting......\e[0m\n"
  exit
end

Voila! You have pretty prompting to confirm what you're doing.

Want to see more? I've posted a quick overview on using multistage deployments to this gist: https://gist.github.com/4667228