simpleworker 0.0.1
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 +7 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/lib/simpleworker/abstract_worker.rb +42 -0
- data/lib/simpleworker/bash/simple-localworker +8 -0
- data/lib/simpleworker/bash/ssh-remoteworker +21 -0
- data/lib/simpleworker/local_worker.rb +18 -0
- data/lib/simpleworker/runner.rb +59 -0
- data/lib/simpleworker/ssh_worker.rb +33 -0
- data/lib/simpleworker/version.rb +4 -0
- data/lib/simpleworker.rb +11 -0
- data/simpleworker.gemspec +27 -0
- data/spec/simpleworker/local_worker_spec.rb +33 -0
- data/spec/simpleworker/runner_spec.rb +19 -0
- data/spec/simpleworker/ssh_worker_spec.rb +43 -0
- data/spec/spec_helper.rb +3 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fe17f8a2b92b4c0ce10fd235a2a2b4ea85e5a70
|
4
|
+
data.tar.gz: 9175ffcdb89eda2144fad564145cbe7c8a009364
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 560792ce1d89592887af9bbd0c069f425e33d4be05438c253d5c1189053870454e4d8db553351de66ea72eba7c9edb617a5d1e4563fead91762dce762b748faf
|
7
|
+
data.tar.gz: 5fc38d0395d77ea5480859edc6c509da306cc2fa62830932a531707f4c4dbce4529ed628f141ca6d71b68c9447ee60465dca21fe77275f0bebe7d0e0d334e887
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -fs
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
SimpleWorker
|
2
|
+
============
|
3
|
+
|
4
|
+
Distribute automation scripts on multiple machines.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
=====
|
8
|
+
|
9
|
+
Create `simpleworker.yml` in the projects working directory. Ruby must be
|
10
|
+
setup on the remote host such that it is available in the login shell.
|
11
|
+
|
12
|
+
```yml
|
13
|
+
---
|
14
|
+
workers:
|
15
|
+
- type: ssh # type of worker
|
16
|
+
directory: /tmp/foobar # directory on remote host
|
17
|
+
user: bill # user on remote host
|
18
|
+
host: my.remote.host.com # remote host name
|
19
|
+
```
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'simpleworker'
|
23
|
+
|
24
|
+
# execute with workers configured in $PWD/simpleworker.yml
|
25
|
+
SimpleWorker::Runnner.run "my-command"
|
26
|
+
|
27
|
+
# execute with a special worker configuration
|
28
|
+
SimpleWorker::Runner.load("my-worker-config.yml").run "my-command"
|
29
|
+
```
|
30
|
+
|
31
|
+
Note on Patches/Pull Requests
|
32
|
+
=============================
|
33
|
+
|
34
|
+
* Fork the project.
|
35
|
+
* Make your feature addition or bug fix.
|
36
|
+
* Add tests for it. This is important so I don't break it in a
|
37
|
+
future version unintentionally.
|
38
|
+
* Commit, do not mess with rakefile, version, or history.
|
39
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
40
|
+
* Send me a pull request. Bonus points for topic branches.
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module SimpleWorker::AbstractWorker
|
3
|
+
|
4
|
+
attr_accessor :script, :cmd
|
5
|
+
|
6
|
+
def start
|
7
|
+
if script.kind_of? Array
|
8
|
+
@process = ChildProcess.build *script
|
9
|
+
else
|
10
|
+
@process = ChildProcess.build script
|
11
|
+
end
|
12
|
+
|
13
|
+
@process.io.inherit!
|
14
|
+
|
15
|
+
set_process_env
|
16
|
+
|
17
|
+
@process.start
|
18
|
+
end
|
19
|
+
|
20
|
+
def wait
|
21
|
+
@process.wait
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop
|
25
|
+
@process.stop
|
26
|
+
end
|
27
|
+
|
28
|
+
def env
|
29
|
+
@env
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def set_process_env
|
35
|
+
env['cmd'] ||= cmd
|
36
|
+
|
37
|
+
env.each do |key, value|
|
38
|
+
@process.environment[key] = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
rsync -ar --delete -e ssh "${PWD}/" "${user}@${host}:${directory}"
|
4
|
+
|
5
|
+
remote_script=$(cat << EOF
|
6
|
+
|
7
|
+
cd ${directory};
|
8
|
+
echo "Ruby Version: \$(ruby -v)";
|
9
|
+
echo "Which ruby: \$(which ruby)";
|
10
|
+
|
11
|
+
echo "PWD: \${PWD}";
|
12
|
+
|
13
|
+
bundle install;
|
14
|
+
bundle exec ${cmd};
|
15
|
+
|
16
|
+
EOF
|
17
|
+
)
|
18
|
+
|
19
|
+
ssh "${user}@${host}" "bash -lc '${remote_script}'"
|
20
|
+
|
21
|
+
rsync -ar -e ssh "${user}@${host}:${directory}/" "${PWD}/"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module SimpleWorker
|
3
|
+
class LocalWorker
|
4
|
+
include AbstractWorker
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@script = %W[bash #{File.expand_path(File.dirname(__FILE__))}/bash/simple-localworker]
|
8
|
+
@env = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create(config = {})
|
12
|
+
worker = new
|
13
|
+
worker.script = config['script'] if config.has_key? 'script'
|
14
|
+
worker.cmd = config['cmd'] if config.has_key? 'cmd'
|
15
|
+
worker
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
module SimpleWorker
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@workers = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run(cmd = 'rake')
|
10
|
+
new.load.run(cmd)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load(config = 'simpleworker.yml')
|
14
|
+
new.load(config)
|
15
|
+
end
|
16
|
+
|
17
|
+
def load(config = 'simpleworker.yml')
|
18
|
+
data = YAML.load( IO.read(config) )
|
19
|
+
data['workers'].each do |config|
|
20
|
+
case config['type']
|
21
|
+
when 'ssh'
|
22
|
+
@workers << SshWorker.create(config)
|
23
|
+
else
|
24
|
+
@workers << LocalWorker.create(config)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def run(cmd = 'rake')
|
32
|
+
@workers.each do |worker|
|
33
|
+
worker.cmd = cmd
|
34
|
+
end
|
35
|
+
start
|
36
|
+
process
|
37
|
+
stop
|
38
|
+
rescue Interrupt
|
39
|
+
stop
|
40
|
+
rescue StandardError => e
|
41
|
+
stop
|
42
|
+
raise e
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def start
|
48
|
+
@workers.each &:start
|
49
|
+
end
|
50
|
+
|
51
|
+
def process
|
52
|
+
@workers.each &:wait
|
53
|
+
end
|
54
|
+
|
55
|
+
def stop
|
56
|
+
@workers.each &:stop
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
module SimpleWorker
|
3
|
+
class SshWorker
|
4
|
+
include AbstractWorker
|
5
|
+
|
6
|
+
attr_accessor :directory, :user, :host
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@script = %W[bash #{File.expand_path(File.dirname(__FILE__))}/bash/ssh-remoteworker]
|
10
|
+
@env = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create(config = {})
|
14
|
+
worker = new
|
15
|
+
worker.script = config['script'] if config.has_key? 'script'
|
16
|
+
worker.cmd = config['cmd'] if config.has_key? 'cmd'
|
17
|
+
worker.user = config['user'] if config.has_key? 'user'
|
18
|
+
worker.host = config['host'] if config.has_key? 'host'
|
19
|
+
worker.directory = config['directory'] if config.has_key? 'directory'
|
20
|
+
worker
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_process_env
|
26
|
+
env['user'] = user || `whoami`
|
27
|
+
env['host'] = host || 'localhost'
|
28
|
+
env['directory'] = directory || Dir.pwd
|
29
|
+
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/simpleworker.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simpleworker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simpleworker"
|
7
|
+
s.version = SimpleWorker::VERSION
|
8
|
+
s.licenses = ['MIT']
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Jason Gowan"]
|
11
|
+
s.email = ["gowanjason@gmail.com"]
|
12
|
+
s.homepage = "https://github.com/jesg/simpleworker"
|
13
|
+
s.summary = %q{Distribute ruby scripts on multiple machines}
|
14
|
+
s.description = %q{Distribute ruby scripts on multiple machines for automated testing.}
|
15
|
+
|
16
|
+
s.rubyforge_project = "simpleworker"
|
17
|
+
|
18
|
+
s.add_dependency 'childprocess', '>= 0.5.3'
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", "~> 2.5"
|
21
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
module SimpleWorker
|
4
|
+
describe LocalWorker do
|
5
|
+
let(:mock_env) { double(Hash) }
|
6
|
+
let(:mock_process) { double(ChildProcess, :start => nil, :stop => nil, :wait => nil, :io => double('io').as_null_object, :environment => mock_env) }
|
7
|
+
|
8
|
+
it 'can start local worker with defaults' do
|
9
|
+
ChildProcess.should_receive(:build).with('bash', end_with('simple-localworker')).and_return(mock_process)
|
10
|
+
mock_process.should_receive(:start)
|
11
|
+
mock_env.should_receive(:[]=).with('cmd', 'rake')
|
12
|
+
|
13
|
+
worker = LocalWorker.new
|
14
|
+
worker.cmd = 'rake'
|
15
|
+
worker.start
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can start local worker with customization' do
|
19
|
+
ChildProcess.should_receive(:build).with('bash', end_with('simple-localworker')).and_return(mock_process)
|
20
|
+
mock_process.should_receive(:start)
|
21
|
+
mock_env.should_receive(:[]=).with('cmd', 'cuke')
|
22
|
+
mock_process.should_receive(:wait)
|
23
|
+
mock_process.should_receive(:stop)
|
24
|
+
|
25
|
+
worker = LocalWorker.new
|
26
|
+
worker.cmd = 'cuke'
|
27
|
+
worker.start
|
28
|
+
worker.wait
|
29
|
+
worker.stop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
module SimpleWorker
|
4
|
+
describe Runner do
|
5
|
+
let(:mock_worker) { double(AbstractWorker, :start => nil, :wait => nil, :stop => nil) }
|
6
|
+
|
7
|
+
it 'can run workers' do
|
8
|
+
mock_worker.should_receive(:start)
|
9
|
+
mock_worker.should_receive(:cmd=).with('cuke')
|
10
|
+
mock_worker.should_receive(:wait)
|
11
|
+
mock_worker.should_receive(:stop)
|
12
|
+
IO.should_receive(:read).with('simpleworker.yml').and_return('hi')
|
13
|
+
YAML.should_receive(:load).with('hi').and_return({'workers' => [{'type' => 'ssh'}]})
|
14
|
+
SshWorker.should_receive(:create).and_return(mock_worker)
|
15
|
+
|
16
|
+
Runner.run 'cuke'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
module SimpleWorker
|
4
|
+
describe SshWorker do
|
5
|
+
let(:mock_env) { double(Hash) }
|
6
|
+
let(:mock_process) { double(ChildProcess, :start => nil, :stop => nil, :wait => nil, :io => double('io').as_null_object, :environment => mock_env) }
|
7
|
+
|
8
|
+
it 'can start ssh worker with defaults' do
|
9
|
+
ChildProcess.should_receive(:build).with('bash', end_with('ssh-remoteworker')).and_return(mock_process)
|
10
|
+
mock_process.should_receive(:start)
|
11
|
+
mock_env.should_receive(:[]=).once.with('cmd', 'rake')
|
12
|
+
mock_env.should_receive(:[]=).once.with('user', `whoami`)
|
13
|
+
mock_env.should_receive(:[]=).once.with('host', 'localhost')
|
14
|
+
mock_env.should_receive(:[]=).once.with('directory', Dir.pwd)
|
15
|
+
|
16
|
+
worker = SshWorker.new
|
17
|
+
worker.cmd = 'rake'
|
18
|
+
worker.start
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can start ssh worker with customization' do
|
22
|
+
ChildProcess.should_receive(:build).with('bash', end_with('ssh-remoteworker')).and_return(mock_process)
|
23
|
+
mock_process.should_receive(:start)
|
24
|
+
mock_env.should_receive(:[]=).once.with('cmd', 'cuke')
|
25
|
+
mock_env.should_receive(:[]=).once.with('user', 'bob')
|
26
|
+
mock_env.should_receive(:[]=).once.with('host', 'foo')
|
27
|
+
mock_env.should_receive(:[]=).once.with('directory', 'bar')
|
28
|
+
|
29
|
+
mock_process.should_receive(:wait)
|
30
|
+
mock_process.should_receive(:stop)
|
31
|
+
|
32
|
+
worker = SshWorker.new
|
33
|
+
worker.cmd = 'cuke'
|
34
|
+
worker.user = 'bob'
|
35
|
+
worker.host = 'foo'
|
36
|
+
worker.directory = 'bar'
|
37
|
+
worker.start
|
38
|
+
worker.wait
|
39
|
+
worker.stop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simpleworker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Gowan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: childprocess
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.2
|
55
|
+
description: Distribute ruby scripts on multiple machines for automated testing.
|
56
|
+
email:
|
57
|
+
- gowanjason@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/simpleworker.rb
|
68
|
+
- lib/simpleworker/abstract_worker.rb
|
69
|
+
- lib/simpleworker/bash/simple-localworker
|
70
|
+
- lib/simpleworker/bash/ssh-remoteworker
|
71
|
+
- lib/simpleworker/local_worker.rb
|
72
|
+
- lib/simpleworker/runner.rb
|
73
|
+
- lib/simpleworker/ssh_worker.rb
|
74
|
+
- lib/simpleworker/version.rb
|
75
|
+
- simpleworker.gemspec
|
76
|
+
- spec/simpleworker/local_worker_spec.rb
|
77
|
+
- spec/simpleworker/runner_spec.rb
|
78
|
+
- spec/simpleworker/ssh_worker_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: https://github.com/jesg/simpleworker
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project: simpleworker
|
100
|
+
rubygems_version: 2.2.0
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Distribute ruby scripts on multiple machines
|
104
|
+
test_files:
|
105
|
+
- spec/simpleworker/local_worker_spec.rb
|
106
|
+
- spec/simpleworker/runner_spec.rb
|
107
|
+
- spec/simpleworker/ssh_worker_spec.rb
|
108
|
+
- spec/spec_helper.rb
|