sshkit-chunky-runner 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/lib/sshkit/chunky/runner.rb +10 -0
- data/lib/sshkit/chunky/runner/chunks.rb +19 -0
- data/lib/sshkit/chunky/runner/coordinator.rb +22 -0
- data/lib/sshkit/chunky/runner/version.rb +7 -0
- data/spec/lib/sshkit/chunky/runner/chunks_spec.rb +37 -0
- data/spec/lib/sshkit/chunky/runner/coordinator_spec.rb +44 -0
- data/spec/spec_helper.rb +87 -0
- data/sshkit-chunky-runner.gemspec +28 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49bf7cbfd1a2feb7a1420695a8b3be966ccf4287
|
4
|
+
data.tar.gz: a294221cde76f2c38de2c280fea367afb646b79c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39cd8b01bdb72cf2906e8bf48c2b5aac05f5821ae2233b3d5b2c3816af829bb3324e52ac65ae606c352da288da6c7c3f01e0281ab23353d50438428ce5432e44
|
7
|
+
data.tar.gz: 0d7e8cbc5f933d9a201465c858275adfdea0d075c50b5e0c2aec3425307b59f85240fbed5c6606948174e344803734bfb94c00001b919ac131abe0da93748e46
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tomas Brazys
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# SSHKit::Chunky::Runner
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/deees/sshkit-chunky-runner.svg)](https://travis-ci.org/deees/sshkit-chunky-runner)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/deees/sshkit-chunky-runner/badges/gpa.svg)](https://codeclimate.com/github/deees/sshkit-chunky-runner)
|
5
|
+
|
6
|
+
Runs ssh commands in few chunks. It divides hosts into static number of chunks,
|
7
|
+
you just need to specify how many chunks you need.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sshkit-chunky-runner'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install sshkit-chunky-runner
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
hosts = %w(
|
29
|
+
1.example.com
|
30
|
+
2.example.com
|
31
|
+
3.example.com
|
32
|
+
4.example.com
|
33
|
+
5.example.com
|
34
|
+
6.example.com
|
35
|
+
7.example.com
|
36
|
+
8.example.com
|
37
|
+
)
|
38
|
+
on hosts, in: :chunks, count: 3, wait: 5 do
|
39
|
+
within '/opt/sites/example.com' do
|
40
|
+
as :deploy do
|
41
|
+
with rails_env: :production do
|
42
|
+
rake 'assets:precompile'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
This will divide all hosts into 3 groups.
|
50
|
+
|
51
|
+
First group will have `1.example.com`, `2.example.com`, `3.example.com`, second
|
52
|
+
group - `4.example.com`, `5.example.com`, `6.example.com`, and the last one -
|
53
|
+
`7.example.com`, `8.example.com`.
|
54
|
+
|
55
|
+
If you add more hosts, each group then will have more hosts. Number of groups
|
56
|
+
remain the same.
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it ( https://github.com/deees/sshkit-chunky-runner/fork )
|
61
|
+
2. Create your feature branch (`git checkout -b features/my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin features/my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module SSHKit
|
2
|
+
module Chunky
|
3
|
+
module Runner
|
4
|
+
class Chunks < SSHKit::Runner::Group
|
5
|
+
attr_writer :chunks_count
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def group_size
|
10
|
+
(hosts.size.to_f / chunks_count).ceil
|
11
|
+
end
|
12
|
+
|
13
|
+
def chunks_count
|
14
|
+
@chunks_count || options[:count] || 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'sshkit/coordinator'
|
2
|
+
|
3
|
+
module SSHKit
|
4
|
+
class Coordinator
|
5
|
+
# overrides original method to include chunks runner
|
6
|
+
def each(options={}, &block)
|
7
|
+
if hosts
|
8
|
+
options = default_options.merge(options)
|
9
|
+
case options[:in]
|
10
|
+
when :parallel then Runner::Parallel
|
11
|
+
when :sequence then Runner::Sequential
|
12
|
+
when :groups then Runner::Group
|
13
|
+
when :chunks then SSHKit::Chunky::Runner::Chunks # <- added
|
14
|
+
else
|
15
|
+
raise RuntimeError, "Don't know how to handle run style #{options[:in].inspect}"
|
16
|
+
end.new(hosts, options, &block).execute
|
17
|
+
else
|
18
|
+
Runner::Null.new(hosts, options, &block).execute
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'sshkit/chunky/runner/chunks'
|
2
|
+
|
3
|
+
describe SSHKit::Chunky::Runner::Chunks do
|
4
|
+
describe '#group_size' do
|
5
|
+
let(:options) { { count: 3 } }
|
6
|
+
let(:block_to_run) { ->(host) { execute "echo #{Time.now.to_i}" } }
|
7
|
+
let(:runner) do
|
8
|
+
SSHKit::Chunky::Runner::Chunks.new(hosts, options, &block_to_run)
|
9
|
+
end
|
10
|
+
|
11
|
+
subject(:group_size) { runner.send(:group_size) }
|
12
|
+
|
13
|
+
context 'with one host' do
|
14
|
+
let(:hosts) { ['example.com'] }
|
15
|
+
|
16
|
+
it 'returns one' do
|
17
|
+
expect(group_size).to eq 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with 6 hosts' do
|
22
|
+
let(:hosts) { ['example.com'] * 6 }
|
23
|
+
|
24
|
+
it 'returns 2' do
|
25
|
+
expect(group_size).to eq 2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with 7 hosts' do
|
30
|
+
let(:hosts) { ['example.com'] * 7 }
|
31
|
+
|
32
|
+
it 'returns 3' do
|
33
|
+
expect(group_size).to eq 3
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sshkit/chunky/runner/coordinator'
|
2
|
+
|
3
|
+
describe SSHKit::Coordinator do
|
4
|
+
describe '#each' do
|
5
|
+
let(:output) { '' }
|
6
|
+
let(:block_to_run) { ->(host) { execute "echo #{Time.now.to_i}" } }
|
7
|
+
|
8
|
+
subject(:results) do
|
9
|
+
output.lines.map { |value| value.split(' ').last.to_i }
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
SSHKit.config.backend = SSHKit::Backend::Printer
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with default options' do
|
17
|
+
before do
|
18
|
+
SSHKit.capture_output output do
|
19
|
+
SSHKit::Coordinator.new(%w{1.example.com 2.example.com})
|
20
|
+
.each(&block_to_run)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns parallel results' do
|
25
|
+
expect(results.size).to eq 2
|
26
|
+
expect(results.first).to eq results.last
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with chunks options' do
|
31
|
+
before do
|
32
|
+
SSHKit.capture_output output do
|
33
|
+
SSHKit::Coordinator.new(%w{1.example.com 2.example.com})
|
34
|
+
.each(in: :chunks, count: 2, &block_to_run)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns sequential results' do
|
39
|
+
expect(results.size).to eq 2
|
40
|
+
expect(results.first).to be < results.last
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'sshkit'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# These two settings work together to allow you to limit a spec run
|
44
|
+
# to individual examples or groups you care about by tagging them with
|
45
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
46
|
+
# get run.
|
47
|
+
config.filter_run :focus
|
48
|
+
config.run_all_when_everything_filtered = true
|
49
|
+
|
50
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
51
|
+
# For more details, see:
|
52
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
53
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
54
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
55
|
+
# config.disable_monkey_patching!
|
56
|
+
|
57
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
58
|
+
# be too noisy due to issues in dependencies.
|
59
|
+
# config.warnings = true
|
60
|
+
|
61
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
62
|
+
# file, and it's useful to allow more verbose output when running an
|
63
|
+
# individual spec file.
|
64
|
+
if config.files_to_run.one?
|
65
|
+
# Use the documentation formatter for detailed output,
|
66
|
+
# unless a formatter has already been configured
|
67
|
+
# (e.g. via a command-line flag).
|
68
|
+
config.default_formatter = 'doc'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Print the 10 slowest examples and example groups at the
|
72
|
+
# end of the spec run, to help surface which specs are running
|
73
|
+
# particularly slow.
|
74
|
+
config.profile_examples = 10
|
75
|
+
|
76
|
+
# Run specs in random order to surface order dependencies. If you find an
|
77
|
+
# order dependency and want to debug it, you can fix the order by providing
|
78
|
+
# the seed, which is printed after each run.
|
79
|
+
# --seed 1234
|
80
|
+
config.order = :random
|
81
|
+
|
82
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
83
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
84
|
+
# test failures related to randomization by passing the same `--seed` value
|
85
|
+
# as the one that triggered the failure.
|
86
|
+
Kernel.srand config.seed
|
87
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sshkit/chunky/runner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'sshkit-chunky-runner'
|
8
|
+
spec.version = SSHKit::Chunky::Runner::VERSION
|
9
|
+
spec.authors = ['Tomas Brazys']
|
10
|
+
spec.email = ['tomas.brazys@gmail.com']
|
11
|
+
spec.summary = 'Run ssh commands in chunks'
|
12
|
+
spec.description = 'Runs ssh commands in few chunks. It divides hosts into \
|
13
|
+
static number of chunks, you just need to specify how \
|
14
|
+
many chunks you need.'
|
15
|
+
spec.homepage = 'https://github.com/deees/sshkit-chunky-runner'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'sshkit', '~> 1.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sshkit-chunky-runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Brazys
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sshkit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: |-
|
70
|
+
Runs ssh commands in few chunks. It divides hosts into \
|
71
|
+
static number of chunks, you just need to specify how \
|
72
|
+
many chunks you need.
|
73
|
+
email:
|
74
|
+
- tomas.brazys@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/sshkit/chunky/runner.rb
|
87
|
+
- lib/sshkit/chunky/runner/chunks.rb
|
88
|
+
- lib/sshkit/chunky/runner/coordinator.rb
|
89
|
+
- lib/sshkit/chunky/runner/version.rb
|
90
|
+
- spec/lib/sshkit/chunky/runner/chunks_spec.rb
|
91
|
+
- spec/lib/sshkit/chunky/runner/coordinator_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- sshkit-chunky-runner.gemspec
|
94
|
+
homepage: https://github.com/deees/sshkit-chunky-runner
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Run ssh commands in chunks
|
118
|
+
test_files:
|
119
|
+
- spec/lib/sshkit/chunky/runner/chunks_spec.rb
|
120
|
+
- spec/lib/sshkit/chunky/runner/coordinator_spec.rb
|
121
|
+
- spec/spec_helper.rb
|