Sha256: 74cc3facfae9a56cdfcdc454c21c7a3bb4b4443ece89cd66137a292cd5b23b88

Contents?: true

Size: 1.9 KB

Versions: 12

Compression:

Stored size: 1.9 KB

Contents

require 'capistrano/recipes/deploy/strategy/remote'

module Capistrano
  module Deploy
    module Strategy

      # Implements the deployment strategy that keeps a cached checkout of
      # the source code on each remote server. Each deploy simply updates the
      # cached checkout, and then does a copy from the cached copy to the
      # final deployment location.
      class RemoteCache < Remote
        # Executes the SCM command for this strategy and writes the REVISION
        # mark file to each host.
        def deploy!
          update_repository_cache
          copy_repository_cache
        end

        def check!
          super.check do |d|
            d.remote.command("rsync") unless copy_exclude.empty?
            d.remote.writable(shared_path)
          end
        end

        private

          def repository_cache
            File.join(shared_path, configuration[:repository_cache] || "cached-copy")
          end

          def update_repository_cache
            logger.trace "updating the cached checkout on all servers"
            command = "if [ -d #{repository_cache} ]; then " +
              "#{source.sync(revision, repository_cache)}; " +
              "else #{source.checkout(revision, repository_cache)}; fi"
            scm_run(command)
          end

          def copy_repository_cache
            logger.trace "copying the cached version to #{configuration[:release_path]}"
            if copy_exclude.empty? 
              run "cp -RPp #{repository_cache} #{configuration[:release_path]} && #{mark}"
            else
              exclusions = copy_exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
              run "rsync -lrpt #{exclusions} #{repository_cache}/* #{configuration[:release_path]} && #{mark}"
            end
          end
          
          def copy_exclude
            @copy_exclude ||= Array(configuration.fetch(:copy_exclude, []))
          end
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
capistrano-2.5.22 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.28 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.27 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.26 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.25 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.24 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.23 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.22 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
HeSYINUvSBZfxqA-capistrano-2.5.21 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
capistrano-2.6.0 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
capistrano-2.5.21 lib/capistrano/recipes/deploy/strategy/remote_cache.rb
capistrano-2.5.20 lib/capistrano/recipes/deploy/strategy/remote_cache.rb