serverkit 0.0.6 → 0.1.0
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 +4 -0
- data/README.md +16 -16
- data/lib/serverkit/actions/base.rb +50 -9
- data/lib/serverkit/command.rb +11 -30
- data/lib/serverkit/errors/base.rb +1 -1
- data/lib/serverkit/errors/missing_action_name_argument_error.rb +12 -0
- data/lib/serverkit/errors/missing_recipe_path_argument_error.rb +12 -0
- data/lib/serverkit/errors/non_existent_path_error.rb +17 -0
- data/lib/serverkit/errors/unknown_action_name_error.rb +17 -0
- data/lib/serverkit/loaders/base_loader.rb +3 -0
- data/lib/serverkit/version.rb +1 -1
- data/serverkit.gemspec +1 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d32c86ed73e992891971d99e1f5fed1c3d20e9
|
4
|
+
data.tar.gz: 53173d404b9a4b86e7d0c84f6717531ab73e290c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3063377dafa07b971082c048a1795aa16a0b0e0c714f9779f599c2caced4a2486eec5fe27d5510b5df203a8748f736fa3b5cfeda23a5eebbb499ede87d76c042
|
7
|
+
data.tar.gz: 2193c293ed47692cccfb58b0221086c5fb6cef4f232e61d7a64e69c35e3195c719f3fb4dbe337369bdd283754f9096848c8190dae087fc69f8146aaaeb3decad
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Validates recipe schema, resources, and attributes.
|
|
9
9
|
For instance, it shows validation error if `source` attributes is missing in `file` resource.
|
10
10
|
|
11
11
|
```
|
12
|
-
$ serverkit validate
|
12
|
+
$ serverkit validate recipe.yml
|
13
13
|
Error: source attribute is required in file resource
|
14
14
|
Error: path attribute can't be unreadable path in recipe resource
|
15
15
|
```
|
@@ -18,7 +18,7 @@ Error: path attribute can't be unreadable path in recipe resource
|
|
18
18
|
Shows fully-expanded recipe data in JSON format.
|
19
19
|
|
20
20
|
```
|
21
|
-
$ serverkit inspect
|
21
|
+
$ serverkit inspect recipe.yml
|
22
22
|
{
|
23
23
|
"resources": [
|
24
24
|
{
|
@@ -61,7 +61,7 @@ $ serverkit inspect --recipe=recipe.yml
|
|
61
61
|
Shows the difference between your recipe and the state of the target host.
|
62
62
|
|
63
63
|
```
|
64
|
-
$ serverkit check
|
64
|
+
$ serverkit check recipe.yml
|
65
65
|
[OK] install_mysql
|
66
66
|
[OK] install_redis
|
67
67
|
[OK] install_licecap
|
@@ -74,7 +74,7 @@ $ serverkit check --recipe=recipe.yml
|
|
74
74
|
Executes migration process to fill-in the gaps.
|
75
75
|
|
76
76
|
```
|
77
|
-
$ serverkit apply
|
77
|
+
$ serverkit apply recipe.yml
|
78
78
|
[SKIP] install_mysql
|
79
79
|
[SKIP] install_redis
|
80
80
|
[SKIP] install_licecap
|
@@ -97,18 +97,18 @@ A recipe can be specified as a path to one of the following patterns:
|
|
97
97
|
- Directory including recipe files recursively
|
98
98
|
|
99
99
|
```
|
100
|
-
$ serverkit apply
|
101
|
-
$ serverkit apply
|
102
|
-
$ serverkit apply
|
103
|
-
$ serverkit apply
|
104
|
-
$ serverkit apply
|
105
|
-
$ serverkit apply
|
106
|
-
$ serverkit apply
|
107
|
-
$ serverkit apply
|
108
|
-
$ serverkit apply
|
109
|
-
$ serverkit apply
|
110
|
-
$ serverkit apply
|
111
|
-
$ serverkit apply
|
100
|
+
$ serverkit apply recipe
|
101
|
+
$ serverkit apply recipe.json
|
102
|
+
$ serverkit apply recipe.json.erb
|
103
|
+
$ serverkit apply recipe.json.erb --variables=variables
|
104
|
+
$ serverkit apply recipe.json.erb --variables=variables.json
|
105
|
+
$ serverkit apply recipe.json.erb --variables=variables.json.erb
|
106
|
+
$ serverkit apply recipe.json.erb --variables=variables.yml
|
107
|
+
$ serverkit apply recipe.json.erb --variables=variables.yml.erb
|
108
|
+
$ serverkit apply recipe.json.erb --variables=variables/
|
109
|
+
$ serverkit apply recipe.yml
|
110
|
+
$ serverkit apply recipe.yml.erb
|
111
|
+
$ serverkit apply recipes/
|
112
112
|
```
|
113
113
|
|
114
114
|
### Variables
|
@@ -1,17 +1,17 @@
|
|
1
|
+
require "etc"
|
2
|
+
require "net/ssh"
|
3
|
+
require "serverkit/errors/missing_recipe_path_argument_error"
|
1
4
|
require "serverkit/loaders/recipe_loader"
|
2
5
|
require "serverkit/recipe"
|
6
|
+
require "slop"
|
3
7
|
require "specinfra"
|
4
8
|
|
5
9
|
module Serverkit
|
6
10
|
module Actions
|
7
11
|
class Base
|
8
|
-
# @param [
|
9
|
-
def initialize(
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
def call
|
14
|
-
raise NotImplementedError
|
12
|
+
# @param [Array] argv Command-line arguments given to serverkit executable
|
13
|
+
def initialize(argv)
|
14
|
+
@argv = argv
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -22,12 +22,53 @@ module Serverkit
|
|
22
22
|
|
23
23
|
# @return [Specinfra::Backend::Base]
|
24
24
|
def backend
|
25
|
-
@backend ||=
|
25
|
+
@backend ||= backend_class.new(backend_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def backend_class
|
29
|
+
if host
|
30
|
+
Specinfra::Backend::Ssh
|
31
|
+
else
|
32
|
+
Specinfra::Backend::Exec
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def backend_options
|
37
|
+
{
|
38
|
+
disable_sudo: true,
|
39
|
+
host: host,
|
40
|
+
ssh_options: {
|
41
|
+
user: ssh_user,
|
42
|
+
},
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def host
|
47
|
+
options[:host]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Slop] Command-line options
|
51
|
+
def options
|
52
|
+
@options ||= Slop.parse!(@argv, help: true) do
|
53
|
+
banner "Usage: serverkit ACTION [options]"
|
54
|
+
on "--host=", "Pass hostname to use SSH"
|
55
|
+
on "--variables=", "Path to variables file for ERB recipe"
|
56
|
+
end
|
26
57
|
end
|
27
58
|
|
28
59
|
# @return [Serverkit::Recipe]
|
29
60
|
def recipe
|
30
|
-
@recipe ||= Loaders::RecipeLoader.new(
|
61
|
+
@recipe ||= Loaders::RecipeLoader.new(recipe_path, variables_path: options[:variables]).load
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [String, nil]
|
65
|
+
def recipe_path
|
66
|
+
@argv[1] or raise Errors::MissingRecipePathArgumentError
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [String] User name used on SSH
|
70
|
+
def ssh_user
|
71
|
+
Net::SSH::Config.for(host)[:user] || Etc.getlogin
|
31
72
|
end
|
32
73
|
end
|
33
74
|
end
|
data/lib/serverkit/command.rb
CHANGED
@@ -2,7 +2,9 @@ require "serverkit/actions/apply"
|
|
2
2
|
require "serverkit/actions/check"
|
3
3
|
require "serverkit/actions/inspect"
|
4
4
|
require "serverkit/actions/validate"
|
5
|
-
require "
|
5
|
+
require "serverkit/errors/missing_action_name_argument_error"
|
6
|
+
require "serverkit/errors/missing_recipe_path_argument_error"
|
7
|
+
require "serverkit/errors/unknown_action_name_error"
|
6
8
|
|
7
9
|
module Serverkit
|
8
10
|
class Command
|
@@ -14,7 +16,7 @@ module Serverkit
|
|
14
16
|
def call
|
15
17
|
case action_name
|
16
18
|
when nil
|
17
|
-
|
19
|
+
raise Errors::MissingActionNameArgumentError
|
18
20
|
when "apply"
|
19
21
|
apply
|
20
22
|
when "check"
|
@@ -24,55 +26,34 @@ module Serverkit
|
|
24
26
|
when "validate"
|
25
27
|
validate
|
26
28
|
else
|
27
|
-
|
29
|
+
raise Errors::UnknownActionNameError
|
28
30
|
end
|
29
|
-
rescue Slop::MissingOptionError => exception
|
31
|
+
rescue Errors::Base, Slop::MissingOptionError => exception
|
30
32
|
abort "Error: #{exception}"
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
35
|
-
def abort_for_missing_action_name
|
36
|
-
abort "Error: Missing action name"
|
37
|
-
end
|
38
|
-
|
39
|
-
def abort_for_unknown_action_name
|
40
|
-
abort "Error: Unknown action name `#{action_name}`"
|
41
|
-
end
|
42
|
-
|
43
37
|
# @return [String, nil]
|
44
38
|
def action_name
|
45
|
-
|
39
|
+
@argv.first
|
46
40
|
end
|
47
41
|
|
48
42
|
def apply
|
49
|
-
Actions::Apply.new(
|
43
|
+
Actions::Apply.new(@argv).call
|
50
44
|
end
|
51
45
|
|
52
46
|
def check
|
53
|
-
Actions::Check.new(
|
54
|
-
end
|
55
|
-
|
56
|
-
def has_unknown_action_name?
|
57
|
-
!ACTION_NAMES.include?(action_name)
|
47
|
+
Actions::Check.new(@argv).call
|
58
48
|
end
|
59
49
|
|
60
50
|
# @note #inspect is reserved ;(
|
61
51
|
def _inspect
|
62
|
-
Actions::Inspect.new(
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [Hash] Command-line options
|
66
|
-
def options
|
67
|
-
@options ||= Slop.parse!(@argv) do
|
68
|
-
banner "Usage: serverkit ACTION [options]"
|
69
|
-
on "-r", "--recipe=", "Path to recipe file", required: true
|
70
|
-
on "--variables=", "Path to variables file for ERB recipe"
|
71
|
-
end
|
52
|
+
Actions::Inspect.new(@argv).call
|
72
53
|
end
|
73
54
|
|
74
55
|
def validate
|
75
|
-
Actions::Validate.new(
|
56
|
+
Actions::Validate.new(@argv).call
|
76
57
|
end
|
77
58
|
end
|
78
59
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "serverkit/errors/base"
|
2
|
+
|
3
|
+
module Serverkit
|
4
|
+
module Errors
|
5
|
+
class NonExistentPathError < Base
|
6
|
+
# @param [#to_s] path
|
7
|
+
def initialize(path)
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
def to_s
|
13
|
+
abort "No such file or directory `#{@path}`"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "serverkit/errors/base"
|
2
|
+
|
3
|
+
module Serverkit
|
4
|
+
module Errors
|
5
|
+
class UnknownActionNameError < Base
|
6
|
+
# @param [String] action_name
|
7
|
+
def initialize(action_name)
|
8
|
+
@action_name = action_name
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
def to_s
|
13
|
+
abort "Unknown action name `#{@action_name}`"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "erb"
|
2
2
|
require "json"
|
3
3
|
require "pathname"
|
4
|
+
require "serverkit/errors/non_existent_path_error"
|
4
5
|
require "tempfile"
|
5
6
|
require "yaml"
|
6
7
|
|
@@ -17,6 +18,8 @@ module Serverkit
|
|
17
18
|
# @todo Rescue Error::ENOENT error
|
18
19
|
def load
|
19
20
|
case
|
21
|
+
when !pathname.exist?
|
22
|
+
raise Errors::NonExistentPathError, pathname
|
20
23
|
when has_directory_path?
|
21
24
|
load_from_directory
|
22
25
|
when has_erb_path?
|
data/lib/serverkit/version.rb
CHANGED
data/serverkit.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_runtime_dependency "activemodel"
|
20
20
|
spec.add_runtime_dependency "activesupport"
|
21
|
+
spec.add_runtime_dependency "highline"
|
21
22
|
spec.add_runtime_dependency "slop", "~> 3.4"
|
22
23
|
spec.add_runtime_dependency "specinfra"
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: slop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +188,10 @@ files:
|
|
174
188
|
- lib/serverkit/errors/base.rb
|
175
189
|
- lib/serverkit/errors/invalid_recipe_type_error.rb
|
176
190
|
- lib/serverkit/errors/invalid_resources_type_error.rb
|
191
|
+
- lib/serverkit/errors/missing_action_name_argument_error.rb
|
192
|
+
- lib/serverkit/errors/missing_recipe_path_argument_error.rb
|
193
|
+
- lib/serverkit/errors/non_existent_path_error.rb
|
194
|
+
- lib/serverkit/errors/unknown_action_name_error.rb
|
177
195
|
- lib/serverkit/errors/unknown_resource_type_error.rb
|
178
196
|
- lib/serverkit/loaders/base_loader.rb
|
179
197
|
- lib/serverkit/loaders/recipe_loader.rb
|