Sha256: 6ffbc00712aa157834e4542652d8ddbcd6979306454d22cc6d5c1e30062a14c6

Contents?: true

Size: 1.88 KB

Versions: 22

Compression:

Stored size: 1.88 KB

Contents

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
le1t0-capistrano-2.5.18.024 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.023 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.022 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.021 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.020 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.019 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.018 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.017 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.016 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.015 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.014 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.013 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.012 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.011 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.010 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.009 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.008 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.007 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.006 lib/capistrano/multistage.rb
le1t0-capistrano-2.5.18.005 lib/capistrano/multistage.rb