sshkit 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +31 -1
- data/EXAMPLES.md +33 -0
- data/Gemfile.lock +5 -5
- data/README.md +3 -0
- data/lib/sshkit/configuration.rb +2 -4
- data/lib/sshkit/host.rb +6 -0
- data/lib/sshkit/version.rb +1 -1
- data/test/unit/backends/test_printer.rb +2 -4
- data/test/unit/test_configuration.rb +1 -13
- data/test/unit/test_host.rb +7 -0
- metadata +1 -2
- data/example.rb +0 -28
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,38 @@
|
|
1
|
-
##
|
1
|
+
## Changelog
|
2
2
|
|
3
3
|
This file is written in reverse chronological order, newer releases will
|
4
4
|
appear at the top.
|
5
5
|
|
6
|
+
## 0.0.5
|
7
|
+
|
8
|
+
* Removed configuration option `SSHKit.config.format` (see below)
|
9
|
+
* Removed configuration option `SSHKit.config.runner` (see below)
|
10
|
+
|
11
|
+
The format should now be set by doing:
|
12
|
+
|
13
|
+
SSHKit.config.output = File.open('/dev/null')
|
14
|
+
SSHKit.config.output = MyFormatterClass.new($stdout)
|
15
|
+
|
16
|
+
The library ships with three formatters, `BlackHole`, `Dot` and `Pretty`.
|
17
|
+
|
18
|
+
The default is `Pretty`, but can easily be changed:
|
19
|
+
|
20
|
+
SSHKit.config.output = SSHKit::Formatter::Pretty.new($stdout)
|
21
|
+
SSHKit.config.output = SSHKit::Formatter::Dot.new($stdout)
|
22
|
+
SSHKit.config.output = SSHKit::Formatter::BlackHole.new($stdout)
|
23
|
+
|
24
|
+
The one and only argument to the formatter is the *String/StringIO*ish object
|
25
|
+
to which the output should be sent. (It should be possible to stack
|
26
|
+
formatters, or build a multi-formatter to log, and stream to the screen, for
|
27
|
+
example)
|
28
|
+
|
29
|
+
The *runner* is now set by `default_options` on the Coordinator class. The
|
30
|
+
default is still *:parallel*, and can be overridden on the `on()` (or
|
31
|
+
`Coordinator#each`) calls directly.
|
32
|
+
|
33
|
+
There is no global way to change the runner style for all `on()` calls as of
|
34
|
+
version `0.0.5`.
|
35
|
+
|
6
36
|
## 0.0.4
|
7
37
|
|
8
38
|
* Rename the ConnectionManager class to Coordinator, connections are handled
|
data/EXAMPLES.md
CHANGED
@@ -165,3 +165,36 @@ An extension of the behaviour above, if you write a command like this:
|
|
165
165
|
**Note:** The logic which reformats the script into a oneliner may be naïve, but in all
|
166
166
|
known test cases, it works. The key thing is that `if` is not mapped to
|
167
167
|
`/usr/bin/env if`, which would break with a syntax error.
|
168
|
+
|
169
|
+
## Using with Rake
|
170
|
+
|
171
|
+
Into the `Rakefile` simply put something like:
|
172
|
+
|
173
|
+
require 'sshkit/dsl'
|
174
|
+
|
175
|
+
SSHKit.config.command_map[:rake] = "./bin/rake"
|
176
|
+
|
177
|
+
desc "Deploy the site, pulls from Git, migrate the db and precompile assets, then restart Passenger."
|
178
|
+
task :deploy do
|
179
|
+
on "example.com" do |host|
|
180
|
+
within "/opt/sites/example.com" do
|
181
|
+
execute :git, :pull
|
182
|
+
execute :bundle, :install, '--deployment'
|
183
|
+
execute :rake, 'db:migrate'
|
184
|
+
execute :rake, 'assets:precompile'
|
185
|
+
execute :touch, 'tmp/restart.txt'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
## Using without the DSL
|
191
|
+
|
192
|
+
The *Coordinator* will resolve all hosts into *Host* objects, you can mix and
|
193
|
+
match.
|
194
|
+
|
195
|
+
Coordinator.new("one.example.com", SSHKit::Host.new('two.example.com')).each in: :sequence do
|
196
|
+
puts capture :uptime
|
197
|
+
end
|
198
|
+
|
199
|
+
You might also look at `./lib/sshkit/dsl.rb` where you can see almost the
|
200
|
+
exact code as above, which implements the `on()` method.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sshkit (0.0.
|
4
|
+
sshkit (0.0.5)
|
5
5
|
net-ssh
|
6
6
|
term-ansicolor
|
7
7
|
|
@@ -9,20 +9,20 @@ GEM
|
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ZenTest (4.6.2)
|
12
|
-
ansi (1.4.
|
12
|
+
ansi (1.4.3)
|
13
13
|
archive-tar-minitar (0.5.2)
|
14
14
|
autotest (4.4.6)
|
15
15
|
ZenTest (>= 4.4.1)
|
16
16
|
childprocess (0.3.6)
|
17
17
|
ffi (~> 1.0, >= 1.0.6)
|
18
18
|
columnize (0.3.6)
|
19
|
-
debugger (1.2.
|
19
|
+
debugger (1.2.3)
|
20
20
|
columnize (>= 0.3.1)
|
21
21
|
debugger-linecache (~> 1.1.1)
|
22
22
|
debugger-ruby_core_source (~> 1.1.5)
|
23
23
|
debugger-linecache (1.1.2)
|
24
24
|
debugger-ruby_core_source (>= 1.1.1)
|
25
|
-
debugger-ruby_core_source (1.1.
|
25
|
+
debugger-ruby_core_source (1.1.6)
|
26
26
|
erubis (2.7.0)
|
27
27
|
ffi (1.2.0)
|
28
28
|
i18n (0.6.1)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
rake (10.0.3)
|
39
39
|
redcarpet (2.2.2)
|
40
40
|
term-ansicolor (1.0.7)
|
41
|
-
turn (0.9.
|
41
|
+
turn (0.9.6)
|
42
42
|
ansi
|
43
43
|
unindent (1.0)
|
44
44
|
vagrant (1.0.5)
|
data/README.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
**SSHKit** is a toolkit for running commands in a structured way on one or
|
4
4
|
more servers.
|
5
5
|
|
6
|
+
[![Build Status](https://travis-ci.org/wacku/sshkit.png?branch=master)](https://travis-ci.org/wacku/sshkit)
|
7
|
+
[![Dependency Status](https://gemnasium.com/wacku/sshkit.png)](https://gemnasium.com/wacku/sshkit)
|
8
|
+
|
6
9
|
## How might it work?
|
7
10
|
|
8
11
|
The typical use-case looks something like this:
|
data/lib/sshkit/configuration.rb
CHANGED
@@ -3,12 +3,10 @@ module SSHKit
|
|
3
3
|
class Configuration
|
4
4
|
|
5
5
|
attr_writer :command_map
|
6
|
-
attr_accessor :output, :
|
6
|
+
attr_accessor :output, :backend
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@output = $stdout
|
10
|
-
@format = :dot
|
11
|
-
@runner = :parallel
|
9
|
+
@output = SSHKit::Formatter::Pretty.new($stdout)
|
12
10
|
@backend = SSHKit::Backend::Netssh
|
13
11
|
end
|
14
12
|
|
data/lib/sshkit/host.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module SSHKit
|
2
4
|
|
3
5
|
UnparsableHostStringError = Class.new(StandardError)
|
@@ -48,6 +50,10 @@ module SSHKit
|
|
48
50
|
sprintf("%s@%s:%d", username, hostname, port)
|
49
51
|
end
|
50
52
|
|
53
|
+
def properties
|
54
|
+
@properties ||= OpenStruct.new
|
55
|
+
end
|
56
|
+
|
51
57
|
end
|
52
58
|
|
53
59
|
# @private
|
data/lib/sshkit/version.rb
CHANGED
@@ -27,12 +27,10 @@ module SSHKit
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_simple_printing
|
30
|
-
|
31
|
-
SSHKit.capture_output(
|
30
|
+
result = String.new
|
31
|
+
SSHKit.capture_output(result) do
|
32
32
|
printer.run
|
33
33
|
end
|
34
|
-
sio.rewind
|
35
|
-
result = sio.read
|
36
34
|
assert_equal <<-EOEXPECTED.unindent, result
|
37
35
|
if test ! -d /opt/sites/example.com; then echo "Directory does not exist '/opt/sites/example.com'" 1>&2; false; fi
|
38
36
|
cd /opt/sites/example.com && /usr/bin/env date
|
@@ -10,23 +10,11 @@ module SSHKit
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_output
|
13
|
-
|
13
|
+
assert SSHKit.config.output.is_a? SSHKit::Formatter::Pretty
|
14
14
|
assert SSHKit.config.output = $stderr
|
15
15
|
assert_equal $stderr, SSHKit.config.output
|
16
16
|
end
|
17
17
|
|
18
|
-
def test_runner
|
19
|
-
assert_equal :parallel, SSHKit.config.runner
|
20
|
-
assert SSHKit.config.runner = :sequence
|
21
|
-
assert_equal :sequence, SSHKit.config.runner
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_format
|
25
|
-
assert_equal :dot, SSHKit.config.format
|
26
|
-
assert SSHKit.config.format = :pretty
|
27
|
-
assert_equal :pretty, SSHKit.config.format
|
28
|
-
end
|
29
|
-
|
30
18
|
def test_backend
|
31
19
|
assert_equal SSHKit::Backend::Netssh, SSHKit.config.backend
|
32
20
|
assert SSHKit.config.backend = SSHKit::Backend::Printer
|
data/test/unit/test_host.rb
CHANGED
@@ -60,6 +60,13 @@ module SSHKit
|
|
60
60
|
assert Host.new('example.com').equal? Host.new('example.com')
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_arbitrary_host_properties
|
64
|
+
h = Host.new('example.com')
|
65
|
+
assert_equal nil, h.properties.roles
|
66
|
+
assert h.properties.roles = [:web, :app]
|
67
|
+
assert_equal [:web, :app], h.properties.roles
|
68
|
+
end
|
69
|
+
|
63
70
|
end
|
64
71
|
|
65
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -235,7 +235,6 @@ files:
|
|
235
235
|
- Vagrantfile
|
236
236
|
- assets/images/example_output.png
|
237
237
|
- assets/images/logo.png
|
238
|
-
- example.rb
|
239
238
|
- lib/core_ext/array.rb
|
240
239
|
- lib/core_ext/hash.rb
|
241
240
|
- lib/sshkit.rb
|
data/example.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Ruby 1.9 doesn't include the current
|
4
|
-
# working directory on the load path.
|
5
|
-
$: << Dir.pwd + '/lib/'
|
6
|
-
|
7
|
-
# Automatically sucks in the `sshkit`
|
8
|
-
# files so that you don't need to.
|
9
|
-
require 'sshkit/dsl'
|
10
|
-
|
11
|
-
directory = '/opt/sites/web_application'
|
12
|
-
hosts = SSHKit::Host.new("root@example.com")
|
13
|
-
|
14
|
-
SSHKit.config.output = SSHKit::Formatter::Pretty.new($stdout)
|
15
|
-
|
16
|
-
on hosts do |host|
|
17
|
-
target = '/opt/rack-rack-repository'
|
18
|
-
if host.hostname =~ /seven/
|
19
|
-
target = '/var/rack-rack-repository'
|
20
|
-
end
|
21
|
-
if execute(:test, "-d #{target}")
|
22
|
-
within target do
|
23
|
-
execute :git, :pull
|
24
|
-
end
|
25
|
-
else
|
26
|
-
execute :git, :clone, 'git://github.com/rack/rack.git', target
|
27
|
-
end
|
28
|
-
end
|