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

Changeset 6487

Show
Ignore:
Timestamp:
03/29/07 04:48:34 (1 year ago)
Author:
minam
Message:

Add deploy:check test for verifying that dependencies are in order for deploying

Files:

Legend:

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

    r6468 r6487  
    149149servers. Any file or directory starting with a '.' character will be ignored. 
    150150 
    151   $ cap deploy:update_files FILES=templates,controller.rb" 
    152   task :update_files, :except => { :no_release => true } do 
     151  $ cap deploy:upload FILES=templates,controller.rb" 
     152  task :upload, :except => { :no_release => true } do 
    153153    files = (ENV["FILES"] || ""). 
    154154      split(","). 
     
    256256  end 
    257257 
     258desc "Test deployment dependencies. Checks things like directory permissions, \ 
     259necessary utilities, and so forth, reporting on the things that appear to be \ 
     260incorrect or missing. This is good for making sure a deploy has a chance of \ 
     261working before you actually run `cap deploy'!" 
     262  task :check, :except => { :no_release => true } do 
     263    dependencies = strategy.check! 
     264    if dependencies.pass? 
     265      puts "You appear to have all necessary dependencies installed" 
     266    else 
     267      puts "The following dependencies failed. Please check them and try again:" 
     268      dependencies.reject { |d| d.pass? }.each do |d| 
     269        puts "--> #{d.message}" 
     270      end 
     271    end 
     272  end 
     273 
    258274  namespace :pending do 
    259275desc "Displays the `diff' since your last deploy. This is useful if you want \ 
  • tools/capistrano/lib/capistrano/recipes/deploy/scm/base.rb

    r6463 r6487  
    8585        end 
    8686 
     87        # Returns the name of the command-line utility for this SCM. It first 
     88        # looks at the :scm_command variable, and if it does not exist, it 
     89        # then falls back to whatever was defined by +default_command+. 
     90        def command 
     91          configuration[:scm_command] || default_command 
     92        end 
     93 
    8794        private 
    8895 
     
    106113          end 
    107114 
    108           # Returns the name of the command-line utility for this SCM. It first 
    109           # looks at the :scm_command variable, and if it does not exist, it 
    110           # then falls back to whatever was defined by +default_command+. 
    111           def command 
    112             configuration[:scm_command] || default_command 
    113           end 
    114  
    115115          # A convenience method for accessing the declared repository value. 
    116116          def repository 
  • tools/capistrano/lib/capistrano/recipes/deploy/strategy/base.rb

    r6463 r6487  
     1require 'capistrano/recipes/deploy/dependencies' 
     2 
    13module Capistrano 
    24  module Deploy 
     
    2325        end 
    2426 
     27        # Performs a check on the remote hosts to determine whether everything 
     28        # is setup such that a deploy could succeed. 
     29        def check! 
     30          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]}'.") 
     34          end 
     35        end 
     36           
    2537        protected 
    2638 
  • tools/capistrano/lib/capistrano/recipes/deploy/strategy/copy.rb

    r6463 r6487  
    3737          FileUtils.rm filename rescue nil 
    3838          FileUtils.rm_rf destination rescue nil 
     39        end 
     40 
     41        def check! 
     42          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) 
     46          end 
    3947        end 
    4048 
     
    93101 
    94102          # Returns the command necessary to compress the given directory 
    95           # into the given file. 
     103          # into the given file. The command is returned as an array, where 
     104          # the first element is the utility to be used to perform the compression. 
    96105          def compress(directory, file) 
    97106            case compression 
    98             when :gzip, :gz   then "tar czf #{file} #{directory}" 
    99             when :bzip2, :bz2 then "tar cjf #{file} #{directory}" 
    100             when :zip         then "zip -qr #{file} #{directory}" 
     107            when :gzip, :gz   then ["tar", "czf", file, directory] 
     108            when :bzip2, :bz2 then ["tar", "cjf", file, directory] 
     109            when :zip         then ["zip", "-qr", file, directory] 
     110            else raise ArgumentError, "invalid compression type #{compression.inspect}" 
    101111            end 
    102112          end 
     
    104114          # Returns the command necessary to decompress the given file, 
    105115          # relative to the current working directory. It must also 
    106           # preserve the directory structure in the file. 
     116          # preserve the directory structure in the file. The command is returned 
     117          # as an array, where the first element is the utility to be used to 
     118          # perform the decompression. 
    107119          def decompress(file) 
    108120            case compression 
    109             when :gzip, :gz   then "tar xzf #{file}" 
    110             when :bzip2, :bz2 then "tar xjf #{file}" 
    111             when :zip         then "unzip -q #{file}" 
     121            when :gzip, :gz   then ["tar", "xzf", file] 
     122            when :bzip2, :bz2 then ["tar", "xjf", file] 
     123            when :zip         then ["unzip", "-q", file] 
     124            else raise ArgumentError, "invalid compression type #{compression.inspect}" 
    112125            end 
    113126          end 
  • tools/capistrano/lib/capistrano/recipes/deploy/strategy/remote.rb

    r6463 r6487  
    1414        def deploy! 
    1515          scm_run "#{command} && #{mark}" 
     16        end 
     17 
     18        def check! 
     19          result = super 
     20          test("type -p #{source.command}", "could not find `#{source.command}'") && result 
    1621        end 
    1722 
  • tools/capistrano/setup.rb

    r2525 r6487  
    11791179 
    11801180  def ruby_scripts 
    1181     collect_filenames_auto().select {|n| /\.r(b|html)\z/ =~ n} 
     1181    collect_filenames_auto().select {|n| /\.(r(b|html)|txt)\z/ =~ n} 
    11821182  end 
    11831183