Last active
September 28, 2021 12:24
-
-
Save gamecreature/f91adf16e7d5af43f03cf5bde9135e24 to your computer and use it in GitHub Desktop.
A snippet for deploying to multiple servers at once
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load DSL and set up stages | |
require 'capistrano/setup' | |
# Include default deployment tasks | |
require 'capistrano/deploy' | |
require "capistrano/scm/git" | |
install_plugin Capistrano::SCM::Git | |
# -8<-------8<-------8<-------8<-------8<-------8<------ | |
# include from here, after the git plugin | |
stage = ARGV[0] | |
multi_deployment = ['production', 'staging'].include?(stage) | |
if multi_deployment | |
args = ARGV[1..-1] | |
puts "MULTI DEPLOYMENT: #{stage}" | |
puts "=" * 60 | |
puts "" | |
files = Dir.glob("config/deploy/#{stage}*.rb").sort | |
files.each do |file| | |
name = file.sub('config/deploy/', '').sub('.rb', '') | |
next if name == stage | |
cmd = ['bundle', 'exec', 'cap', name] + args | |
puts cmd.join(' ') | |
puts "-" * 60 | |
system(*cmd) | |
puts "" | |
end | |
exit | |
end | |
# ->8------->8------->8------->8------->8------->8------->8------ | |
## rest of normal capile ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the snippet above it is possible to have multiple production/staging servers...
And makes it easy to deploy to all of them or per-server.
For example
You can deploy ALL servers of a given environemtn
Or a specific server individually