capistrano-strategy-copy-partial 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-strategy-copy-partial.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # capistrano-strategy-copy-partial
2
+
3
+ capistrano-strategy-copy-partial is [capistrano](https://github.com/capistrano/capistrano) extension that add strategy for deploy only part (subdirectory) of repository
4
+
5
+ ## Installation
6
+
7
+ Add to `Gemfile`:
8
+
9
+ gem "capistrano-strategy-copy-partial"
10
+
11
+ ## Configuration
12
+
13
+ Use next options:
14
+
15
+ set :deploy_via, :copy_partial
16
+ set :copy_partial, "path/for/deploy"
17
+ set :copy_strategy, :export
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-strategy-copy-partial"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-strategy-copy-partial"
7
+ s.version = CapistranoStrategyCopyPartial::VERSION
8
+ s.authors = ["Maxim Bondaruk"]
9
+ s.email = ["maxim.bondaruk@railsware.com"]
10
+ s.homepage = "http://github.com/railsware/capistrano-strategy-copy-partial"
11
+ s.summary = %q{Capistrano deploy strategy to transfer subdirectory of repository}
12
+
13
+ s.rubyforge_project = "capistrano-strategy-copy-partial"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "capistrano", ">=2.5.5"
21
+ end
@@ -0,0 +1,3 @@
1
+ require "capistrano-strategy-copy-partial/version"
2
+ require "capistrano/recipes/deploy/strategy/copy_partial"
3
+
@@ -0,0 +1,3 @@
1
+ module CapistranoStrategyCopyPartial
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,116 @@
1
+ require 'capistrano/recipes/deploy/strategy/copy'
2
+ require 'tempfile' # Dir.tmpdir
3
+
4
+ class Capistrano::Deploy::Strategy::CopyPartial < Capistrano::Deploy::Strategy::Copy
5
+
6
+ #
7
+ # set :copy_partial, 'subdir/of/project'
8
+ #
9
+ def deploy!
10
+ if copy_cache
11
+ if File.exists?(copy_cache)
12
+ logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
13
+ system(source.sync(revision, copy_cache))
14
+ else
15
+ logger.debug "preparing local cache at #{copy_cache}"
16
+ system(source.checkout(revision, copy_cache))
17
+ end
18
+
19
+ logger.debug "copying cache to deployment staging area #{destination}"
20
+ Dir.chdir(copy_cache) do
21
+ FileUtils.mkdir_p(destination)
22
+ queue = Dir.glob("*", File::FNM_DOTMATCH)
23
+ while queue.any?
24
+ item = queue.shift
25
+ name = File.basename(item)
26
+
27
+ next if name == "." || name == ".."
28
+ next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
29
+
30
+ if File.symlink?(item)
31
+ FileUtils.ln_s(File.readlink(File.join(copy_cache, item)), File.join(destination, item))
32
+ elsif File.directory?(item)
33
+ queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
34
+ FileUtils.mkdir(File.join(destination, item))
35
+ else
36
+ FileUtils.ln(File.join(copy_cache, item), File.join(destination, item))
37
+ end
38
+ end
39
+ end
40
+ else
41
+ logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
42
+ system(command)
43
+
44
+ if copy_exclude.any?
45
+ logger.debug "processing exclusions..."
46
+ if copy_exclude.any?
47
+ copy_exclude.each do |pattern|
48
+ delete_list = Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)
49
+ # avoid the /.. trap that deletes the parent directories
50
+ delete_list.delete_if { |dir| dir =~ /\/\.\.$/ }
51
+ FileUtils.rm_rf(delete_list.compact)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ File.open(File.join(destination_partial, "REVISION"), "w") { |f| f.puts(revision) }
58
+
59
+ logger.trace "compressing #{destination_partial} to #{filename}"
60
+ Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename), copy_partial).join(" ")) }
61
+
62
+ upload(filename, remote_filename)
63
+ if compression.partial_command && !copy_partial.empty?
64
+ run "cd #{configuration[:releases_path]} && mkdir #{File.basename(destination)} && cd #{File.basename(destination)} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
65
+ else
66
+ run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
67
+ end
68
+ ensure
69
+ FileUtils.rm filename rescue nil
70
+ FileUtils.rm_rf destination rescue nil
71
+ end
72
+
73
+ private
74
+
75
+ def copy_partial
76
+ @copy_partial ||= configuration.fetch(:copy_partial, '')
77
+ end
78
+
79
+ def destination_partial
80
+ @destination_partial ||= File.join(destination, copy_partial)
81
+ end
82
+
83
+ # A struct for representing the specifics of a compression type.
84
+ # Commands are arrays, where the first element is the utility to be
85
+ # used to perform the compression or decompression.
86
+ Compression = Struct.new(:extension, :compress_command, :decompress_command, :partial_command)
87
+
88
+ # The compression method to use, defaults to :gzip.
89
+ def compression
90
+ type = configuration[:copy_compression] || :gzip
91
+ case type
92
+ when :gzip, :gz then Compression.new("tar.gz", %w(tar czf), %w(tar xzf), "-C")
93
+ when :bzip2, :bz2 then Compression.new("tar.bz2", %w(tar cjf), %w(tar xjf), "-C")
94
+ when :zip then Compression.new("zip", %w(zip -qr), %w(unzip -q), nil)
95
+ else raise ArgumentError, "invalid compression type #{type.inspect}"
96
+ end
97
+ end
98
+
99
+ # Returns the command necessary to compress the given directory
100
+ # into the given file.
101
+ def compress(directory, file, partial_dir='')
102
+ if compression.partial_command && !partial_dir.empty?
103
+ compression.compress_command + [file, compression.partial_command, "#{directory}/#{partial_dir}", './']
104
+ else
105
+ compression.compress_command + [file, directory]
106
+ end
107
+ end
108
+
109
+ # Returns the command necessary to decompress the given file,
110
+ # relative to the current working directory. It must also
111
+ # preserve the directory structure in the file.
112
+ def decompress(file)
113
+ compression.decompress_command + [file]
114
+ end
115
+
116
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-strategy-copy-partial
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Maxim Bondaruk
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-20 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 2
32
+ - 5
33
+ - 5
34
+ version: 2.5.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description:
38
+ email:
39
+ - maxim.bondaruk@railsware.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - capistrano-strategy-copy-partial.gemspec
52
+ - lib/capistrano-strategy-copy-partial.rb
53
+ - lib/capistrano-strategy-copy-partial/version.rb
54
+ - lib/capistrano/recipes/deploy/strategy/copy_partial.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/railsware/capistrano-strategy-copy-partial
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project: capistrano-strategy-copy-partial
85
+ rubygems_version: 1.6.2
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Capistrano deploy strategy to transfer subdirectory of repository
89
+ test_files: []
90
+