serverkit 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 656a155cfa4b8c499bafcfdbda76075bb28d1570
4
- data.tar.gz: adc66fb429d351629b872e61dcfc8ad2d11c40ce
3
+ metadata.gz: e7d32c86ed73e992891971d99e1f5fed1c3d20e9
4
+ data.tar.gz: 53173d404b9a4b86e7d0c84f6717531ab73e290c
5
5
  SHA512:
6
- metadata.gz: a21e147dcf7e37feae2c6eec67242cec814353bb4583df2b02698c9498546dc476f419574c67214c453e7173db3896c91a413c9ef503f2c130bf23cc70303af1
7
- data.tar.gz: c4f77002e8336a5a635d2d8516d9db3522fc6a596eaf95d0c7dcc758ef9de439f0d72334ce4d0d24b9f76ce9f0b926de871ea5b2cecabd0d5b9c1892532f3b67
6
+ metadata.gz: 3063377dafa07b971082c048a1795aa16a0b0e0c714f9779f599c2caced4a2486eec5fe27d5510b5df203a8748f736fa3b5cfeda23a5eebbb499ede87d76c042
7
+ data.tar.gz: 2193c293ed47692cccfb58b0221086c5fb6cef4f232e61d7a64e69c35e3195c719f3fb4dbe337369bdd283754f9096848c8190dae087fc69f8146aaaeb3decad
data/.rubocop.yml CHANGED
@@ -22,6 +22,9 @@ Metrics/MethodLength:
22
22
  Metrics/PerceivedComplexity:
23
23
  Enabled: false
24
24
 
25
+ Style/AndOr:
26
+ Enabled: false
27
+
25
28
  Style/Documentation:
26
29
  Enabled: false
27
30
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.0
2
+ - Support execution over SSH with --host option
3
+ - Remove --recipe=... option and require recipe path in 2nd command-line argument
4
+
1
5
  ## 0.0.6
2
6
  - Add `serverkit inspec` action
3
7
  - Define required ruby version with 2.0.0 or higher in gemspec
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 --recipe=recipe.yml
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 --recipe=recipe.yml
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 --recipe=recipe.yml
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 --recipe=recipe.yml
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 --recipe=recipe
101
- $ serverkit apply --recipe=recipe.json
102
- $ serverkit apply --recipe=recipe.json.erb
103
- $ serverkit apply --recipe=recipe.json.erb --variables=variables
104
- $ serverkit apply --recipe=recipe.json.erb --variables=variables.json
105
- $ serverkit apply --recipe=recipe.json.erb --variables=variables.json.erb
106
- $ serverkit apply --recipe=recipe.json.erb --variables=variables.yml
107
- $ serverkit apply --recipe=recipe.json.erb --variables=variables.yml.erb
108
- $ serverkit apply --recipe=recipe.json.erb --variables=variables/
109
- $ serverkit apply --recipe=recipe.yml
110
- $ serverkit apply --recipe=recipe.yml.erb
111
- $ serverkit apply --recipe=recipes/
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 [Hash] options
9
- def initialize(options)
10
- @options = options
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 ||= Specinfra::Backend::Exec.new
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(@options[:recipe], variables_path: @options[:variables]).load
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
@@ -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 "slop"
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
- abort_for_missing_action_name
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
- abort_for_unknown_action_name
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
- ARGV.first
39
+ @argv.first
46
40
  end
47
41
 
48
42
  def apply
49
- Actions::Apply.new(options).call
43
+ Actions::Apply.new(@argv).call
50
44
  end
51
45
 
52
46
  def check
53
- Actions::Check.new(options).call
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(options).call
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(options).call
56
+ Actions::Validate.new(@argv).call
76
57
  end
77
58
  end
78
59
  end
@@ -1,6 +1,6 @@
1
1
  module Serverkit
2
2
  module Errors
3
- class Base
3
+ class Base < StandardError
4
4
  end
5
5
  end
6
6
  end
@@ -0,0 +1,12 @@
1
+ require "serverkit/errors/base"
2
+
3
+ module Serverkit
4
+ module Errors
5
+ class MissingActionNameArgumentError < Base
6
+ # @return [String]
7
+ def to_s
8
+ abort "Missing action name argument"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require "serverkit/errors/base"
2
+
3
+ module Serverkit
4
+ module Errors
5
+ class MissingRecipePathArgumentError < Base
6
+ # @return [String]
7
+ def to_s
8
+ abort "Missing recipe path argument"
9
+ end
10
+ end
11
+ end
12
+ 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?
@@ -1,3 +1,3 @@
1
1
  module Serverkit
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
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.6
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