serverkit 0.0.5 → 0.0.6

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: 40d5fe026687af52454bb4f3507ee76df5c24892
4
- data.tar.gz: f5ff7864e5a727ee33b68bc66624b9bc338d1a6d
3
+ metadata.gz: 656a155cfa4b8c499bafcfdbda76075bb28d1570
4
+ data.tar.gz: adc66fb429d351629b872e61dcfc8ad2d11c40ce
5
5
  SHA512:
6
- metadata.gz: 2fe05e953601daa2a7dbaa05151d4142e09f8ef588af30e9e600efe3dd179f45843dff9aae5f6c7dd69e0a09b0eb65c950b748f67d2c27ca5971c3453ca1b8cd
7
- data.tar.gz: 198e7ee4550b9aa16ff52a57056073612be2dcd00cd85cad0e0545b62881591343356312e84b2abe0def220b7311b893dd8cf3279ac3e619a5e731a5263d4df2
6
+ metadata.gz: a21e147dcf7e37feae2c6eec67242cec814353bb4583df2b02698c9498546dc476f419574c67214c453e7173db3896c91a413c9ef503f2c130bf23cc70303af1
7
+ data.tar.gz: c4f77002e8336a5a635d2d8516d9db3522fc6a596eaf95d0c7dcc758ef9de439f0d72334ce4d0d24b9f76ce9f0b926de871ea5b2cecabd0d5b9c1892532f3b67
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.6
2
+ - Add `serverkit inspec` action
3
+ - Define required ruby version with 2.0.0 or higher in gemspec
4
+ - Improve recipe validation accuracy
5
+
1
6
  ## 0.0.5
2
7
  - Add `recipe` resource type
3
8
  - Improve validation error message
data/README.md CHANGED
@@ -2,15 +2,85 @@
2
2
  Configuration management toolkit for IT automation.
3
3
 
4
4
  ## Usage
5
- This gem provides `serverkit` executable with 3 actions.
6
- `validate` action validates your recipe format.
7
- `check` action shows the difference between your recipe and the state of the target host.
8
- `apply` action executes migration programs to fill-in the gaps.
9
-
10
- ```sh
11
- serverkit validate --recipe=recipe.yml
12
- serverkit check --recipe=recipe.yml
13
- serverkit apply --recipe=recipe.yml
5
+ Write a recipe, then run `serverkit` executable to validate, inspect, check, and apply the recipe.
6
+
7
+ ### serverkit validate
8
+ Validates recipe schema, resources, and attributes.
9
+ For instance, it shows validation error if `source` attributes is missing in `file` resource.
10
+
11
+ ```
12
+ $ serverkit validate --recipe=recipe.yml
13
+ Error: source attribute is required in file resource
14
+ Error: path attribute can't be unreadable path in recipe resource
15
+ ```
16
+
17
+ ### serverkit inspect
18
+ Shows fully-expanded recipe data in JSON format.
19
+
20
+ ```
21
+ $ serverkit inspect --recipe=recipe.yml
22
+ {
23
+ "resources": [
24
+ {
25
+ "id": "install_mysql",
26
+ "type": "homebrew",
27
+ "name": "mysql"
28
+ },
29
+ {
30
+ "id": "install_redis",
31
+ "type": "homebrew",
32
+ "name": "redis"
33
+ },
34
+ {
35
+ "id": "install_licecap",
36
+ "type": "homebrew_cask",
37
+ "name": "licecap"
38
+ },
39
+ {
40
+ "id": "install_alfred",
41
+ "type": "homebrew_cask",
42
+ "name": "alfred"
43
+ },
44
+ {
45
+ "id": "clone_dotfiles",
46
+ "type": "git",
47
+ "repository": "git@github.com:r7kamura/dotfiles.git",
48
+ "path": "/Users/r7kamura/src/github.com/r7kamura/dotfiles"
49
+ },
50
+ {
51
+ "id": "symlink_zshrc",
52
+ "type": "symlink",
53
+ "source": "/Users/r7kamura/.zshrc",
54
+ "destination": "/Users/r7kamura/src/github.com/r7kamura/dotfiles/linked/.zshrc"
55
+ }
56
+ ]
57
+ }
58
+ ```
59
+
60
+ ### serverkit check
61
+ Shows the difference between your recipe and the state of the target host.
62
+
63
+ ```
64
+ $ serverkit check --recipe=recipe.yml
65
+ [OK] install_mysql
66
+ [OK] install_redis
67
+ [OK] install_licecap
68
+ [OK] install_alfred
69
+ [NG] clone_dotfiles
70
+ [NG] symlink_zshrc
71
+ ```
72
+
73
+ ### serverkit apply
74
+ Executes migration process to fill-in the gaps.
75
+
76
+ ```
77
+ $ serverkit apply --recipe=recipe.yml
78
+ [SKIP] install_mysql
79
+ [SKIP] install_redis
80
+ [SKIP] install_licecap
81
+ [SKIP] install_alfred
82
+ [DONE] clone_dotfiles
83
+ [DONE] symlink_zshrc
14
84
  ```
15
85
 
16
86
  ## Recipe
@@ -26,26 +96,26 @@ A recipe can be specified as a path to one of the following patterns:
26
96
  - Executable to output JSON
27
97
  - Directory including recipe files recursively
28
98
 
29
- ```sh
30
- serverkit apply --recipe=recipe
31
- serverkit apply --recipe=recipe.json
32
- serverkit apply --recipe=recipe.json.erb
33
- serverkit apply --recipe=recipe.json.erb --variables=variables
34
- serverkit apply --recipe=recipe.json.erb --variables=variables.json
35
- serverkit apply --recipe=recipe.json.erb --variables=variables.json.erb
36
- serverkit apply --recipe=recipe.json.erb --variables=variables.yml
37
- serverkit apply --recipe=recipe.json.erb --variables=variables.yml.erb
38
- serverkit apply --recipe=recipe.json.erb --variables=variables/
39
- serverkit apply --recipe=recipe.yml
40
- serverkit apply --recipe=recipe.yml.erb
41
- serverkit apply --recipe=recipes/
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/
42
112
  ```
43
113
 
44
114
  ### Variables
45
115
  When using ERB recipe, you can also give optional variables file
46
116
  that defines configurations in a Hash object for ERB template.
47
117
  It supports similar format variation with Recipe.
48
- In ERB template, you can refer given variables via `variables` method.
118
+ In ERB template, you can use given variables via `variables` method.
49
119
 
50
120
  ### Example
51
121
  This is an example recipe to install some packages, clone a git repository, and create a symlink.
@@ -3,7 +3,7 @@ require "active_model"
3
3
  class ReadableValidator < ActiveModel::EachValidator
4
4
  def validate_each(record, attribute, value)
5
5
  unless File.readable?(value)
6
- record.errors.add(attribute, "is unreadable")
6
+ record.errors.add(attribute, "can't be unreadable path")
7
7
  end
8
8
  end
9
9
  end
@@ -16,6 +16,10 @@ module Serverkit
16
16
 
17
17
  private
18
18
 
19
+ def abort_with_errors
20
+ abort recipe.errors.map { |error| "Error: #{error}" }.join("\n")
21
+ end
22
+
19
23
  # @return [Specinfra::Backend::Base]
20
24
  def backend
21
25
  @backend ||= Specinfra::Backend::Exec.new
@@ -0,0 +1,16 @@
1
+ require "serverkit/actions/base"
2
+ require "yaml"
3
+
4
+ module Serverkit
5
+ module Actions
6
+ class Inspect < Base
7
+ def call
8
+ if recipe.valid?
9
+ puts JSON.pretty_generate(recipe.to_hash)
10
+ else
11
+ abort_with_errors
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -7,7 +7,7 @@ module Serverkit
7
7
  if recipe.valid?
8
8
  puts "Success"
9
9
  else
10
- abort recipe.errors.map { |error| "Error: #{error}" }.join("\n")
10
+ abort_with_errors
11
11
  end
12
12
  end
13
13
  end
@@ -1,33 +1,30 @@
1
1
  require "serverkit/actions/apply"
2
2
  require "serverkit/actions/check"
3
+ require "serverkit/actions/inspect"
3
4
  require "serverkit/actions/validate"
4
5
  require "slop"
5
6
 
6
7
  module Serverkit
7
8
  class Command
8
- ACTION_NAMES = %w(
9
- apply
10
- check
11
- validate
12
- )
13
-
14
9
  # @param [Array<String>] argv
15
10
  def initialize(argv)
16
11
  @argv = argv
17
12
  end
18
13
 
19
14
  def call
20
- case
21
- when has_no_action_name?
15
+ case action_name
16
+ when nil
22
17
  abort_for_missing_action_name
23
- when has_unknown_action_name?
24
- abort_for_unknown_action_name
25
- when action_name == "apply"
18
+ when "apply"
26
19
  apply
27
- when action_name == "check"
20
+ when "check"
28
21
  check
29
- when action_name == "validate"
22
+ when "inspect"
23
+ _inspect
24
+ when "validate"
30
25
  validate
26
+ else
27
+ abort_for_unknown_action_name
31
28
  end
32
29
  rescue Slop::MissingOptionError => exception
33
30
  abort "Error: #{exception}"
@@ -56,14 +53,15 @@ module Serverkit
56
53
  Actions::Check.new(options).call
57
54
  end
58
55
 
59
- def has_no_action_name?
60
- action_name.nil?
61
- end
62
-
63
56
  def has_unknown_action_name?
64
57
  !ACTION_NAMES.include?(action_name)
65
58
  end
66
59
 
60
+ # @note #inspect is reserved ;(
61
+ def _inspect
62
+ Actions::Inspect.new(options).call
63
+ end
64
+
67
65
  # @return [Hash] Command-line options
68
66
  def options
69
67
  @options ||= Slop.parse!(@argv) do
@@ -50,6 +50,11 @@ module Serverkit
50
50
  end
51
51
  end
52
52
 
53
+ # @return [Hash] Fully-expanded recipe data
54
+ def to_hash
55
+ { "resources" => resources.map(&:attributes) }
56
+ end
57
+
53
58
  def valid?
54
59
  errors.empty?
55
60
  end
@@ -22,7 +22,7 @@ module Serverkit
22
22
 
23
23
  attr_accessor :backend
24
24
 
25
- attr_reader :recipe
25
+ attr_reader :attributes, :recipe
26
26
 
27
27
  attribute :id, required: true, type: String
28
28
 
@@ -6,7 +6,7 @@ module Serverkit
6
6
  attribute :name, required: true, type: String
7
7
 
8
8
  def apply
9
- run_command_from_identifier(:install, name)
9
+ run_command_from_identifier(:install_package, name)
10
10
  end
11
11
 
12
12
  # @return [true, false]
@@ -7,7 +7,11 @@ module Serverkit
7
7
 
8
8
  # @note Override
9
9
  def to_a
10
- loaded_recipe.resources
10
+ if valid?
11
+ loaded_recipe.resources
12
+ else
13
+ self
14
+ end
11
15
  end
12
16
 
13
17
  private
@@ -1,3 +1,3 @@
1
1
  module Serverkit
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/serverkit.gemspec CHANGED
@@ -3,17 +3,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "serverkit/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "serverkit"
7
- spec.version = Serverkit::VERSION
8
- spec.authors = ["Ryo Nakamura"]
9
- spec.email = ["r7kamura@gmail.com"]
10
- spec.summary = "Configuration management toolkit for IT automation."
11
- spec.homepage = "https://github.com/r7kamura/serverkit"
12
- spec.license = "MIT"
13
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
- spec.bindir = "bin"
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.require_paths = ["lib"]
6
+ spec.name = "serverkit"
7
+ spec.version = Serverkit::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Configuration management toolkit for IT automation."
11
+ spec.homepage = "https://github.com/r7kamura/serverkit"
12
+ spec.license = "MIT"
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = "bin"
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+ spec.required_ruby_version = ">= 2.0.0"
17
18
 
18
19
  spec.add_runtime_dependency "activemodel"
19
20
  spec.add_runtime_dependency "activesupport"
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.0.5
4
+ version: 0.0.6
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-03 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -167,6 +167,7 @@ files:
167
167
  - lib/serverkit/actions/apply.rb
168
168
  - lib/serverkit/actions/base.rb
169
169
  - lib/serverkit/actions/check.rb
170
+ - lib/serverkit/actions/inspect.rb
170
171
  - lib/serverkit/actions/validate.rb
171
172
  - lib/serverkit/command.rb
172
173
  - lib/serverkit/errors/attribute_validation_error.rb
@@ -205,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
206
  requirements:
206
207
  - - ">="
207
208
  - !ruby/object:Gem::Version
208
- version: '0'
209
+ version: 2.0.0
209
210
  required_rubygems_version: !ruby/object:Gem::Requirement
210
211
  requirements:
211
212
  - - ">="