capistrano-rsync-remote-cache 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a192c1b61afd3e96c2e83cf8363a47995eec949b
4
+ data.tar.gz: 86566b4259ff53f584ae0613c0c2ff4974353087
5
+ SHA512:
6
+ metadata.gz: 39ded65f0305a147d7928c10d220dd10c84693b11a9611d30646c4d93946d422a59dc23e86729748ac1384688a6616a8b68e4fa12d8223d6a365e0f140e2dafc
7
+ data.tar.gz: 11b17b09541e9691cbe78a3d8f22dc9cd1d5145dbbc39923ac7767338b1342018323083e18c532c701c25a5cf654ebef5da32b958e9e47297eed1bedf93b8a93
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-scm-passthrough.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = Capistrano 2.0 rsync_remote_cache Deployment Strategy
2
+
3
+ == Description
4
+
5
+ This gem provides a deployment strategy for Capistrano which combines the
6
+ <tt>rsync</tt> command with a remote cache, allowing fast deployments from SCM
7
+ repositories behind firewalls.
8
+
9
+ == Aim
10
+
11
+ The original gem is outdated. In this gem, I have merged all the pull requests
12
+ that were interesting, such as rsync in parallel, rsh parameters, etc.
13
+
14
+ == Original gem
15
+
16
+ For the original gem, visit: https://github.com/vigetlabs/capistrano_rsync_with_remote_cache
17
+
18
+ == Installation
19
+
20
+ gem install capistrano-rsync-remote-cache
21
+
22
+ == Usage
23
+
24
+ To use this deployment strategy, add this line to your <tt>deploy.rb</tt> file:
25
+
26
+ set :deploy_via, :rsync_remote_cache
27
+
28
+ If you want to enable the parallel deployment:
29
+
30
+ set :rsync_in_parallel, true
31
+
32
+ If you want to tune the number of threads:
33
+
34
+ set :rsync_concurrency, 8
35
+
36
+ By default, the deployments spawns 8 threads.
37
+
38
+ == Under the Hood
39
+
40
+ This strategy maintains two cache directories:
41
+
42
+ * The local cache directory is a checkout from the SCM repository. The local
43
+ cache directory is specified with the <tt>:local_cache</tt> variable in the
44
+ configuration. If not specified, it will default to <tt>.rsync_cache</tt>
45
+ in the same directory as the Capfile.
46
+
47
+ * The remote cache directory is an <tt>rsync</tt> copy of the local cache directory.
48
+ The remote cache directory is specified with the <tt>:repository_cache</tt> variable
49
+ in the configuration (this name comes from the <tt>:remote_cache</tt> strategy that
50
+ ships with Capistrano, and has been maintained for compatibility.) If not
51
+ specified, it will default to <tt>shared/cached-copy</tt> (again, for compatibility
52
+ with remote_cache.)
53
+
54
+ Deployment happens in three major steps. First, the local cache directory is
55
+ processed. There are three possibilities:
56
+
57
+ * If the local cache does not exist, it is created with a checkout of the
58
+ revision to be deployed.
59
+ * If the local cache exists and matches the <tt>:repository</tt> variable, it is
60
+ updated to the revision to be deployed.
61
+ * If the local cache exists and does not match the <p>:repository</p> variable,
62
+ the local cache is purged and recreated with a checkout of the revision
63
+ to be deployed.
64
+ * If the local cache exists but is not a directory, an exception is raised
65
+
66
+ Second, <tt>rsync</tt> runs on the local side to sync the remote cache to the local
67
+ cache. When the <tt>rsync</tt> is complete, the remote cache should be an exact
68
+ replica of the local cache.
69
+
70
+ Finally, a copy of the remote cache is made in the appropriate release
71
+ directory. The end result is the same as if the code had been checked out
72
+ directly on the remote server, as in the default strategy.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "capistrano-rsync-remote-cache"
5
+ gem.version = "1.0.0"
6
+ gem.authors = ["Yeongseok"]
7
+ gem.email = ["iyagi15@gmail.com"]
8
+ gem.homepage = "https://github.com/iyagi15/capistrano_rsync_remote_cache"
9
+ gem.summary = %q{Improved version of rsync-with-remote-cache deployment strategy.}
10
+ gem.description = %q{Improved version of rsync-with-remote-cache deployment strategy.}
11
+
12
+ gem.files = `git ls-files`.split($/)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ["lib"]
16
+
17
+ gem.add_dependency('capistrano', '>=2.4.0')
18
+ gem.add_dependency('parallel', '>=0.0.0')
19
+ end
@@ -0,0 +1,141 @@
1
+ require 'capistrano/recipes/deploy/strategy/remote'
2
+ require 'fileutils'
3
+ require 'parallel'
4
+
5
+ module Capistrano
6
+ module Deploy
7
+ module Strategy
8
+ class RsyncRemoteCache < Remote
9
+
10
+ class InvalidCacheError < Exception; end
11
+ class RsyncFailedError < Exception; end
12
+ class LocalCacheUpdateFailedError < Exception; end
13
+
14
+ def self.default_attribute(attribute, default_value)
15
+ define_method(attribute) { configuration[attribute] || default_value }
16
+ end
17
+
18
+ INFO_COMMANDS = {
19
+ :subversion => "svn info . | sed -n \'s/URL: //p\'",
20
+ :git => "git config remote.origin.url",
21
+ :mercurial => "hg showconfig paths.default",
22
+ :bzr => "bzr info | grep parent | sed \'s/^.*parent branch: //\'"
23
+ }
24
+
25
+ default_attribute :rsync_options, '-az --delete'
26
+ default_attribute :local_cache, '.rsync_cache'
27
+ default_attribute :repository_cache, 'cached-copy'
28
+ default_attribute :rsync_concurrency, 8
29
+ default_attribute :rsync_in_parallel, false
30
+ default_attribute :rsync_ssh_options, '-o PasswordAuthentication=no -o StrictHostKeyChecking=no'
31
+
32
+ def deploy!
33
+ update_local_cache
34
+ update_remote_cache
35
+ copy_remote_cache
36
+ end
37
+
38
+ def system!(command)
39
+ system(command) or raise RuntimeError.new("Command exit with non zero status: #{command}")
40
+ end
41
+
42
+ def update_local_cache
43
+ system!(command)
44
+ mark_local_cache
45
+ end
46
+
47
+ def update_remote_cache
48
+ finder_options = {:except => { :no_release => true }}
49
+ if rsync_in_parallel
50
+ Parallel.map(find_servers(finder_options), :in_processes => rsync_concurrency) do |s|
51
+ system!(rsync_command_for(s))
52
+ end.all?
53
+ else
54
+ find_servers(finder_options).each {|s| system(rsync_command_for(s)) }
55
+ end
56
+ end
57
+
58
+ def copy_remote_cache
59
+ run("rsync -azx #{repository_cache_path}/ #{configuration[:release_path]}/")
60
+ end
61
+
62
+ def rsync_command_for(server)
63
+ "sshpass -p '#{password}'' rsync #{rsync_options} --rsh='ssh -p #{ssh_port(server)} #{rsync_ssh_options}' '#{local_cache_path}/' #{rsync_host(server)}:#{repository_cache_path}/"
64
+ end
65
+
66
+ def mark_local_cache
67
+ File.open(File.join(local_cache_path, 'REVISION'), 'w') {|f| f << revision }
68
+ end
69
+
70
+ def ssh_port(server)
71
+ server.port || ssh_options[:port] || 22
72
+ end
73
+
74
+ def local_cache_path
75
+ File.expand_path(local_cache)
76
+ end
77
+
78
+ def repository_cache_path
79
+ File.join(shared_path, repository_cache)
80
+ end
81
+
82
+ def repository_url
83
+ `cd #{local_cache_path} && #{INFO_COMMANDS[configuration[:scm]]}`.strip
84
+ end
85
+
86
+ def repository_url_changed?
87
+ repository_url != configuration[:repository]
88
+ end
89
+
90
+ def remove_local_cache
91
+ logger.trace "repository has changed; removing old local cache from #{local_cache_path}"
92
+ FileUtils.rm_rf(local_cache_path)
93
+ end
94
+
95
+ def remove_local_cache_if_repository_url_changed
96
+ remove_local_cache if repository_url_changed?
97
+ end
98
+
99
+ def rsync_host(server)
100
+ configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
101
+ end
102
+
103
+ def local_cache_exists?
104
+ File.exist?(local_cache_path)
105
+ end
106
+
107
+ def local_cache_valid?
108
+ local_cache_exists? && File.directory?(local_cache_path)
109
+ end
110
+
111
+ # Defines commands that should be checked for by deploy:check. These include the SCM command
112
+ # on the local end, and rsync on both ends. Note that the SCM command is not needed on the
113
+ # remote end.
114
+ def check!
115
+ super.check do |check|
116
+ check.local.command(source.command)
117
+ check.local.command('rsync')
118
+ check.local.command('sshpass')
119
+ check.remote.command('rsync')
120
+ end
121
+ end
122
+
123
+ private
124
+
125
+ def command
126
+ if local_cache_exists?
127
+ remove_local_cache_if_repository_url_changed
128
+ end
129
+ if local_cache_valid?
130
+ source.sync(revision, local_cache_path)
131
+ elsif !local_cache_exists?
132
+ "mkdir -p #{local_cache_path} && #{source.checkout(revision, local_cache_path)}"
133
+ else
134
+ raise InvalidCacheError, "The local cache exists but is not valid (#{local_cache_path})"
135
+ end
136
+ end
137
+ end
138
+
139
+ end
140
+ end
141
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-rsync-remote-cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yeongseok
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: parallel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.0
41
+ description: Improved version of rsync-with-remote-cache deployment strategy.
42
+ email:
43
+ - iyagi15@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - README.rdoc
51
+ - Rakefile
52
+ - capistrano-rsync-remote-cache.gemspec
53
+ - lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb
54
+ homepage: https://github.com/iyagi15/capistrano_rsync_remote_cache
55
+ licenses: []
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.0.3
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Improved version of rsync-with-remote-cache deployment strategy.
77
+ test_files: []