capistrano2-remote_cache_from_local 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 300c48ccaf62c3a4b22e0423a2df1599fa236d7a
4
+ data.tar.gz: ac55d5ea4cdbaed42f3c855a17e89a52f349ad8d
5
+ SHA512:
6
+ metadata.gz: b82947c59fd18a095120ed1fd38ce61987c37f8f3da5e2b2b437fae3ff4999f6a058a83f633a8931cda413605ddaa762a2cf225340b1a09ddaa1fca0c9e7abf8
7
+ data.tar.gz: 64412d07911a9026874b85752b5e052fc065dd946994e3acb7596054ecebda47a494d4d5d6158f74e838e2400d8e556faaf8ef2659d7caaff73d2e41a7262e51
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano2-remote_cache_from_local.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Collaborative Drug Discovery
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # :remote_cache_from_local for Capistrano 2
2
+
3
+ This gem allows you to deploy a project using Capistrano 2 directly from the
4
+ local git repo to the deployment server, removing your reliance on a central,
5
+ possibly-unavailable SCM service. It supports git submodules in the same way —
6
+ your local checkouts of the project's submodules will be used to clone on the
7
+ deployment server.
8
+
9
+ It piggybacks on the SSH connection that Capistrano sets up, so you do not need
10
+ to separately configure it. Besides cloning from the local checkout, it
11
+ otherwise behaves the same as Capistrano's built-in `:remote_cache` strategy.
12
+
13
+ ### Alternatives
14
+
15
+ Capistrano's `:copy` strategy can also deploy from the local working copy, at
16
+ the cost of re-copying the entire codebase from the local machine to the server
17
+ on every deploy. This strategy takes advantage of git to only transfer what has
18
+ changed.
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'capistrano2-remote_cache_from_local', require: false
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install capistrano2-remote_cache_from_local
35
+
36
+ ## Usage
37
+
38
+ In your `deploy.rb`, add this line:
39
+
40
+ ```
41
+ require 'capistrano/remote_cache_from_local'
42
+ ```
43
+
44
+ **Remove** anywhere you have a `:repository`, `:scm`, or `:deploy_via` variable
45
+ set. This strategy needs to specify those values for you.
46
+
47
+ ```ruby
48
+ # set :repository, 'git+shh://git.example.com/foo.git'
49
+ # set :scm, :git
50
+ # set :deploy_via, :remote_cache
51
+ ```
52
+
53
+ Set any of the following variables if you need a value other than the defaults
54
+ listed here:
55
+
56
+ ```ruby
57
+ # The path to the root of the local working copy, relative to this project's root.
58
+ set :local_repository, '.'
59
+ # The port used for the temporary git daemon.
60
+ set :git_tunnel_local_port, 50123
61
+ # The port used for the remote side of the temporary SSH tunnel used for cloning
62
+ set :git_tunnel_remote_port, 50123
63
+ # The PID file used to keep track of the git daemon.
64
+ set :git_daemon_pid_file, 'tmp/git-daemon.pid'
65
+ # To see the details of the git operations, make this true
66
+ set :scm_verbose, false
67
+ ```
68
+
69
+ To enable submodules to be cloned from the local copies, you must also disable
70
+ Capistrano's built-in submodule support:
71
+
72
+ ```ruby
73
+ # Disable built-in submodule support
74
+ set :git_enable_submodules, false
75
+ # Enable remote_cache_from_local's submodule support
76
+ set :git_local_enable_submodules, true
77
+ ```
78
+
79
+ ## Security
80
+
81
+ In order to make the local repo available to clone from the server, the strategy
82
+ starts a temporary [git-daemon][]. It listens only on `localhost` — connections
83
+ from the server are forwarded via an SSH tunnel — so it is not visible to the
84
+ network at large.
85
+
86
+ However, because connections to git-daemon are not authenticated, this temporary
87
+ daemon is accessible to any process running on the deploying machine. A
88
+ malicious process running as a different user could gain read access to the
89
+ deployed application's source code. So don't use this if you don't trust the
90
+ machine you are deploying from.
91
+
92
+ [git-daemon]: https://www.kernel.org/pub/software/scm/git/docs/git-daemon.html
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bundle install` to install dependencies. Then,
97
+ run `rake spec` to run the tests.
98
+
99
+ To install this gem onto your local machine, run `bundle exec rake install`. To
100
+ release a new version, update the version number in `version.rb`, and then run
101
+ `bundle exec rake release`, which will create a git tag for the version, push
102
+ git commits and tags, and push the `.gem` file to
103
+ [rubygems.org](https://rubygems.org).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cdd/capistrano2-remote_cache_from_local.
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
112
+
113
+ ## Future work
114
+
115
+ * An alternate implementation for Capistrano 3.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/remote_cache_from_local/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano2-remote_cache_from_local"
8
+ spec.version = Capistrano::RemoteCacheFromLocal::VERSION
9
+ spec.authors = ["Rhett Sutphin"]
10
+ spec.email = ["rhett@detailedbalance.net"]
11
+
12
+ spec.summary = %q{Allows deploying with capistrano directly from the local git repo.}
13
+ spec.description = %q{A deployment strategy for Capistrano 2 that allows deploying directly from the local git repo, piggybacking on Capistrano's existing SSH connection.}
14
+ spec.homepage = "https://github.com/cdd/capistrano2-remote_cache_from_local"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "capistrano", "~> 2.5"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,61 @@
1
+ require 'capistrano/recipes/deploy/scm/git'
2
+
3
+ module Capistrano::Deploy::SCM
4
+ ##
5
+ # An SCM that works in tandem with the :remote_cache_from_local strategy
6
+ # to support git submodules being retrieved via the local SSH tunnel also.
7
+ # Does not currently support recursive submodules.
8
+ class GitLocal < Git
9
+ default_command "git" # Not inherited
10
+
11
+ def checkout(revision, destination)
12
+ super_command = super
13
+ super_with_submodules_if_enabled(super_command, destination)
14
+ end
15
+
16
+ def sync(revision, destination)
17
+ sync_command = super
18
+ # Match remote URL to current repository setting — don't know why the base
19
+ # Git SCM only does this when the remote is not "origin".
20
+ sync_with_remote_set_url_command = [
21
+ "cd #{destination}",
22
+ "#{command} remote set-url #{origin} #{variable(:repository)}",
23
+ sync_command
24
+ ].join(' && ')
25
+
26
+ super_with_submodules_if_enabled(sync_with_remote_set_url_command, destination)
27
+ end
28
+
29
+ private
30
+
31
+ def super_with_submodules_if_enabled(super_command, destination)
32
+ if variable(:git_local_enable_submodules)
33
+ [super_command, update_submodules(destination)].join(' && ')
34
+ else
35
+ super_command
36
+ end
37
+ end
38
+
39
+ def update_submodules(main_checkout)
40
+ git = command
41
+ repo_prefix = repository.sub(/\.git$/, '')
42
+ execute = []
43
+
44
+ submodules_root = File.expand_path('../cached-submodules', main_checkout)
45
+ execute << "mkdir -p #{submodules_root}"
46
+ execute << "cd #{main_checkout}"
47
+ execute << "#{git} submodule #{verbose} init"
48
+ # This mess does the following:
49
+ # - Parses .gitmodules to extract a list of [path-property-name, path-value] pairs
50
+ # - For each of these pairs,
51
+ # - Transforms the path property name to the URL property name
52
+ # - Uses git-config to set the local URL property of the submodule to the version available via the SSH tunnel
53
+ # N.b.: `git submodule foreach` could do this slightly cleaner, but it doesn't work until after `update` for some reason.
54
+ execute << %Q[#{git} config -f .gitmodules --get-regexp 'submodule.*path' | awk '{ gsub("path", "url", $1); system(sprintf("git config %s #{repo_prefix}%s/.git", $1, $2)) }']
55
+ execute << "#{git} config --get-regexp submodule" if variable(:scm_verbose)
56
+ execute << "#{git} submodule #{verbose} update"
57
+
58
+ execute.join(' && ')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,74 @@
1
+ require 'capistrano/recipes/deploy/strategy/remote_cache'
2
+
3
+ module Capistrano::Deploy::Strategy
4
+ ##
5
+ # A deployment strategy which has the app server pull the code from the
6
+ # deploying machine via an SSH tunnel. The strategy behaves like :remote_cache
7
+ # otherwise.
8
+ class RemoteCacheFromLocal < RemoteCache
9
+ private
10
+
11
+ def update_repository_cache
12
+ configuration.set(:repository, "git://127.0.0.1:#{git_tunnel_remote_port}/.git")
13
+ with_tunneled_local_daemon { super }
14
+ end
15
+
16
+ def with_tunneled_local_daemon
17
+ execute_on_servers do |servers|
18
+ servers.each do |s|
19
+ begin
20
+ # Run a git daemon locally (listening on 127.0.0.1 only)
21
+ execute "Run local git daemon" do
22
+ system "git daemon --verbose --listen=127.0.0.1 --port=#{git_tunnel_local_port} --reuseaddr --export-all --base-path='#{local_repository}' --detach --pid-file='#{git_daemon_pid_file}'"
23
+ end
24
+
25
+ # Forward remote connections to local git daemon via capistrano's SSH session
26
+ session = sessions[s]
27
+ session.forward.remote(git_tunnel_local_port, '127.0.0.1', git_tunnel_remote_port)
28
+ keep_looping = true
29
+ Thread.new { session.loop { sleep(0.1); keep_looping } }
30
+
31
+ yield
32
+ ensure
33
+ keep_looping = false
34
+ execute "Kill local git daemon if running" do
35
+ system "if [ -e #{git_daemon_pid_file} ]; then kill `cat '#{git_daemon_pid_file}'`; rm '#{git_daemon_pid_file}'; fi"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def git_tunnel_local_port
43
+ fetch(:git_tunnel_local_port, 50123)
44
+ end
45
+
46
+ def git_tunnel_remote_port
47
+ fetch(:git_tunnel_remote_port, 50123)
48
+ end
49
+
50
+ def git_daemon_pid_file
51
+ fetch(:git_daemon_pid_file, 'tmp/git-daemon.pid')
52
+ end
53
+
54
+ # Local execution methods copied from the copy strategy
55
+
56
+ def execute(description, &block)
57
+ logger.debug description
58
+ handle_system_errors(&block)
59
+ end
60
+
61
+ def handle_system_errors(&block)
62
+ block.call
63
+ raise_command_failed if last_command_failed?
64
+ end
65
+
66
+ def raise_command_failed
67
+ raise Capistrano::Error, "shell command failed with return code #{$?}"
68
+ end
69
+
70
+ def last_command_failed?
71
+ $? != 0
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module RemoteCacheFromLocal
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ if Capistrano::Configuration.instance
2
+ config = Capistrano::Configuration.instance
3
+ config.set :scm, :git_local
4
+ config.set :deploy_via, :remote_cache_from_local
5
+ config.set :local_repository, '.'
6
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano2-remote_cache_from_local
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rhett Sutphin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-29 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.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A deployment strategy for Capistrano 2 that allows deploying directly
70
+ from the local git repo, piggybacking on Capistrano's existing SSH connection.
71
+ email:
72
+ - rhett@detailedbalance.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - capistrano2-remote_cache_from_local.gemspec
85
+ - lib/capistrano/recipes/deploy/scm/git_local.rb
86
+ - lib/capistrano/recipes/deploy/strategy/remote_cache_from_local.rb
87
+ - lib/capistrano/remote_cache_from_local.rb
88
+ - lib/capistrano/remote_cache_from_local/version.rb
89
+ homepage: https://github.com/cdd/capistrano2-remote_cache_from_local
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Allows deploying with capistrano directly from the local git repo.
113
+ test_files: []