From affb615a8a5da2d41383741fd51871261550925e Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 24 Aug 2005 15:15:23 +0000 Subject: SwitchTower: use a timestamp as the release name, instead of the revision number. Various tweaks and fixes to the supported scm modules. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2046 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- switchtower/lib/switchtower/actor.rb | 2 +- switchtower/lib/switchtower/configuration.rb | 13 +++++++++---- switchtower/lib/switchtower/scm/base.rb | 18 ++++++++++++++++++ switchtower/lib/switchtower/scm/cvs.rb | 18 +++++------------- switchtower/lib/switchtower/scm/darcs.rb | 25 +++---------------------- switchtower/lib/switchtower/scm/subversion.rb | 14 +++++--------- 6 files changed, 41 insertions(+), 49 deletions(-) create mode 100644 switchtower/lib/switchtower/scm/base.rb (limited to 'switchtower/lib') diff --git a/switchtower/lib/switchtower/actor.rb b/switchtower/lib/switchtower/actor.rb index 012f4a1f55..a74ea95a24 100644 --- a/switchtower/lib/switchtower/actor.rb +++ b/switchtower/lib/switchtower/actor.rb @@ -248,7 +248,7 @@ module SwitchTower buffer << out if str == :out raise "could not determine releases #{out.inspect}" if str == :err end - @releases = buffer.split.map { |i| i.to_i }.sort + @releases = buffer.split.sort end @releases diff --git a/switchtower/lib/switchtower/configuration.rb b/switchtower/lib/switchtower/configuration.rb index 937618a727..c6ddff5568 100644 --- a/switchtower/lib/switchtower/configuration.rb +++ b/switchtower/lib/switchtower/configuration.rb @@ -26,12 +26,17 @@ module SwitchTower # The load paths used for locating recipe files. attr_reader :load_paths + # The time (in UTC) at which this configuration was created, used for + # determining the release path. + attr_reader :now + def initialize(actor_class=Actor) #:nodoc: @roles = Hash.new { |h,k| h[k] = [] } @actor = actor_class.new(self) @logger = Logger.new @load_paths = [".", File.join(File.dirname(__FILE__), "recipes")] @variables = {} + @now = Time.now.utc set :application, nil set :repository, nil @@ -165,10 +170,10 @@ module SwitchTower File.join(deploy_to, shared_dir) end - # Return the full path to the named revision (defaults to the most current - # revision in the repository). - def release_path(revision=source.latest_revision) - File.join(releases_path, revision) + # Return the full path to the named release. If a release is not specified, + # +now+ is used (the time at which the configuration was created). + def release_path(release=now.strftime("%Y%m%d%H%M%S")) + File.join(releases_path, release) end def respond_to?(sym) #:nodoc: diff --git a/switchtower/lib/switchtower/scm/base.rb b/switchtower/lib/switchtower/scm/base.rb new file mode 100644 index 0000000000..4e079d2758 --- /dev/null +++ b/switchtower/lib/switchtower/scm/base.rb @@ -0,0 +1,18 @@ +module SwitchTower + module SCM + + # The ancestor class of the various SCM module implementations. + class Base + attr_reader :configuration + + def initialize(configuration) #:nodoc: + @configuration = configuration + end + + def checkout(actor) + raise NotImplementedError, "subclasses must implement checkout" + end + end + + end +end diff --git a/switchtower/lib/switchtower/scm/cvs.rb b/switchtower/lib/switchtower/scm/cvs.rb index a4c588e611..db3eae9261 100644 --- a/switchtower/lib/switchtower/scm/cvs.rb +++ b/switchtower/lib/switchtower/scm/cvs.rb @@ -1,4 +1,5 @@ require 'time' +require 'switchtower/scm/base' module SwitchTower module SCM @@ -21,13 +22,7 @@ module SwitchTower # Also, you can specify the CVS_RSH variable to use on the remote machine(s) # via the :cvs_rsh variable. This defaults to the value of the # CVS_RSH environment variable locally, or if it is not set, to "ssh". - class Cvs - attr_reader :configuration - - def initialize(configuration) #:nodoc: - @configuration = configuration - end - + class Cvs < Base # Return a string representing the date of the last revision (CVS is # seriously retarded, in that it does not give you a way to query when # the last revision was made to the repository, so this is a fairly @@ -37,7 +32,7 @@ module SwitchTower configuration.logger.debug "querying latest revision..." @latest_revision = cvs_log(configuration.local). split(/\r?\n/). - grep(/^date: (.*?);/) { Time.parse($1).strftime("%FT%T") }. + grep(/^date: (.*?);/) { Time.parse($1).strftime("%F %T") }. sort. last end @@ -49,12 +44,9 @@ module SwitchTower cvs_rsh = configuration[:cvs_rsh] || ENV['CVS_RSH'] || "ssh" command = <<-CMD - if [[ -d #{actor.release_path} ]]; then - cd #{actor.release_path}; - CVS_RSH="#{cvs_rsh}" #{cvs} -q up -d#{latest_revision}; - else + if [[ ! -d #{actor.release_path} ]]; then cd #{configuration.releases_path}; - CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -q co -D #{latest_revision} -d #{latest_revision} #{actor.application}; + CVS_RSH="#{cvs_rsh}" #{cvs} -d #{configuration.repository} -Q co -D "#{latest_revision}" -d #{File.basename(actor.release_path)} #{actor.application}; fi CMD actor.run(command) do |ch, stream, out| diff --git a/switchtower/lib/switchtower/scm/darcs.rb b/switchtower/lib/switchtower/scm/darcs.rb index 93735446ed..acaa006951 100644 --- a/switchtower/lib/switchtower/scm/darcs.rb +++ b/switchtower/lib/switchtower/scm/darcs.rb @@ -1,4 +1,4 @@ -require 'time' +require 'switchtower/scm/base' module SwitchTower module SCM @@ -13,26 +13,7 @@ module SwitchTower # executable on the remote machine: # # set :darcs, "/opt/local/bin/darcs" - class Darcs - attr_reader :configuration - - def initialize(configuration) #:nodoc: - @configuration = configuration - end - - # Return an integer identifying the last known revision (patch) in the - # darcs repository. (This integer is currently the 14-digit timestamp - # of the last known patch.) - def latest_revision - unless @latest_revision - configuration.logger.debug "querying latest revision..." - @latest_revision = Time. - parse(`darcs changes --last 1 --repo #{configuration.repository}`). - strftime("%Y%m%d%H%M%S").to_i - end - @latest_revision - end - + class Darcs < Base # Check out (on all servers associated with the current task) the latest # revision. Uses the given actor instance to execute the command. def checkout(actor) @@ -40,7 +21,7 @@ module SwitchTower command = <<-CMD if [[ ! -d #{actor.release_path} ]]; then - #{darcs} get --set-scripts-executable #{configuration.repository} #{actor.release_path}; + #{darcs} get -q --set-scripts-executable #{configuration.repository} #{actor.release_path}; fi CMD actor.run(command) diff --git a/switchtower/lib/switchtower/scm/subversion.rb b/switchtower/lib/switchtower/scm/subversion.rb index cc5d78c3e6..368c965dec 100644 --- a/switchtower/lib/switchtower/scm/subversion.rb +++ b/switchtower/lib/switchtower/scm/subversion.rb @@ -1,3 +1,5 @@ +require 'switchtower/scm/base' + module SwitchTower module SCM @@ -12,13 +14,7 @@ module SwitchTower # executable on the remote machine: # # set :svn, "/opt/local/bin/svn" - class Subversion - attr_reader :configuration - - def initialize(configuration) #:nodoc: - @configuration = configuration - end - + class Subversion < Base # Return an integer identifying the last known revision in the svn # repository. (This integer is currently the revision number.) If latest # revision does not exist in the given repository, this routine will @@ -64,9 +60,9 @@ module SwitchTower prefix ch.send_data "yes\n" elsif out =~ %r{passphrase} - message = "subversion needs your key's passphrase and cannot proceed" + message = "subversion needs your key's passphrase, sending empty string" actor.logger.info message, prefix - raise message + ch.send_data "\n" elsif out =~ %r{The entry \'(\w+)\' is no longer a directory} message = "subversion can't update because directory '#{$1}' was replaced. Please add it to svn:ignore." actor.logger.info message, prefix -- cgit v1.2.3