serverkit 0.2.7 → 0.2.8
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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/lib/serverkit/actions/base.rb +24 -21
- data/lib/serverkit/command.rb +44 -6
- data/lib/serverkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65f599078706665a41712a95fac9fceb098ab617
|
4
|
+
data.tar.gz: c83b4d7ca7377f8029300646eb11f5ea9f105a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ab8e2a496800ee62a5fcd8676e5d82fa8cd2b96c07a03462fc535d8f489e3f1e1d1731e042bfdff1c0d1bdb231733b23bfbb2f825179c80deaeec0f0b034de
|
7
|
+
data.tar.gz: 36bfe26ca78820a08f6049237fb74793de3a711db6d03059f3b8140a0851f8d33c5f5c681881e369b1fe682158293decf62671416e1c9c4d6653f886c7265faf
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "bundler"
|
2
2
|
require "etc"
|
3
3
|
require "net/ssh"
|
4
|
-
require "serverkit/errors/missing_recipe_path_argument_error"
|
5
4
|
require "serverkit/loaders/recipe_loader"
|
6
5
|
require "serverkit/recipe"
|
7
6
|
require "slop"
|
@@ -10,9 +9,15 @@ require "specinfra"
|
|
10
9
|
module Serverkit
|
11
10
|
module Actions
|
12
11
|
class Base
|
13
|
-
# @param [
|
14
|
-
|
15
|
-
|
12
|
+
# @param [String, nil] hosts
|
13
|
+
# @param [String] recipe_path
|
14
|
+
# @param [Hash, nil] ssh_options For override default ssh options
|
15
|
+
# @param [Stirng, nil] variables_path
|
16
|
+
def initialize(hosts: nil, recipe_path: nil, ssh_options: nil, variables_path: nil)
|
17
|
+
@hosts = hosts
|
18
|
+
@recipe_path = recipe_path
|
19
|
+
@ssh_options = ssh_options
|
20
|
+
@variables_path = variables_path
|
16
21
|
end
|
17
22
|
|
18
23
|
def call
|
@@ -28,14 +33,14 @@ module Serverkit
|
|
28
33
|
|
29
34
|
# @return [Array<Specinfra::Backend::Base>]
|
30
35
|
def backends
|
31
|
-
if
|
36
|
+
if has_hosts?
|
32
37
|
hosts.map do |host|
|
33
38
|
backend_class.new(
|
34
39
|
disable_sudo: true,
|
35
40
|
host: host,
|
36
41
|
ssh_options: {
|
37
42
|
user: ssh_user_for(host),
|
38
|
-
},
|
43
|
+
}.merge(ssh_options),
|
39
44
|
)
|
40
45
|
end
|
41
46
|
else
|
@@ -44,7 +49,7 @@ module Serverkit
|
|
44
49
|
end
|
45
50
|
|
46
51
|
def backend_class
|
47
|
-
if
|
52
|
+
if has_hosts?
|
48
53
|
Specinfra::Backend::Ssh
|
49
54
|
else
|
50
55
|
Specinfra::Backend::Exec
|
@@ -56,16 +61,14 @@ module Serverkit
|
|
56
61
|
rescue Bundler::GemfileNotFound
|
57
62
|
end
|
58
63
|
|
59
|
-
def
|
60
|
-
|
64
|
+
def has_hosts?
|
65
|
+
!@hosts.nil?
|
61
66
|
end
|
62
67
|
|
63
|
-
# @return [
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
on "--hosts=", "Pass hostname to execute command over SSH"
|
68
|
-
on "--variables=", "Path to variables file for ERB recipe"
|
68
|
+
# @return [Array<String>, nil]
|
69
|
+
def hosts
|
70
|
+
if has_hosts?
|
71
|
+
@hosts.split(",")
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
@@ -74,14 +77,14 @@ module Serverkit
|
|
74
77
|
abort_with_errors unless recipe.valid?
|
75
78
|
end
|
76
79
|
|
77
|
-
# @return [
|
78
|
-
def
|
79
|
-
@
|
80
|
+
# @return [Hash]
|
81
|
+
def ssh_options
|
82
|
+
@ssh_options || {}
|
80
83
|
end
|
81
84
|
|
82
|
-
# @return [
|
83
|
-
def
|
84
|
-
@
|
85
|
+
# @return [Serverkit::Recipe]
|
86
|
+
def recipe
|
87
|
+
@recipe ||= Loaders::RecipeLoader.new(@recipe_path, variables_path: @variables_path).load
|
85
88
|
end
|
86
89
|
|
87
90
|
# @param [String] host
|
data/lib/serverkit/command.rb
CHANGED
@@ -7,6 +7,8 @@ require "serverkit/errors/missing_recipe_path_argument_error"
|
|
7
7
|
require "serverkit/errors/unknown_action_name_error"
|
8
8
|
|
9
9
|
module Serverkit
|
10
|
+
# Command clsas takes care of command line interface.
|
11
|
+
# It builds and runs an Action object from given command line arguements.
|
10
12
|
class Command
|
11
13
|
# @param [Array<String>] argv
|
12
14
|
def initialize(argv)
|
@@ -34,26 +36,62 @@ module Serverkit
|
|
34
36
|
|
35
37
|
private
|
36
38
|
|
39
|
+
# @note #inspect is reserved ;(
|
40
|
+
def _inspect
|
41
|
+
Actions::Inspect.new(action_options).call
|
42
|
+
end
|
43
|
+
|
37
44
|
# @return [String, nil]
|
38
45
|
def action_name
|
39
46
|
@argv.first
|
40
47
|
end
|
41
48
|
|
49
|
+
# @return [Hash<Symbol => String>]
|
50
|
+
def action_options
|
51
|
+
{
|
52
|
+
hosts: hosts,
|
53
|
+
recipe_path: recipe_path,
|
54
|
+
variables_path: variables_path,
|
55
|
+
}.reject do |key, value|
|
56
|
+
value.nil?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
42
60
|
def apply
|
43
|
-
Actions::Apply.new(
|
61
|
+
Actions::Apply.new(action_options).call
|
44
62
|
end
|
45
63
|
|
46
64
|
def check
|
47
|
-
Actions::Check.new(
|
65
|
+
Actions::Check.new(action_options).call
|
48
66
|
end
|
49
67
|
|
50
|
-
# @note
|
51
|
-
|
52
|
-
|
68
|
+
# @note This options are commonly used from all actions for now, however,
|
69
|
+
# someday a new action that requires options might appear.
|
70
|
+
# @return [Slop]
|
71
|
+
def command_line_options
|
72
|
+
@command_line_options ||= Slop.parse!(@argv, help: true) do
|
73
|
+
banner "Usage: serverkit ACTION [options]"
|
74
|
+
on "--hosts=", "Pass hostname to execute command over SSH"
|
75
|
+
on "--variables=", "Path to variables file for ERB recipe"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [String, nil]
|
80
|
+
def hosts
|
81
|
+
command_line_options[:hosts]
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [String]
|
85
|
+
def recipe_path
|
86
|
+
@argv[1] or raise Errors::MissingRecipePathArgumentError
|
53
87
|
end
|
54
88
|
|
55
89
|
def validate
|
56
|
-
Actions::Validate.new(
|
90
|
+
Actions::Validate.new(action_options).call
|
91
|
+
end
|
92
|
+
|
93
|
+
def variables_path
|
94
|
+
command_line_options[:variables]
|
57
95
|
end
|
58
96
|
end
|
59
97
|
end
|
data/lib/serverkit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|