Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Initial version of fast_remote_cache plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Jun 2, 2008
0 parents commit af7214c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Include hook code here
29 changes: 29 additions & 0 deletions lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'capistrano/recipes/deploy/strategy/remote_cache'

class Capistrano::Deploy::Strategy::FastRemoteCache < Capistrano::Deploy::Strategy::RemoteCache
def check!
super.check do |d|
d.remote.command(configuration.fetch(:ruby, "ruby"))
d.remote.directory(bin_path)
d.remote.file(File.join(bin_path, "copy.rb"))
end
end

def setup!
run "mkdir -p #{bin_path}"
upload(File.join(File.dirname(__FILE__), "utilities", "copy.rb"), File.join(bin_path, "copy.rb"))
end

private

def bin_path
@bin_path ||= File.join(configuration[:shared_path], "bin")
end

def copy_repository_cache
logger.trace "copying the cached version to #{configuration[:release_path]}"
ruby = configuration.fetch(:ruby, "ruby")
excludes = Array(configuration[:copy_exclude]).join(" ")
run "#{ruby} #{File.join(bin_path, 'copy.rb')} #{repository_cache} #{configuration[:release_path]} #{excludes} && #{mark}"
end
end
35 changes: 35 additions & 0 deletions lib/capistrano/recipes/deploy/strategy/utilities/copy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'fileutils'

verbose = false

from = ARGV.shift or abort "need source directory"
to = ARGV.shift or abort "need target directory"

exclude = ARGV

from = File.expand_path(from)
to = File.expand_path(to)

Dir.chdir(from) do
FileUtils.mkdir_p(to)
queue = Dir.glob("*", File::FNM_DOTMATCH)
while queue.any?
item = queue.shift
name = File.basename(item)

next if name == "." || name == ".."
next if exclude.any? { |pattern| File.fnmatch(pattern, item) }

source = File.join(from, item)
target = File.join(to, item)

if File.symlink?(item)
FileUtils.ln_s(File.readlink(source), target)
elsif File.directory?(item)
queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
FileUtils.mkdir_p(target, :mode => File.stat(item).mode)
else
FileUtils.ln(source, target)
end
end
end
21 changes: 21 additions & 0 deletions recipes/fast_remote_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))

namespace :fast_remote_cache do

desc <<-DESC
Perform any setup required by fast_remote_cache. This is called
automatically after deploy:setup, but may be invoked manually to configure
a new machine. It is also necessary to invoke when you are switching to the
fast_remote_cache strategy for the first time.
DESC
task :setup do
if deploy_via == :fast_remote_cache
strategy.setup!
else
logger.warn "you're including the fast_remote_cache strategy, but not using it!"
end
end

end

after "deploy:setup", "fast_remote_cache:setup"

0 comments on commit af7214c

Please sign in to comment.