capistrano_sentinel 0.0.1

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: 0262d02b86a16d5361e2979b46866fd45facfdb3
4
+ data.tar.gz: f5e3a675e3a7ea66960e49b263fd1ed494b14bcf
5
+ SHA512:
6
+ metadata.gz: f5a6940b5f15d44db218c7d7ecfa1abcb2e925345d5a3c6b6af7461c4643df70577e093b13d36ae0ae1cc5eac59ce5e4aabe4401cd60722aa9605e159effcd29
7
+ data.tar.gz: 8341f1505be6f690148f9906cc1a334cdf9eecf7f7df14aa33e969c1a24dbaef06db8d7c96dda7934084a32534fb8ded07ff38932fee1e1559e109811aca3dee
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ enhanced_date_select (1.3.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ actionpack (4.2.6)
10
+ actionview (= 4.2.6)
11
+ activesupport (= 4.2.6)
12
+ rack (~> 1.6)
13
+ rack-test (~> 0.6.2)
14
+ rails-dom-testing (~> 1.0, >= 1.0.5)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
+ actionview (4.2.6)
17
+ activesupport (= 4.2.6)
18
+ builder (~> 3.1)
19
+ erubis (~> 2.7.0)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
+ activesupport (4.2.6)
23
+ i18n (~> 0.7)
24
+ json (~> 1.7, >= 1.7.7)
25
+ minitest (~> 5.1)
26
+ thread_safe (~> 0.3, >= 0.3.4)
27
+ tzinfo (~> 1.1)
28
+ appraisal (2.1.0)
29
+ bundler
30
+ rake
31
+ thor (>= 0.14.0)
32
+ builder (3.2.2)
33
+ colored (1.2)
34
+ coveralls (0.8.14)
35
+ json (>= 1.8, < 3)
36
+ simplecov (~> 0.12.0)
37
+ term-ansicolor (~> 1.3)
38
+ thor (~> 0.19.1)
39
+ tins (~> 1.6.0)
40
+ diff-lcs (1.2.5)
41
+ docile (1.1.5)
42
+ erubis (2.7.0)
43
+ i18n (0.7.0)
44
+ json (1.8.3)
45
+ loofah (2.0.3)
46
+ nokogiri (>= 1.5.9)
47
+ lorax (0.2.0)
48
+ nokogiri (>= 1.4.0)
49
+ metaclass (0.0.4)
50
+ mini_portile2 (2.1.0)
51
+ minitest (5.9.0)
52
+ mocha (1.1.0)
53
+ metaclass (~> 0.0.1)
54
+ nokogiri (1.6.8)
55
+ mini_portile2 (~> 2.1.0)
56
+ pkg-config (~> 1.1.7)
57
+ pkg-config (1.1.7)
58
+ rack (1.6.4)
59
+ rack-test (0.6.3)
60
+ rack (>= 1.0)
61
+ rails-deprecated_sanitizer (1.0.3)
62
+ activesupport (>= 4.2.0.alpha)
63
+ rails-dom-testing (1.0.7)
64
+ activesupport (>= 4.2.0.beta, < 5.0)
65
+ nokogiri (~> 1.6.0)
66
+ rails-deprecated_sanitizer (>= 1.0.1)
67
+ rails-html-sanitizer (1.0.3)
68
+ loofah (~> 2.0)
69
+ railties (4.2.6)
70
+ actionpack (= 4.2.6)
71
+ activesupport (= 4.2.6)
72
+ rake (>= 0.8.7)
73
+ thor (>= 0.18.1, < 2.0)
74
+ rake (11.2.2)
75
+ rspec-core (3.5.1)
76
+ rspec-support (~> 3.5.0)
77
+ rspec-expectations (3.5.0)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.5.0)
80
+ rspec-mocks (3.5.0)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.5.0)
83
+ rspec-rails (3.5.0)
84
+ actionpack (>= 3.0)
85
+ activesupport (>= 3.0)
86
+ railties (>= 3.0)
87
+ rspec-core (~> 3.5.0)
88
+ rspec-expectations (~> 3.5.0)
89
+ rspec-mocks (~> 3.5.0)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-support (3.5.0)
92
+ shoulda (3.5.0)
93
+ shoulda-context (~> 1.0, >= 1.0.1)
94
+ shoulda-matchers (>= 1.4.1, < 3.0)
95
+ shoulda-context (1.2.1)
96
+ shoulda-matchers (2.8.0)
97
+ activesupport (>= 3.0.0)
98
+ simplecov (0.12.0)
99
+ docile (~> 1.1.0)
100
+ json (>= 1.8, < 3)
101
+ simplecov-html (~> 0.10.0)
102
+ simplecov-html (0.10.0)
103
+ simplecov-summary (0.0.4)
104
+ colored
105
+ simplecov
106
+ term-ansicolor (1.3.2)
107
+ tins (~> 1.0)
108
+ thor (0.19.1)
109
+ thread_safe (0.3.5)
110
+ tins (1.6.0)
111
+ tzinfo (1.2.2)
112
+ thread_safe (~> 0.1)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ appraisal (~> 2.1, >= 2.1)
119
+ coveralls (~> 0.8, >= 0.8)
120
+ enhanced_date_select!
121
+ lorax (~> 0, >= 0.2)
122
+ mocha (~> 1.1, >= 1.1.0)
123
+ nokogiri (~> 1.6, >= 1.6)
124
+ rack (>= 1.0)
125
+ rake (~> 11.0, >= 11.0)
126
+ rspec-mocks (~> 3.4, >= 3.4)
127
+ rspec-rails (~> 3.4, >= 3.4)
128
+ shoulda (~> 3.5, >= 3.5.0)
129
+ simplecov (~> 0.11, >= 0.11)
130
+ simplecov-summary (~> 0.0, >= 0.0.4)
131
+
132
+ BUNDLED WITH
133
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 bogdanRada
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ capistrano_sentinel
2
+ =================
3
+
4
+ Overview
5
+ --------
6
+
7
+ To BE DONE VERY SOON : )
8
+
9
+ Testing
10
+ -------
11
+
12
+ To test, do the following:
13
+
14
+ 1. cd to the gem root.
15
+ 2. bundle install
16
+ 3. bundle exec rake
17
+
18
+ Contributions
19
+
20
+ ---
21
+
22
+ Please log all feedback/issues via [Github Issues](http://github.com/bogdanRada/capistrano_sentinel/issues). Thanks.
23
+
24
+ Contributing to capistrano_sentinel
25
+ ---------------------------------
26
+
27
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
28
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
29
+ - Fork the project.
30
+ - Start a feature/bugfix branch.
31
+ - Commit and push until you are happy with your contribution.
32
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
34
+
35
+ Copyright
36
+ ---------
37
+
38
+ Copyright (c) 2016 bogdanRada. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/version', __FILE__)
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ require 'appraisal'
7
+ require 'rspec/core/rake_task'
8
+ require 'coveralls/rake/task'
9
+ Coveralls::RakeTask.new
10
+
11
+ begin
12
+ Bundler.setup(:default, :development)
13
+ rescue Bundler::BundlerError => e
14
+ $stderr.puts e.message
15
+ $stderr.puts 'Run `bundle install` to install missing gems'
16
+ exit e.status_code
17
+ end
18
+ require 'rake'
19
+
20
+ RSpec::Core::RakeTask.new(:spec) do |spec|
21
+ spec.rspec_opts = ['--backtrace '] if ENV['DEBUG']
22
+ spec.verbose = true
23
+ end
24
+
25
+ desc 'Default: run the unit tests.'
26
+ task default: [:all]
27
+
28
+ desc 'Test the plugin under all supported Rails versions.'
29
+ task :all do |_t|
30
+ if ENV['TRAVIS']
31
+ # require 'json'
32
+ # puts JSON.pretty_generate(ENV.to_hash)
33
+ if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
34
+ appraisal_name = ENV['BUNDLE_GEMFILE'].scan(/rails\_(.*)\.gemfile/).flatten.first
35
+ command_prefix = "appraisal rails-#{appraisal_name}"
36
+ exec ("#{command_prefix} bundle install && #{command_prefix} bundle exec rspec && bundle exec rake coveralls:push ")
37
+ else
38
+ exec(' bundle exec appraisal install && bundle exec rake appraisal spec && bundle exec rake coveralls:push')
39
+ end
40
+ else
41
+ exec('bundle exec appraisal install && bundle exec rake appraisal spec')
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path("../lib/capistrano_sentinel/version", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "capistrano_sentinel"
5
+ s.version = CapistranoSentinel.gem_version
6
+ s.platform = Gem::Platform::RUBY
7
+ s.summary = "\"capistrano_sentinel\""
8
+ s.email = "raoul_ice@yahoo.com"
9
+ s.homepage = "http://github.com/bogdanRada/capistrano_sentinel"
10
+ s.description = "\"Handles capistrano deploy in parallel.\""
11
+ s.authors = ["bogdanRada"]
12
+
13
+ s.date = Date.today
14
+
15
+ s.licenses = ["MIT"]
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = s.files.grep(/^(spec)/)
18
+ s.require_paths = ["lib"]
19
+ s.required_ruby_version = '>= 1.9'
20
+
21
+
22
+ s.add_dependency 'websocket'
23
+
24
+
25
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'bundler/setup'
4
+
5
+ require 'base64'
6
+ require 'socket'
7
+ require 'fileutils'
8
+ require 'json'
9
+ require 'uri'
10
+ require 'digest/md5'
11
+ require 'openssl'
12
+ require 'forwardable'
13
+ require 'thread'
14
+ require 'monitor'
15
+
16
+ require 'websocket'
17
+
18
+ require_relative './capistrano_sentinel/classes/gem_finder'
19
+
20
+ Gem.find_files('capistrano_sentinel/initializers/active_support/**/*.rb').each { |path| require path }
21
+
22
+ Gem.find_files('capistrano_sentinel/initializers/core_ext/**/*.rb').each { |path| require path }
23
+ Gem.find_files('capistrano_sentinel/helpers/**/*.rb').each { |path| require path }
24
+ Gem.find_files('capistrano_sentinel/classes/**/*.rb').each { |path| require path }
25
+
26
+ if CapistranoSentinel::GemFinder.fetch_gem_version('bundler')
27
+ require_relative './capistrano_sentinel/patches/bundler'
28
+ end
29
+
30
+ if CapistranoSentinel::GemFinder.fetch_gem_version('rake')
31
+ require_relative './capistrano_sentinel/patches/rake'
32
+ end
33
+
34
+ if CapistranoSentinel::GemFinder.capistrano_version_2?
35
+ require_relative './capistrano_sentinel/patches/capistrano2'
36
+ end
@@ -0,0 +1,53 @@
1
+ module CapistranoSentinel
2
+ # helper used to determine gem versions
3
+ class GemFinder
4
+ class << self
5
+
6
+ def capistrano_version_2?
7
+ cap_version = fetch_gem_version('capistrano')
8
+ value_blank?(cap_version) ? false : verify_gem_version(cap_version, '3.0', operator: '<')
9
+ end
10
+
11
+ def value_blank?(value)
12
+ value.nil? || value_empty?(value) || (value.is_a?(String) && /\A[[:space:]]*\z/ === value)
13
+ end
14
+
15
+ def value_empty?(value)
16
+ value.respond_to?(:empty?) ? !!value.empty? : !value
17
+ end
18
+
19
+ def find_loaded_gem(name, property = nil)
20
+ gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name }
21
+ return if value_blank?(gem_spec)
22
+ value_blank?(property) ? gem_spec : gem_spec.send(property)
23
+ end
24
+
25
+ def find_loaded_gem_property(gem_name, property = 'version')
26
+ find_loaded_gem(gem_name, property)
27
+ end
28
+
29
+ def fetch_gem_version(gem_name)
30
+ version = find_loaded_gem_property(gem_name)
31
+ value_blank?(version) ? nil : get_parsed_version(version)
32
+ end
33
+
34
+ def get_parsed_version(version)
35
+ return 0 if value_blank?(version)
36
+ version = version.to_s.split('.')
37
+ version = format_gem_version(version)
38
+ version.join('.').to_f
39
+ end
40
+
41
+ def format_gem_version(version)
42
+ return version if version.size <= 2
43
+ version.pop until version.size == 2
44
+ version
45
+ end
46
+
47
+ def verify_gem_version(gem_version, version, options = {})
48
+ version = get_parsed_version(version)
49
+ get_parsed_version(gem_version).send(options.fetch('operator', '<='), version)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ module CapistranoSentinel
2
+ # class used to hook into the input stream
3
+ class InputStream
4
+ def self.hook(actor, stringio)
5
+ $stdin = new($stdin, actor, stringio)
6
+ end
7
+
8
+ def self.unhook
9
+ $stdin.finish if $stdin.is_a? CapistranoSentinel::InputStream
10
+ $stdin = STDIN
11
+ end
12
+
13
+ attr_accessor :real, :actor, :stringio
14
+
15
+ def initialize(real_stdin, actor, stringio)
16
+ self.real = real_stdin
17
+ self.actor = actor
18
+ self.stringio = stringio
19
+ end
20
+
21
+ def gets(*_args)
22
+ @stringio.rewind
23
+ data = @stringio.read
24
+ @actor.user_prompt_needed?(data)
25
+ end
26
+
27
+ def finish
28
+ end
29
+
30
+ def method_missing(name, *args, &block)
31
+ @real.send name, *args, &block
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module CapistranoSentinel
2
+ # class used to hook into the output stream
3
+ class OutputStream
4
+ def self.hook(stringio)
5
+ $stdout = new($stdout, stringio)
6
+ end
7
+
8
+ def self.unhook
9
+ $stdout.finish if $stdout.is_a? CapistranoSentinel::OutputStream
10
+ $stdout = STDOUT
11
+ end
12
+
13
+ attr_accessor :real, :stringio
14
+
15
+ def initialize(real_stdout, stringio)
16
+ self.real = real_stdout
17
+ self.stringio = stringio
18
+ end
19
+
20
+ def write(*args)
21
+ @stringio.write(*args)
22
+ @real.write(*args)
23
+ @real.flush
24
+ end
25
+
26
+ def finish
27
+ end
28
+
29
+ def method_missing(name, *args, &block)
30
+ @real.send name, *args, &block
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,85 @@
1
+ require_relative './input_stream'
2
+ require_relative './output_stream'
3
+ require_relative './request_worker'
4
+ module CapistranoSentinel
5
+ # class used to handle the rake worker and sets all the hooks before and after running the worker
6
+ class RequestHooks
7
+
8
+ ENV_KEY_JOB_ID = 'multi_cap_job_id'
9
+ SUBSCRIPTION_PREFIX ="rake_worker_"
10
+ PUBLISHER_PREFIX ="celluloid_worker_"
11
+
12
+ attr_accessor :job_id, :task
13
+
14
+ def initialize(task = nil)
15
+ @job_id = ENV[CapistranoSentinel::RequestHooks::ENV_KEY_JOB_ID]
16
+ @task = task.respond_to?(:fully_qualified_name) ? task.fully_qualified_name : task
17
+ end
18
+
19
+ def automatic_hooks(&block)
20
+ if job_id.present? && @task.present?
21
+ actor_start_working(action: 'invoke')
22
+ actor.wait_execution until actor.task_approved
23
+ actor_execute_block(&block)
24
+ else
25
+ block.call
26
+ end
27
+ end
28
+
29
+ def print_question?(question)
30
+ if job_id.present?
31
+ actor.user_prompt_needed?(question)
32
+ else
33
+ yield if block_given?
34
+ end
35
+ end
36
+
37
+
38
+ def show_bundler_progress
39
+ actor_start_working({action: "bundle_install"}) if @task.present? && @task.to_s.size > 2
40
+ yield if block_given?
41
+ end
42
+
43
+ private
44
+
45
+ def actor
46
+ @actor ||= CapistranoSentinel::RequestWorker.new
47
+ @actor
48
+ end
49
+
50
+ def output_stream
51
+ CapistranoSentinel::OutputStream
52
+ end
53
+
54
+ def input_stream
55
+ CapistranoSentinel::InputStream
56
+ end
57
+
58
+ def before_hooks
59
+ stringio = StringIO.new
60
+ output = output_stream.hook(stringio)
61
+ input = input_stream.hook(actor, stringio)
62
+ [input, output]
63
+ end
64
+
65
+ def after_hooks
66
+ input_stream.unhook
67
+ output_stream.unhook
68
+ end
69
+
70
+ def actor_execute_block(&block)
71
+ before_hooks
72
+ block.call
73
+ after_hooks
74
+ end
75
+
76
+ def actor_start_working(additionals = {})
77
+ additionals = additionals.present? ? additionals : {}
78
+ data = {job_id: job_id, task: @task }.merge(additionals)
79
+ data = data.stringify_keys
80
+ actor.work(data)
81
+ end
82
+
83
+
84
+ end
85
+ end