kondate 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +50 -27
- data/lib/kondate.rb +1 -0
- data/lib/kondate/cli.rb +3 -1
- data/lib/kondate/config.rb +10 -0
- data/lib/kondate/host_plugin/base.rb +24 -0
- data/lib/kondate/host_plugin/file.rb +15 -5
- data/lib/kondate/property_builder.rb +33 -9
- data/lib/kondate/templates/.kondate.conf +2 -0
- data/lib/kondate/templates/bootstrap.rb +1 -0
- data/lib/kondate/templates/properties/environments/.gitkeep +0 -0
- data/lib/kondate/templates/properties/nodes/.gitkeep +0 -0
- data/lib/kondate/templates/recipes/roles/.gitkeep +0 -0
- data/lib/kondate/templates/secrets/properties/environments/.gitkeep +0 -0
- data/lib/kondate/templates/secrets/properties/nodes/.gitkeep +0 -0
- data/lib/kondate/templates/secrets/properties/roles/.gitkeep +0 -0
- data/lib/kondate/templates/spec/middleware/.gitkeep +0 -0
- data/lib/kondate/templates/spec/roles/.gitkeep +0 -0
- data/lib/kondate/version.rb +1 -1
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe91929a45399f7e8a221f3fb5e213e397c08ec
|
4
|
+
data.tar.gz: 6b9b197d8d7c53862c9df96a01c15ab88ac95775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600de96b908537679071fd2aa4fa1a44c6e843834118ebb89f50b02106e021662e4f49cda5bc7c44e39ca145cf938370181a13daa246ce5d98cbb9db1a8b4c0d
|
7
|
+
data.tar.gz: c624cf7f23eda9397538da28ebf161dbcc36236745112db1395112f6f27ca88e84344f213e4a029a65c28ef8b2d9a75dc7f2001ad2f60ed1a034964fab647358
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -47,25 +47,26 @@ $ bundle exec kondate serverspec <host>
|
|
47
47
|
```
|
48
48
|
.
|
49
49
|
├── .kondate.conf # kondate configuration
|
50
|
-
├── bootstrap.rb
|
51
|
-
├── hosts.yml
|
52
|
-
├── properties
|
53
|
-
│ ├── nodes
|
54
|
-
│
|
55
|
-
│
|
56
|
-
├── secrets
|
50
|
+
├── bootstrap.rb # itamae bootstrap
|
51
|
+
├── hosts.yml # manages hostnames and its roles
|
52
|
+
├── properties # manages run_lists and attributes
|
53
|
+
│ ├── nodes # host specific properties
|
54
|
+
│ ├── roles # role properties
|
55
|
+
│ └── environments # environment properties
|
56
|
+
├── secrets # manages secrets attributes such as passwords
|
57
57
|
│ └── properties
|
58
58
|
│ ├── nodes
|
59
|
-
│
|
60
|
-
|
61
|
-
|
59
|
+
│ ├── roles
|
60
|
+
│ └── environments
|
61
|
+
├── recipes # itamae recipes
|
62
|
+
│ ├── middleware # middleware recipes
|
62
63
|
│ │ └── base
|
63
64
|
│ │ └── default.rb
|
64
|
-
│ └── roles
|
65
|
-
└── spec
|
66
|
-
├── middleware
|
65
|
+
│ └── roles # role recipes
|
66
|
+
└── spec # serverspec specs
|
67
|
+
├── middleware # middleware recipes specs
|
67
68
|
│ └── base_spec.rb
|
68
|
-
├─ roles
|
69
|
+
├─ roles # role recipes specs
|
69
70
|
└── spec_helper.rb
|
70
71
|
```
|
71
72
|
|
@@ -80,8 +81,10 @@ middleware_recipes_serverspec_dir: spec/middleware
|
|
80
81
|
roles_recipes_serverspec_dir: spec/roles
|
81
82
|
nodes_properties_dir: properties/nodes
|
82
83
|
roles_properties_dir: properties/roles
|
84
|
+
environments_properties_dir: properties/environments
|
83
85
|
secret_nodes_properties_dir: secrets/properties/nodes
|
84
86
|
secret_roles_properties_dir: secrets/properties/roles
|
87
|
+
secret_environments_properties_dir: secrets/properties/environments
|
85
88
|
plugin_dir: lib
|
86
89
|
host_plugin:
|
87
90
|
type: file
|
@@ -117,10 +120,10 @@ You can create your own host plugin. See `Host Plugin` section for more details.
|
|
117
120
|
Property files are places to write recipes to run and attributes values.
|
118
121
|
|
119
122
|
```
|
120
|
-
├── properties
|
121
|
-
│ ├── nodes
|
122
|
-
│
|
123
|
-
│
|
123
|
+
├── properties # manages run_lists and attributes
|
124
|
+
│ ├── nodes # host specific properties
|
125
|
+
│ ├── roles # role properties
|
126
|
+
│ └── environments # environment properties
|
124
127
|
```
|
125
128
|
|
126
129
|
An example looks like below:
|
@@ -141,7 +144,7 @@ attributes:
|
|
141
144
|
|
142
145
|
The attributes variables are accessible like `attrs['rbenv']['versions']` in recipes, which is equivalent and short version of `node['attributes']['rbenv']['versions']`.
|
143
146
|
|
144
|
-
You can also prepare
|
147
|
+
You can also prepare host-specific property files such as:
|
145
148
|
|
146
149
|
properties/nodes/#{host}.yml
|
147
150
|
|
@@ -151,7 +154,19 @@ attributes:
|
|
151
154
|
worker_processes: 8
|
152
155
|
```
|
153
156
|
|
154
|
-
|
157
|
+
In addition, you can also prepare environment property files such as:
|
158
|
+
|
159
|
+
properties/environments/development.yml
|
160
|
+
|
161
|
+
```
|
162
|
+
attributes:
|
163
|
+
global:
|
164
|
+
aws_region: ap-northeast-1
|
165
|
+
```
|
166
|
+
|
167
|
+
The `global` is a reserved name, the `global` is used to only store global attributes, and do not run `global` recipe.
|
168
|
+
|
169
|
+
These files are merged on kondate execution in order of `environment` + `role` + `node` (`node` > `role` > `environment` in the strong order).
|
155
170
|
|
156
171
|
### secret properties
|
157
172
|
|
@@ -161,7 +176,8 @@ Secret properties are places to write confidential attributes.
|
|
161
176
|
├── secrets # manages secrets attributes such as passwords
|
162
177
|
│ └── properties
|
163
178
|
│ ├── nodes
|
164
|
-
│
|
179
|
+
│ ├── roles
|
180
|
+
│ └── environments
|
165
181
|
```
|
166
182
|
|
167
183
|
An example looks like below:
|
@@ -250,21 +266,28 @@ require 'yaml'
|
|
250
266
|
|
251
267
|
module Kondate
|
252
268
|
module HostPlugin
|
253
|
-
|
269
|
+
# YAML format
|
270
|
+
#
|
271
|
+
# host1: [role1, role2]
|
272
|
+
# host2: [role1, role2]
|
273
|
+
class File < Base
|
254
274
|
# @param [HashWithIndifferentAccess] config
|
255
275
|
def initialize(config)
|
276
|
+
super
|
256
277
|
raise ConfigError.new('file: path is not configured') unless config.path
|
257
278
|
@path = config.path
|
258
279
|
end
|
259
280
|
|
281
|
+
# @param [String] host hostname
|
282
|
+
# @return [String] environment name
|
283
|
+
def get_environment(host)
|
284
|
+
ENV['ENVIRONMENT']
|
285
|
+
end
|
286
|
+
|
260
287
|
# @param [String] host hostname
|
261
288
|
# @return [Array] array of roles
|
262
289
|
def get_roles(host)
|
263
|
-
|
264
|
-
#
|
265
|
-
# host1: [role1, role2]
|
266
|
-
# host2: [role1, role2]
|
267
|
-
YAML.load_file(@path)[host]
|
290
|
+
YAML.load_file(@path)[host]['roles']
|
268
291
|
end
|
269
292
|
end
|
270
293
|
end
|
data/lib/kondate.rb
CHANGED
data/lib/kondate/cli.rb
CHANGED
@@ -34,6 +34,7 @@ module Kondate
|
|
34
34
|
templates_dir = File.join(Kondate::ROOT, 'lib', 'kondate', 'templates')
|
35
35
|
templates_dir_length = templates_dir.length
|
36
36
|
Find.find(templates_dir).select {|f| File.file?(f) }.each do |src|
|
37
|
+
next if File.basename(src) == '.gitkeep'
|
37
38
|
dst = File.join(target_dir, src[templates_dir_length+1 .. -1])
|
38
39
|
dst_dir = File.dirname(dst)
|
39
40
|
unless Dir.exist?(dst_dir)
|
@@ -94,8 +95,9 @@ module Kondate
|
|
94
95
|
|
95
96
|
ENV['TARGET_NODE_FILE'] = property_file
|
96
97
|
recipes = YAML.load_file(property_file)['attributes'].keys.map {|recipe|
|
98
|
+
next if recipe == 'global'
|
97
99
|
File.join(Config.middleware_recipes_serverspec_dir, recipe)
|
98
|
-
}
|
100
|
+
}.compact
|
99
101
|
recipes << File.join(Config.roles_recipes_serverspec_dir, role)
|
100
102
|
t.pattern = '{' + recipes.join(',') + '}_spec.rb'
|
101
103
|
end
|
data/lib/kondate/config.rb
CHANGED
@@ -41,8 +41,10 @@ module Kondate
|
|
41
41
|
'roles_recipes_serverspec_dir' => roles_recipes_serverspec_dir,
|
42
42
|
'nodes_properties_dir' => nodes_properties_dir,
|
43
43
|
'roles_properties_dir' => roles_properties_dir,
|
44
|
+
'environments_properties_dir' => environments_properties_dir,
|
44
45
|
'secret_nodes_properties_dir' => secret_nodes_properties_dir,
|
45
46
|
'secret_roles_properties_dir' => secret_roles_properties_dir,
|
47
|
+
'secret_environments_properties_dir' => secret_environments_properties_dir,
|
46
48
|
}
|
47
49
|
end
|
48
50
|
|
@@ -70,6 +72,10 @@ module Kondate
|
|
70
72
|
config[:roles_properties_dir] || 'properties/roles'
|
71
73
|
end
|
72
74
|
|
75
|
+
def environments_properties_dir
|
76
|
+
config[:environments_properties_dir] || 'properties/environments'
|
77
|
+
end
|
78
|
+
|
73
79
|
def secret_nodes_properties_dir
|
74
80
|
config[:secret_nodes_properties_dir] || 'secrets/properties/nodes'
|
75
81
|
end
|
@@ -78,6 +84,10 @@ module Kondate
|
|
78
84
|
config[:secret_roles_properties_dir] || 'secrets/properties/roles'
|
79
85
|
end
|
80
86
|
|
87
|
+
def secret_environments_properties_dir
|
88
|
+
config[:secret_environments_properties_dir] || 'secrets/properties/environments'
|
89
|
+
end
|
90
|
+
|
81
91
|
def plugin_dir
|
82
92
|
File.expand_path(config[:plugin_dir] || 'lib')
|
83
93
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Kondate
|
2
|
+
module HostPlugin
|
3
|
+
class Base
|
4
|
+
attr_reader :config
|
5
|
+
|
6
|
+
# @param [HashWithIndifferentAccess] config
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [String] host hostname
|
12
|
+
# @return [String] environment name
|
13
|
+
def get_environment(host)
|
14
|
+
ENV['ENVIRONMENT']
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] host hostname
|
18
|
+
# @return [Array] array of roles
|
19
|
+
def get_roles(host)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,17 +2,27 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module Kondate
|
4
4
|
module HostPlugin
|
5
|
-
|
5
|
+
# YAML format
|
6
|
+
#
|
7
|
+
# host1: [role1, role2]
|
8
|
+
# host2: [role1, role2]
|
9
|
+
class File < Base
|
10
|
+
# @param [HashWithIndifferentAccess] config
|
6
11
|
def initialize(config)
|
12
|
+
super
|
7
13
|
raise ConfigError.new('file: path is not configured') unless config.path
|
8
14
|
@path = config.path
|
9
15
|
end
|
10
16
|
|
17
|
+
# @param [String] host hostname
|
18
|
+
# @return [String] environment name
|
19
|
+
def get_environment(host)
|
20
|
+
ENV['ENVIRONMENT']
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [String] host hostname
|
24
|
+
# @return [Array] array of roles
|
11
25
|
def get_roles(host)
|
12
|
-
# YAML format
|
13
|
-
#
|
14
|
-
# host1: [role1, role2]
|
15
|
-
# host2: [role1, role2]
|
16
26
|
YAML.load_file(@path)[host]
|
17
27
|
end
|
18
28
|
end
|
@@ -9,6 +9,16 @@ module Kondate
|
|
9
9
|
@host = host
|
10
10
|
end
|
11
11
|
|
12
|
+
def environment
|
13
|
+
@environment ||=
|
14
|
+
begin
|
15
|
+
vagrant? ? '' : Config.host_plugin.get_environment(@host)
|
16
|
+
rescue => e
|
17
|
+
$stderr.puts "cannot get environment from host:#{@host}, #{e.class} #{e.message}"
|
18
|
+
''
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def roles
|
13
23
|
@roles ||=
|
14
24
|
begin
|
@@ -58,6 +68,14 @@ module Kondate
|
|
58
68
|
File.join(Config.secret_roles_properties_dir, "#{role}.yml")
|
59
69
|
end
|
60
70
|
|
71
|
+
def environment_file(environment)
|
72
|
+
File.join(Config.environments_properties_dir, "#{environment}.yml")
|
73
|
+
end
|
74
|
+
|
75
|
+
def secret_environment_file(environment)
|
76
|
+
File.join(Config.secret_environments_properties_dir, "#{environment}.yml")
|
77
|
+
end
|
78
|
+
|
61
79
|
def get_content(yaml_file)
|
62
80
|
content = File.exist?(yaml_file) ? YAML.load_file(yaml_file) : {}
|
63
81
|
content.is_a?(Hash) ? content : {}
|
@@ -69,16 +87,22 @@ module Kondate
|
|
69
87
|
#
|
70
88
|
# This file is automatically created and removed
|
71
89
|
def install(role, filter_recipes = nil)
|
72
|
-
node_property
|
73
|
-
secret_node_property
|
74
|
-
role_property
|
75
|
-
secret_role_property
|
90
|
+
node_property = get_content(node_file)
|
91
|
+
secret_node_property = get_content(secret_node_file)
|
92
|
+
role_property = get_content(role_file(role))
|
93
|
+
secret_role_property = get_content(secret_role_file(role))
|
94
|
+
environment_property = get_content(environment_file(environment))
|
95
|
+
secret_environment_property = get_content(secret_environment_file(environment))
|
76
96
|
|
77
97
|
property = HashExt.new.deep_merge!({
|
78
|
-
'
|
79
|
-
'
|
80
|
-
'
|
81
|
-
|
98
|
+
'environment' => environment,
|
99
|
+
'role' => role,
|
100
|
+
'roles' => roles,
|
101
|
+
'attributes' => {},
|
102
|
+
}).
|
103
|
+
deep_merge!(environment_property).
|
104
|
+
deep_merge!(secret_environment_property).
|
105
|
+
deep_merge!(role_property).
|
82
106
|
deep_merge!(secret_role_property).
|
83
107
|
deep_merge!(node_property).
|
84
108
|
deep_merge!(secret_node_property).to_h
|
@@ -93,7 +117,7 @@ module Kondate
|
|
93
117
|
if property['attributes'].empty?
|
94
118
|
nil
|
95
119
|
else
|
96
|
-
Tempfile.open("
|
120
|
+
Tempfile.open("kondate_") do |fp|
|
97
121
|
YAML.dump(property, fp)
|
98
122
|
end.path
|
99
123
|
end
|
@@ -5,8 +5,10 @@ middleware_recipes_serverspec_dir: spec/middleware
|
|
5
5
|
roles_recipes_serverspec_dir: spec/roles
|
6
6
|
nodes_properties_dir: properties/nodes
|
7
7
|
roles_properties_dir: properties/roles
|
8
|
+
environments_properties_dir: properties/environments
|
8
9
|
secret_nodes_properties_dir: secrets/properties/nodes
|
9
10
|
secret_roles_properties_dir: secrets/properties/roles
|
11
|
+
secret_environments_properties_dir: secrets/properties/environments
|
10
12
|
plugin_dir: lib
|
11
13
|
host_plugin:
|
12
14
|
type: file
|
@@ -3,6 +3,7 @@ require 'kondate'
|
|
3
3
|
|
4
4
|
recipes = node['attributes'].keys
|
5
5
|
recipes.each do |recipe|
|
6
|
+
next if recipe == 'global'
|
6
7
|
include_recipe(File.join(Kondate::Config.middleware_recipes_dir, recipe, "default.rb"))
|
7
8
|
end
|
8
9
|
if File.exist?(File.join(Kondate::Config.roles_recipes_dir, node[:role], "default.rb"))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/kondate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kondate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sonots
|
@@ -142,15 +142,24 @@ files:
|
|
142
142
|
- lib/kondate/config.rb
|
143
143
|
- lib/kondate/error.rb
|
144
144
|
- lib/kondate/hash_ext.rb
|
145
|
+
- lib/kondate/host_plugin/base.rb
|
145
146
|
- lib/kondate/host_plugin/file.rb
|
146
147
|
- lib/kondate/property_builder.rb
|
147
148
|
- lib/kondate/string_util.rb
|
148
149
|
- lib/kondate/templates/.kondate.conf
|
149
150
|
- lib/kondate/templates/bootstrap.rb
|
150
151
|
- lib/kondate/templates/hosts.yml
|
152
|
+
- lib/kondate/templates/properties/environments/.gitkeep
|
153
|
+
- lib/kondate/templates/properties/nodes/.gitkeep
|
151
154
|
- lib/kondate/templates/properties/roles/sample.yml
|
152
155
|
- lib/kondate/templates/recipes/middleware/base/default.rb
|
156
|
+
- lib/kondate/templates/recipes/roles/.gitkeep
|
157
|
+
- lib/kondate/templates/secrets/properties/environments/.gitkeep
|
158
|
+
- lib/kondate/templates/secrets/properties/nodes/.gitkeep
|
159
|
+
- lib/kondate/templates/secrets/properties/roles/.gitkeep
|
160
|
+
- lib/kondate/templates/spec/middleware/.gitkeep
|
153
161
|
- lib/kondate/templates/spec/middleware/base_spec.rb
|
162
|
+
- lib/kondate/templates/spec/roles/.gitkeep
|
154
163
|
- lib/kondate/templates/spec/spec_helper.rb
|
155
164
|
- lib/kondate/version.rb
|
156
165
|
homepage: https://github.com/sonots/kondate
|