forked from capistrano/capistrano
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bundle capistrano-ext/multistage with the main Gem.
Almost everybody uses the multistage extension, and having it in a sepate gem has never really made that much sense. With this commit you can use multistage by requiring `capistrano/ext/multistage`. The Gem `capistrano-ext` no longer required.
- Loading branch information
1 parent
c46cefb
commit eed1a6e
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'fileutils' | ||
|
||
unless Capistrano::Configuration.respond_to?(:instance) | ||
abort "capistrano/ext/multistage requires Capistrano 2" | ||
end | ||
|
||
Capistrano::Configuration.instance.load do | ||
location = fetch(:stage_dir, "config/deploy") | ||
|
||
unless exists?(:stages) | ||
set :stages, Dir["#{location}/*.rb"].map { |f| File.basename(f, ".rb") } | ||
end | ||
|
||
stages.each do |name| | ||
desc "Set the target stage to `#{name}'." | ||
task(name) do | ||
set :stage, name.to_sym | ||
load "#{location}/#{stage}" | ||
end | ||
end | ||
|
||
on :load do | ||
if stages.include?(ARGV.first) | ||
# Execute the specified stage so that recipes required in stage can contribute to task list | ||
find_and_execute_task(ARGV.first) if ARGV.any?{ |option| option =~ /-T|--tasks|-e|--explain/ } | ||
else | ||
# Execute the default stage so that recipes required in stage can contribute tasks | ||
find_and_execute_task(default_stage) if exists?(:default_stage) | ||
end | ||
end | ||
|
||
namespace :multistage do | ||
desc "[internal] Ensure that a stage has been selected." | ||
task :ensure do | ||
if !exists?(:stage) | ||
if exists?(:default_stage) | ||
logger.important "Defaulting to `#{default_stage}'" | ||
find_and_execute_task(default_stage) | ||
else | ||
abort "No stage specified. Please specify one of: #{stages.join(', ')} (e.g. `cap #{stages.first} #{ARGV.last}')" | ||
end | ||
end | ||
end | ||
|
||
desc "Stub out the staging config files." | ||
task :prepare do | ||
FileUtils.mkdir_p(location) | ||
stages.each do |name| | ||
file = File.join(location, name + ".rb") | ||
unless File.exists?(file) | ||
File.open(file, "w") do |f| | ||
f.puts "# #{name.upcase}-specific deployment configuration" | ||
f.puts "# please put general deployment config in config/deploy.rb" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
on :start, "multistage:ensure", :except => stages + ['multistage:prepare'] | ||
|
||
end |