diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..3c19a74 --- /dev/null +++ b/init.rb @@ -0,0 +1 @@ +# Include hook code here diff --git a/lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb b/lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb new file mode 100644 index 0000000..d0044ac --- /dev/null +++ b/lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb @@ -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 diff --git a/lib/capistrano/recipes/deploy/strategy/utilities/copy.rb b/lib/capistrano/recipes/deploy/strategy/utilities/copy.rb new file mode 100644 index 0000000..07d2e0b --- /dev/null +++ b/lib/capistrano/recipes/deploy/strategy/utilities/copy.rb @@ -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 diff --git a/recipes/fast_remote_cache.rb b/recipes/fast_remote_cache.rb new file mode 100644 index 0000000..ce1ac05 --- /dev/null +++ b/recipes/fast_remote_cache.rb @@ -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" \ No newline at end of file