Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6500

Show
Ignore:
Timestamp:
04/02/07 22:44:21 (1 year ago)
Author:
minam
Message:

allow custom dependencies to be declared, which deploy:check will verify

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/lib/capistrano/recipes/deploy.rb

    r6497 r6500  
    4848 
    4949set(:run_method)        { fetch(:use_sudo, true) ? :sudo : :run } 
     50 
     51# ========================================================================= 
     52# These are helper methods that will be available to your recipes. 
     53# ========================================================================= 
     54 
     55# Auxiliary helper method for the `deploy:check' task. Lets you set up your 
     56# own dependencies. 
     57def depend(location, type, *args) 
     58  deps = fetch(:dependencies, {}) 
     59  deps[location] ||= {} 
     60  deps[location][type] ||= [] 
     61  deps[location][type] << args 
     62  set :dependencies, deps 
     63end 
    5064 
    5165# ========================================================================= 
     
    298312    be incorrect or missing. This is good for making sure a deploy has a \ 
    299313    chance of working before you actually run `cap deploy'. 
     314 
     315    You can define your own dependencies, as well, using the `depend' method: 
     316 
     317      depend :remote, :gem, "tzinfo", ">=0.3.3" 
     318      depend :local, :command, "svn" 
     319      depend :remote, :directory, "/u/depot/files" 
    300320  DESC 
    301321  task :check, :except => { :no_release => true } do 
    302322    dependencies = strategy.check! 
     323 
     324    other = fetch(:dependencies, {}) 
     325    other.each do |location, types| 
     326      types.each do |type, calls| 
     327        if type == :gem 
     328          dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command") 
     329        end 
     330 
     331        calls.each do |args| 
     332          dependencies.send(location).send(type, *args) 
     333        end 
     334      end 
     335    end 
     336 
    303337    if dependencies.pass? 
    304338      puts "You appear to have all necessary dependencies installed" 
  • tools/capistrano/lib/capistrano/recipes/deploy/local_dependency.rb

    r6487 r6500  
    1010      end 
    1111 
    12       def expects_in_path(command) 
     12      def command(command) 
    1313        @message ||= "`#{command}' could not be found in the path on the local host" 
    1414        @success = find_in_path(command) 
  • tools/capistrano/lib/capistrano/recipes/deploy/remote_dependency.rb

    r6487 r6500  
    1010      end 
    1111 
    12       def expect_directory(path
     12      def directory(path, options={}
    1313        @message ||= "`#{path}' is not a directory" 
    14         try("test -d #{path}"
     14        try("test -d #{path}", options
    1515        self 
    1616      end 
    1717 
    18       def expect_writable(path
     18      def writable(path, options={}
    1919        @message ||= "`#{path}' is not writable" 
    20         try("test -w #{path}"
     20        try("test -w #{path}", options
    2121        self 
    2222      end 
    2323 
    24       def expects_in_path(command
     24      def command(command, options={}
    2525        @message ||= "`#{command}' could not be found in the path" 
    26         try("type -p #{command}") 
     26        try("type -p #{command}", options) 
     27        self 
     28      end 
     29 
     30      def gem(name, version, options={}) 
     31        @message ||= "gem `#{name}' #{version} could not be found" 
     32        gem_cmd = configuration.fetch(:gem_command, "gem") 
     33        try("#{gem_cmd} specification --version \"#{version}\" #{name} 2>&1 | awk 'BEGIN { s = 0 }; /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'", options) 
    2734        self 
    2835      end 
     
    4552    private 
    4653 
    47       def try(command
     54      def try(command, options
    4855        return unless @success # short-circuit evaluation 
    49         configuration.run(command) do |ch,stream,out| 
     56        configuration.run(command, options) do |ch,stream,out| 
    5057          warn "#{ch[:host]}: #{out}" if stream == :err 
    5158        end 
  • tools/capistrano/lib/capistrano/recipes/deploy/strategy/base.rb

    r6487 r6500  
    2929        def check! 
    3030          Dependencies.new(configuration) do |d| 
    31             d.remote.expect_directory(configuration[:releases_path]).or("`#{configuration[:releases_path]}' does not exist. Please run `cap deploy:setup'.") 
    32             d.remote.expect_writable(configuration[:deploy_to]).or("You do not have permissions to write to `#{configuration[:deploy_to]}'.") 
    33             d.remote.expect_writable(configuration[:releases_path]).or("You do not have permissions to write to `#{configuration[:releases_path]}'.") 
     31            d.remote.directory(configuration[:releases_path]).or("`#{configuration[:releases_path]}' does not exist. Please run `cap deploy:setup'.") 
     32            d.remote.writable(configuration[:deploy_to]).or("You do not have permissions to write to `#{configuration[:deploy_to]}'.") 
     33            d.remote.writable(configuration[:releases_path]).or("You do not have permissions to write to `#{configuration[:releases_path]}'.") 
    3434          end 
    3535        end 
  • tools/capistrano/lib/capistrano/recipes/deploy/strategy/copy.rb

    r6487 r6500  
    4141        def check! 
    4242          super.check do |d| 
    43             d.local.expects_in_path(source.command) 
    44             d.local.expects_in_path(compress(nil, nil).first) 
    45             d.remote.expects_in_path(decompress(nil).first) 
     43            d.local.command(source.command) 
     44            d.local.command(compress(nil, nil).first) 
     45            d.remote.command(decompress(nil).first) 
    4646          end 
    4747        end