This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of fast_remote_cache plugin
- Loading branch information
0 parents
commit af7214c
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Include hook code here |
29 changes: 29 additions & 0 deletions
29
lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |