chef-gen-flavors 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +23 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +242 -0
- data/Guardfile +15 -0
- data/History.md +10 -0
- data/LICENSE +15 -0
- data/Manifest.txt +46 -0
- data/README.md +311 -0
- data/Rakefile +85 -0
- data/chef-gen-flavors.gemspec +75 -0
- data/lib/chef_gen/flavor.rb +5 -0
- data/lib/chef_gen/flavor_base.rb +230 -0
- data/lib/chef_gen/flavors.rb +173 -0
- data/lib/chef_gen/snippet/attributes.rb +22 -0
- data/lib/chef_gen/snippet/chef_spec.rb +41 -0
- data/lib/chef_gen/snippet/cookbook_base.rb +64 -0
- data/lib/chef_gen/snippet/example_file.rb +23 -0
- data/lib/chef_gen/snippet/example_template.rb +25 -0
- data/lib/chef_gen/snippet/recipes.rb +22 -0
- data/lib/chef_gen/snippet/resource_provider.rb +24 -0
- data/lib/chef_gen/snippet/standard_ignore.rb +97 -0
- data/lib/chef_gen/snippet/style_rubocop.rb +14 -0
- data/lib/chef_gen/snippet/test_kitchen.rb +51 -0
- data/lib/chef_gen/snippets.rb +15 -0
- data/spec/lib/chef_gen/flavor_base_spec.rb +164 -0
- data/spec/lib/chef_gen/flavors_spec.rb +114 -0
- data/spec/lib/chef_gen/snippet/attributes_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/chef_spec_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/cookbook_base_spec.rb +37 -0
- data/spec/lib/chef_gen/snippet/example_file_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/example_template_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/recipes_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/resource_provider_spec.rb +45 -0
- data/spec/lib/chef_gen/snippet/standard_ignore_spec.rb +40 -0
- data/spec/lib/chef_gen/snippet/style_rubocop_spec.rb +36 -0
- data/spec/lib/chef_gen/snippet/test_kitchen_spec.rb +49 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/fixtures/code_generator/metadata.rb +2 -0
- data/spec/support/fixtures/code_generator/recipes/cookbook.rb +1 -0
- data/spec/support/fixtures/code_generator_2/metadata.rb +2 -0
- data/spec/support/fixtures/code_generator_2/recipes/cookbook.rb +1 -0
- data/spec/support/fixtures/lib/chef_gen/flavor/bar.rb +21 -0
- data/spec/support/fixtures/lib/chef_gen/flavor/baz.rb +6 -0
- data/spec/support/fixtures/lib/chef_gen/flavor/foo.rb +9 -0
- metadata +317 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 946c3722860ef01d69ca49847202671db1846c9b
|
4
|
+
data.tar.gz: a51977f890bb4ef7be75e79d441f0338ba078bdb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb6c97a4fe43d518c45fdc5be85fc3c857524d79ac48a09417e160a6fafcfe4bb4f35df93ad725d602776d76d636be0a9191f97e7ef87c180820a3c94ffc12b5
|
7
|
+
data.tar.gz: 223a7f1f8652f75c5fa59eb1bd37e9cc56712550e5ea989b38f4ee446d1b74ace0c3f72cdfc0866fc697cbf7722a1ab5baf3185323837036e6a520d23bdbaacf
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- '**/Gemfile'
|
4
|
+
- '**/*.gemspec'
|
5
|
+
- 'pkg/**/*'
|
6
|
+
|
7
|
+
Style/RegexpLiteral:
|
8
|
+
Exclude:
|
9
|
+
- '**/Guardfile'
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/**/*.rb'
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 15
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 150
|
20
|
+
|
21
|
+
Lint/UnusedMethodArgument:
|
22
|
+
Exclude:
|
23
|
+
- 'lib/chef_gen/snippet/*.rb'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
chef-gen-flavors (0.3.0.20150514061941)
|
5
|
+
bogo-ui (~> 0.1)
|
6
|
+
little-plugger (~> 1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.0.0)
|
12
|
+
astrolabe (1.3.0)
|
13
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
14
|
+
bogo (0.1.22)
|
15
|
+
hashie
|
16
|
+
multi_json
|
17
|
+
bogo-ui (0.1.10)
|
18
|
+
bogo
|
19
|
+
command_line_reporter
|
20
|
+
paint
|
21
|
+
builder (3.2.2)
|
22
|
+
celluloid (0.16.0)
|
23
|
+
timers (~> 4.0.0)
|
24
|
+
chef (12.3.0)
|
25
|
+
chef-zero (~> 4.1)
|
26
|
+
diff-lcs (~> 1.2, >= 1.2.4)
|
27
|
+
erubis (~> 2.7)
|
28
|
+
ffi-yajl (>= 1.2, < 3.0)
|
29
|
+
highline (~> 1.6, >= 1.6.9)
|
30
|
+
mixlib-authentication (~> 1.3)
|
31
|
+
mixlib-cli (~> 1.4)
|
32
|
+
mixlib-config (~> 2.0)
|
33
|
+
mixlib-log (~> 1.3)
|
34
|
+
mixlib-shellout (>= 2.0.0.rc.0, < 3.0)
|
35
|
+
net-ssh (~> 2.6)
|
36
|
+
net-ssh-multi (~> 1.1)
|
37
|
+
ohai (~> 8.0)
|
38
|
+
plist (~> 3.1.0)
|
39
|
+
pry (~> 0.9)
|
40
|
+
rspec-core (~> 3.2)
|
41
|
+
rspec-expectations (~> 3.2)
|
42
|
+
rspec-mocks (~> 3.2)
|
43
|
+
rspec_junit_formatter (~> 0.2.0)
|
44
|
+
serverspec (~> 2.7)
|
45
|
+
specinfra (~> 2.10)
|
46
|
+
chef-dk (0.5.1)
|
47
|
+
chef (~> 12.0, >= 12.2.1)
|
48
|
+
cookbook-omnifetch (~> 0.2)
|
49
|
+
diff-lcs (~> 1.0)
|
50
|
+
ffi-yajl (~> 1.0)
|
51
|
+
mixlib-cli (~> 1.5)
|
52
|
+
mixlib-shellout (>= 2.0.0.rc.0, < 3.0.0)
|
53
|
+
paint (~> 1.0)
|
54
|
+
solve (~> 1.2)
|
55
|
+
chef-zero (4.2.1)
|
56
|
+
ffi-yajl (>= 1.1, < 3.0)
|
57
|
+
hashie (~> 2.0)
|
58
|
+
mixlib-log (~> 1.3)
|
59
|
+
rack
|
60
|
+
uuidtools (~> 2.1)
|
61
|
+
coderay (1.1.0)
|
62
|
+
colored (1.2)
|
63
|
+
colorize (0.7.7)
|
64
|
+
command_line_reporter (3.3.5)
|
65
|
+
colored (>= 1.2)
|
66
|
+
cookbook-omnifetch (0.2.1)
|
67
|
+
minitar (~> 0.5.4)
|
68
|
+
dep-selector-libgecode (1.0.2)
|
69
|
+
dep_selector (1.0.3)
|
70
|
+
dep-selector-libgecode (~> 1.0)
|
71
|
+
ffi (~> 1.9)
|
72
|
+
diff-lcs (1.2.5)
|
73
|
+
docile (1.1.5)
|
74
|
+
erubis (2.7.0)
|
75
|
+
ffi (1.9.8)
|
76
|
+
ffi-yajl (1.4.0)
|
77
|
+
ffi (~> 1.5)
|
78
|
+
libyajl2 (~> 1.2)
|
79
|
+
formatador (0.2.5)
|
80
|
+
guard (2.12.5)
|
81
|
+
formatador (>= 0.2.4)
|
82
|
+
listen (~> 2.7)
|
83
|
+
lumberjack (~> 1.0)
|
84
|
+
nenv (~> 0.1)
|
85
|
+
notiffany (~> 0.0)
|
86
|
+
pry (>= 0.9.12)
|
87
|
+
shellany (~> 0.0)
|
88
|
+
thor (>= 0.18.1)
|
89
|
+
guard-compat (1.2.1)
|
90
|
+
guard-rake (0.0.10)
|
91
|
+
guard
|
92
|
+
rake
|
93
|
+
guard-rspec (4.5.0)
|
94
|
+
guard (~> 2.1)
|
95
|
+
guard-compat (~> 1.1)
|
96
|
+
rspec (>= 2.99.0, < 4.0)
|
97
|
+
guard-rubocop (1.2.0)
|
98
|
+
guard (~> 2.0)
|
99
|
+
rubocop (~> 0.20)
|
100
|
+
hashie (2.1.2)
|
101
|
+
highline (1.7.2)
|
102
|
+
hirb (0.7.3)
|
103
|
+
hitimes (1.2.2)
|
104
|
+
hoe (3.13.1)
|
105
|
+
rake (>= 0.8, < 11.0)
|
106
|
+
hoe-gemspec (1.0.0)
|
107
|
+
hoe (>= 2.2.0)
|
108
|
+
ipaddress (0.8.0)
|
109
|
+
json (1.8.2)
|
110
|
+
libyajl2 (1.2.0)
|
111
|
+
listen (2.10.0)
|
112
|
+
celluloid (~> 0.16.0)
|
113
|
+
rb-fsevent (>= 0.9.3)
|
114
|
+
rb-inotify (>= 0.9)
|
115
|
+
little-plugger (1.1.3)
|
116
|
+
lumberjack (1.0.9)
|
117
|
+
method_source (0.8.2)
|
118
|
+
mime-types (2.5)
|
119
|
+
minitar (0.5.4)
|
120
|
+
mixlib-authentication (1.3.0)
|
121
|
+
mixlib-log
|
122
|
+
mixlib-cli (1.5.0)
|
123
|
+
mixlib-config (2.1.0)
|
124
|
+
mixlib-log (1.6.0)
|
125
|
+
mixlib-shellout (2.0.1)
|
126
|
+
multi_json (1.11.0)
|
127
|
+
nenv (0.2.0)
|
128
|
+
net-scp (1.2.1)
|
129
|
+
net-ssh (>= 2.6.5)
|
130
|
+
net-ssh (2.9.2)
|
131
|
+
net-ssh-gateway (1.2.0)
|
132
|
+
net-ssh (>= 2.6.5)
|
133
|
+
net-ssh-multi (1.2.1)
|
134
|
+
net-ssh (>= 2.6.5)
|
135
|
+
net-ssh-gateway (>= 1.2.0)
|
136
|
+
notiffany (0.0.6)
|
137
|
+
nenv (~> 0.1)
|
138
|
+
shellany (~> 0.0)
|
139
|
+
ohai (8.3.0)
|
140
|
+
ffi (~> 1.9)
|
141
|
+
ffi-yajl (>= 1.1, < 3.0)
|
142
|
+
ipaddress
|
143
|
+
mime-types (~> 2.0)
|
144
|
+
mixlib-cli
|
145
|
+
mixlib-config (~> 2.0)
|
146
|
+
mixlib-log
|
147
|
+
mixlib-shellout (~> 2.0)
|
148
|
+
rake (~> 10.1)
|
149
|
+
systemu (~> 2.6.4)
|
150
|
+
wmi-lite (~> 1.0)
|
151
|
+
paint (1.0.0)
|
152
|
+
parser (2.2.2.2)
|
153
|
+
ast (>= 1.1, < 3.0)
|
154
|
+
plist (3.1.0)
|
155
|
+
powerpack (0.1.1)
|
156
|
+
pry (0.10.1)
|
157
|
+
coderay (~> 1.1.0)
|
158
|
+
method_source (~> 0.8.1)
|
159
|
+
slop (~> 3.4)
|
160
|
+
rack (1.6.1)
|
161
|
+
rainbow (2.0.0)
|
162
|
+
rake (10.4.2)
|
163
|
+
rb-fsevent (0.9.4)
|
164
|
+
rb-inotify (0.9.5)
|
165
|
+
ffi (>= 0.5.0)
|
166
|
+
rdoc (4.2.0)
|
167
|
+
json (~> 1.4)
|
168
|
+
rspec (3.2.0)
|
169
|
+
rspec-core (~> 3.2.0)
|
170
|
+
rspec-expectations (~> 3.2.0)
|
171
|
+
rspec-mocks (~> 3.2.0)
|
172
|
+
rspec-core (3.2.3)
|
173
|
+
rspec-support (~> 3.2.0)
|
174
|
+
rspec-expectations (3.2.1)
|
175
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
176
|
+
rspec-support (~> 3.2.0)
|
177
|
+
rspec-its (1.2.0)
|
178
|
+
rspec-core (>= 3.0.0)
|
179
|
+
rspec-expectations (>= 3.0.0)
|
180
|
+
rspec-mocks (3.2.1)
|
181
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
182
|
+
rspec-support (~> 3.2.0)
|
183
|
+
rspec-support (3.2.2)
|
184
|
+
rspec_junit_formatter (0.2.2)
|
185
|
+
builder (< 4)
|
186
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
187
|
+
rubocop (0.31.0)
|
188
|
+
astrolabe (~> 1.3)
|
189
|
+
parser (>= 2.2.2.1, < 3.0)
|
190
|
+
powerpack (~> 0.1)
|
191
|
+
rainbow (>= 1.99.1, < 3.0)
|
192
|
+
ruby-progressbar (~> 1.4)
|
193
|
+
ruby-progressbar (1.7.5)
|
194
|
+
semverse (1.2.1)
|
195
|
+
serverspec (2.15.0)
|
196
|
+
multi_json
|
197
|
+
rspec (~> 3.0)
|
198
|
+
rspec-its
|
199
|
+
specinfra (~> 2.31)
|
200
|
+
shellany (0.0.1)
|
201
|
+
simplecov (0.10.0)
|
202
|
+
docile (~> 1.1.0)
|
203
|
+
json (~> 1.8)
|
204
|
+
simplecov-html (~> 0.10.0)
|
205
|
+
simplecov-console (0.2.0)
|
206
|
+
colorize
|
207
|
+
hirb
|
208
|
+
simplecov
|
209
|
+
simplecov-html (0.10.0)
|
210
|
+
slop (3.6.0)
|
211
|
+
solve (1.2.1)
|
212
|
+
dep_selector (~> 1.0)
|
213
|
+
semverse (~> 1.1)
|
214
|
+
specinfra (2.31.0)
|
215
|
+
net-scp
|
216
|
+
net-ssh
|
217
|
+
systemu (2.6.5)
|
218
|
+
thor (0.19.1)
|
219
|
+
timers (4.0.1)
|
220
|
+
hitimes
|
221
|
+
uuidtools (2.1.5)
|
222
|
+
wmi-lite (1.0.0)
|
223
|
+
yard (0.8.7.6)
|
224
|
+
|
225
|
+
PLATFORMS
|
226
|
+
ruby
|
227
|
+
|
228
|
+
DEPENDENCIES
|
229
|
+
chef-dk (~> 0.5)
|
230
|
+
chef-gen-flavors!
|
231
|
+
guard (~> 2.12)
|
232
|
+
guard-rake (~> 0.0)
|
233
|
+
guard-rspec (~> 4.2)
|
234
|
+
guard-rubocop (~> 1.2)
|
235
|
+
hoe (~> 3.13)
|
236
|
+
hoe-gemspec (~> 1.0)
|
237
|
+
rake (~> 10.3)
|
238
|
+
rdoc (~> 4.0)
|
239
|
+
rspec (~> 3.1)
|
240
|
+
simplecov (~> 0.9)
|
241
|
+
simplecov-console (~> 0.2)
|
242
|
+
yard (~> 0.8)
|
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# prevent dropping into pry when nothing is happening
|
2
|
+
interactor :off
|
3
|
+
|
4
|
+
guard :rubocop, all_on_start: true, cli: ['-D'] do
|
5
|
+
watch(%r{.+\.rb$})
|
6
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
7
|
+
watch('Gemfile')
|
8
|
+
watch('Rakefile')
|
9
|
+
end
|
10
|
+
|
11
|
+
guard :rspec, all_on_start: true, cmd: 'bundle exec rspec' do
|
12
|
+
watch(%r{^spec/(.+)_spec\.rb$})
|
13
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
14
|
+
watch(%r{^spec/spec_helper.*\.rb$}) { 'spec' }
|
15
|
+
end
|
data/History.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog for chef-gen-template
|
2
|
+
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
* renamed from ChefDK::Template::Plugin to ChefGen::Flavors at Chef's request so as to not pollute the ChefDK namespace
|
6
|
+
* 0.2.0 exists only with the old name as a transitional to remind people that the name has changed
|
7
|
+
|
8
|
+
## 0.1.0
|
9
|
+
|
10
|
+
* initial version
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# THE APACHE LICENSE, v2
|
2
|
+
|
3
|
+
Copyright 2015 Nordstrom, Inc.
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
6
|
+
use this file except in compliance with the License. You may obtain a copy
|
7
|
+
of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
13
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
14
|
+
License for the specific language governing permissions and limitations
|
15
|
+
under the License.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
.rspec
|
2
|
+
.rubocop.yml
|
3
|
+
.travis.yml
|
4
|
+
Gemfile
|
5
|
+
Gemfile.lock
|
6
|
+
Guardfile
|
7
|
+
History.md
|
8
|
+
LICENSE
|
9
|
+
Manifest.txt
|
10
|
+
README.md
|
11
|
+
Rakefile
|
12
|
+
chef-gen-flavors.gemspec
|
13
|
+
lib/chef_gen/flavor.rb
|
14
|
+
lib/chef_gen/flavor_base.rb
|
15
|
+
lib/chef_gen/flavors.rb
|
16
|
+
lib/chef_gen/snippet/attributes.rb
|
17
|
+
lib/chef_gen/snippet/chef_spec.rb
|
18
|
+
lib/chef_gen/snippet/cookbook_base.rb
|
19
|
+
lib/chef_gen/snippet/example_file.rb
|
20
|
+
lib/chef_gen/snippet/example_template.rb
|
21
|
+
lib/chef_gen/snippet/recipes.rb
|
22
|
+
lib/chef_gen/snippet/resource_provider.rb
|
23
|
+
lib/chef_gen/snippet/standard_ignore.rb
|
24
|
+
lib/chef_gen/snippet/style_rubocop.rb
|
25
|
+
lib/chef_gen/snippet/test_kitchen.rb
|
26
|
+
lib/chef_gen/snippets.rb
|
27
|
+
spec/lib/chef_gen/flavor_base_spec.rb
|
28
|
+
spec/lib/chef_gen/flavors_spec.rb
|
29
|
+
spec/lib/chef_gen/snippet/attributes_spec.rb
|
30
|
+
spec/lib/chef_gen/snippet/chef_spec_spec.rb
|
31
|
+
spec/lib/chef_gen/snippet/cookbook_base_spec.rb
|
32
|
+
spec/lib/chef_gen/snippet/example_file_spec.rb
|
33
|
+
spec/lib/chef_gen/snippet/example_template_spec.rb
|
34
|
+
spec/lib/chef_gen/snippet/recipes_spec.rb
|
35
|
+
spec/lib/chef_gen/snippet/resource_provider_spec.rb
|
36
|
+
spec/lib/chef_gen/snippet/standard_ignore_spec.rb
|
37
|
+
spec/lib/chef_gen/snippet/style_rubocop_spec.rb
|
38
|
+
spec/lib/chef_gen/snippet/test_kitchen_spec.rb
|
39
|
+
spec/spec_helper.rb
|
40
|
+
spec/support/fixtures/code_generator/metadata.rb
|
41
|
+
spec/support/fixtures/code_generator/recipes/cookbook.rb
|
42
|
+
spec/support/fixtures/code_generator_2/metadata.rb
|
43
|
+
spec/support/fixtures/code_generator_2/recipes/cookbook.rb
|
44
|
+
spec/support/fixtures/lib/chef_gen/flavor/bar.rb
|
45
|
+
spec/support/fixtures/lib/chef_gen/flavor/baz.rb
|
46
|
+
spec/support/fixtures/lib/chef_gen/flavor/foo.rb
|
data/README.md
ADDED
@@ -0,0 +1,311 @@
|
|
1
|
+
# chef-gen-flavors
|
2
|
+
|
3
|
+
* home :: https://github.com/Nordstrom/chef-gen-flavors
|
4
|
+
* license :: [Apache2](http://www.apache.org/licenses/LICENSE-2.0)
|
5
|
+
* gem version :: [![Gem Version](https://badge.fury.io/rb/chef-gen-flavors.png)](http://badge.fury.io/rb/chef-gen-flavors)
|
6
|
+
* build status :: [![Build Status](https://travis-ci.org/Nordstrom/chef-gen-flavors.png?branch=master)](https://travis-ci.org/Nordstrom/chef-gen-flavors)
|
7
|
+
* code climate :: [![Code Climate](https://codeclimate.com/github/Nordstrom/chef-gen-flavors/badges/gpa.svg)](https://codeclimate.com/github/Nordstrom/chef-gen-flavors)
|
8
|
+
* docs :: [![Inline docs](http://inch-ci.org/github/nordstrom/chef-gen-flavors.svg?branch=master)](http://inch-ci.org/github/nordstrom/chef-gen-flavors)
|
9
|
+
|
10
|
+
## DESCRIPTION
|
11
|
+
|
12
|
+
chef-gen-flavors is a framework for creating custom templates for the
|
13
|
+
'chef generate' command provided by ChefDK.
|
14
|
+
|
15
|
+
This gem simply provides a framework; templates are provided by separate
|
16
|
+
gems, which you can host privately for use within your organization or
|
17
|
+
publicly for the Chef community to use.
|
18
|
+
|
19
|
+
At present this is focused primarily on providing templates for generation of
|
20
|
+
cookbooks, as this is where most organization-specific customization takes place.
|
21
|
+
Support for the other artifacts that ChefDK can generate may work, but is not
|
22
|
+
the focus of early releases.
|
23
|
+
|
24
|
+
## INSTALLATION
|
25
|
+
|
26
|
+
chef gem install chef-gen-flavors
|
27
|
+
|
28
|
+
You will also need to install at least one plugin, which may be distributed
|
29
|
+
via Rubygems (in which case you install using `chef gem`) or as source, in
|
30
|
+
which case you should refer to the installation documentation that comes with
|
31
|
+
the plugin.
|
32
|
+
|
33
|
+
## PREREQUISITES
|
34
|
+
|
35
|
+
This gem requires that you have [ChefDK](https://downloads.chef.io/chef-dk/)
|
36
|
+
(at least version 0.3.6) installed. chef-dk is not a dependency of this gem
|
37
|
+
because chef-dk should always be installed using the omnibus packages
|
38
|
+
provided by Chef, not as a gem.
|
39
|
+
|
40
|
+
## CONFIGURATION
|
41
|
+
|
42
|
+
In your `knife.rb` file, add this snippet:
|
43
|
+
|
44
|
+
unless chefdk.nil?
|
45
|
+
require 'chef_gen/template'
|
46
|
+
chefdk.generator_cookbook = ChefGen::Flavors.path
|
47
|
+
end
|
48
|
+
|
49
|
+
When you run `chef generate`, all available plugins will be loaded. If more
|
50
|
+
than one plugin is found, you will be prompted as to which you want to use:
|
51
|
+
|
52
|
+
$ chef generate cookbook my_app
|
53
|
+
|
54
|
+
If you set the environment variable `CHEFGEN_TEMPLATE` to the name of a
|
55
|
+
plugin, it will be chosen instead of presenting a prompt:
|
56
|
+
|
57
|
+
$ CHEFGEN_TEMPLATE=mytemplate chef generate cookbook my_app
|
58
|
+
|
59
|
+
## USING THE BUILT-IN CHEFDK TEMPLATE
|
60
|
+
|
61
|
+
By default, this gem does not offer the built-in ChefDK template as an
|
62
|
+
option. By setting the environment variable CHEFDK_FLAVOR, the
|
63
|
+
option `builtin` will be offered.
|
64
|
+
|
65
|
+
## TERMINOLOGY
|
66
|
+
|
67
|
+
(because everything in the Chef ecosystem has to have foodie names)
|
68
|
+
|
69
|
+
* Flavor - a type of template. Provided by a plugin in the namespace `ChefGen::Flavor::`. Flavors can be distributed as ruby gems inside or outside of your organization.
|
70
|
+
* Snippet - a small piece of a code_generator cookbook that flavors can compose together to avoid repeating themselves. Nominally provided by a module in the namespace `ChefGen::Snippet::`, but can be defined in any module. chef-gen-flavors comes with several common snippets, but you can create your own and package them as standalone gems or as part of a flavor gem
|
71
|
+
|
72
|
+
## FLAVORS
|
73
|
+
|
74
|
+
This gem uses [little-plugger](https://rubygems.org/gems/little-plugger) to
|
75
|
+
make adding template flavors easy. Each flavor is defined by a plugin named
|
76
|
+
using [little-pluggers's
|
77
|
+
rules](https://github.com/TwP/little-plugger/blob/little-plugger-1.1.2/lib/little-plugger.rb#L13-25).
|
78
|
+
|
79
|
+
The plugin must define a class inside the naming hierarchy
|
80
|
+
`ChefGen::Flavor::`. The class name should be the filename converted to
|
81
|
+
CamelCase (e.g. `foo_bar.rb` = `FooBar`)
|
82
|
+
|
83
|
+
The name of the module must not be in all caps, as little-plugger ignores
|
84
|
+
these (assuming that they are constants).
|
85
|
+
|
86
|
+
Plugins must also define a class method named `description`, which is used
|
87
|
+
both to find the path to the file that defines the plugin and in the prompt
|
88
|
+
displayed when more than one plugin is available.
|
89
|
+
|
90
|
+
You do not have to `require` your plugin; little-plugger searches all
|
91
|
+
installed gems for files matching the globspec.
|
92
|
+
|
93
|
+
## EXAMPLE FLAVOR STRUCTURE
|
94
|
+
|
95
|
+
This example defines a flavor named `Example`. It can only generate
|
96
|
+
cookbooks, as its code_generator cookbook contains no other recipes.
|
97
|
+
|
98
|
+
A functional copy of this plugin is available on rubygems as
|
99
|
+
`chef-gen-flavor-example`.
|
100
|
+
|
101
|
+
The directory structure of a plugin looks like this:
|
102
|
+
|
103
|
+
chef-gen-flavor-example
|
104
|
+
├── code_generator
|
105
|
+
│ ├── files
|
106
|
+
│ │ └── default
|
107
|
+
│ ├── metadata.rb
|
108
|
+
│ ├── recipes
|
109
|
+
│ │ └── cookbook.rb
|
110
|
+
│ └── templates
|
111
|
+
│ └── default
|
112
|
+
└── lib
|
113
|
+
└── chef_gen
|
114
|
+
└── flavor
|
115
|
+
└── example.rb
|
116
|
+
|
117
|
+
## ALTERNATE code_generator PATHS
|
118
|
+
|
119
|
+
By default, the code_generator cookbook is assumed to live in a directory
|
120
|
+
named `code_generator` four levels higher than the path of the file
|
121
|
+
definining the plugin.
|
122
|
+
|
123
|
+
To specify that the code_generator cookbook lives elsewhere, define a class
|
124
|
+
method named `code_generator_path` which takes one argument (the path to the
|
125
|
+
plugin class) and returns the path to the code_generator cookbook. If the
|
126
|
+
`Example` plugin wanted to place the code_generator cookbook in a directory
|
127
|
+
named `template` instead of `code_generator`, it would define an instance
|
128
|
+
method like this:
|
129
|
+
|
130
|
+
module ChefGen
|
131
|
+
module Flavor
|
132
|
+
class Example
|
133
|
+
class << self
|
134
|
+
def description
|
135
|
+
'example cookbook template'
|
136
|
+
end
|
137
|
+
|
138
|
+
def code_generator_path(classfile)
|
139
|
+
File.expand_path(
|
140
|
+
File.join(
|
141
|
+
classfile,
|
142
|
+
'..', '..', '..', '..',
|
143
|
+
'template'
|
144
|
+
)
|
145
|
+
)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
For compatibility with all platforms supported by ChefDK, plugins should use
|
153
|
+
the methods in the `File` class to construct relative paths rather than
|
154
|
+
assuming what the path separator should be.
|
155
|
+
|
156
|
+
## FLAVOR BASE CLASS
|
157
|
+
|
158
|
+
Inside of your plugin's code_generator cookbook, you can do anything that
|
159
|
+
chef-solo can do. If you aren't familiar with the mechanics of the default
|
160
|
+
generators that comes with chef-dk, you should study [those
|
161
|
+
recipes](https://github.com/chef/chef-dk/tree/0.5.1/lib/chef-dk/skeletons/code_generator)
|
162
|
+
first before attempting to create your own.
|
163
|
+
|
164
|
+
To make the job of authoring a custom template easier, this gem comes with a
|
165
|
+
base class that plugins can inherit from. This provides some useful
|
166
|
+
features:
|
167
|
+
|
168
|
+
* helpers to create directories and render files and templates using simple name translation
|
169
|
+
* the ability to create and use snippets that set up commonly used functionality (i.e. ChefSpec or Test Kitchen)
|
170
|
+
* the ability to prevent files from being overwritten when a template is being applied overtop an existing cookbook
|
171
|
+
|
172
|
+
To use the base class, make it a dependency of your gem and inherit from it:
|
173
|
+
|
174
|
+
require 'chef_gen/flavor_base'
|
175
|
+
|
176
|
+
module ChefGen
|
177
|
+
module Flavor
|
178
|
+
class Amazing < FlavorBase
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Then in one of your generator recipes like `recipes/cookbook.rb`, create
|
184
|
+
an instance of your plugin, passing the recipe into which resources will
|
185
|
+
be injected:
|
186
|
+
|
187
|
+
template = ChefGen::Flavor::Amazing.new(self)
|
188
|
+
|
189
|
+
The plugin has several helper methods you can use:
|
190
|
+
|
191
|
+
* `target_path` returns the full path to the target directory
|
192
|
+
* `directories` is a `Array` of directories to create
|
193
|
+
* `files` is an `Array` of files to create
|
194
|
+
* `files_if_missing` is an `Array` of files to create which should not be overwritten if they exist
|
195
|
+
* `templates` is an `Array` of templates to render
|
196
|
+
* `templates_if_missing` is an `Array` of templates to render which should not be overwritten if they exist
|
197
|
+
* `chefignore_files` is an `Array` of glob patterns to write to the `chefignore` file. If this array is empty, the file is not created automatically (but templates can take this on themselves)
|
198
|
+
* `gitignore_files` is an `Array` of glob patterns to write to the `.gitignore` file. If this array is empty, the file is not created automatically (but templates can take this on themselves)
|
199
|
+
* `fail_on_clobber` is a boolean accessor which causes generation to fail if any files in the `files` or `templates` arrays already exist. Defaults to true, but can be set to false by adding `-a clobber` to the `chef generate` command line
|
200
|
+
* `report_actions` is a boolean accessor which causes the generator to report all of the actions it took
|
201
|
+
* `next_steps` is a message to be displayed to the user as the last thing the generator does
|
202
|
+
|
203
|
+
The distinction between files that are overwritten and those that are
|
204
|
+
created only if they do not exist allows for updating a cookbook to an
|
205
|
+
organization-wide policy while still allowing for per-cookbook
|
206
|
+
customization.
|
207
|
+
|
208
|
+
For example, if your cookbook template has a standard Rakefile and you wish
|
209
|
+
to add a target to it, you can do so if Rakefile is in the `files` array.
|
210
|
+
When the generator is used on top of an existing cookbook, the Rakefile will
|
211
|
+
be rewritten. Custom rake tasks can be placed in `.rake` files in the
|
212
|
+
directory `lib/tasks`, which will not be overwritten.
|
213
|
+
|
214
|
+
Once the template object has been set up to your satisfaction, call the
|
215
|
+
`#generate` method, which creates the Chef resources to generate your
|
216
|
+
target.
|
217
|
+
|
218
|
+
The list of files and templates take the path to the rendered file (e.g.
|
219
|
+
`spec/spec_helper.rb`). The source for the file or template will be
|
220
|
+
transformed by replacing foreward slashes and dots with underscores.
|
221
|
+
Additionally, templates have `.erb` appended to the source.
|
222
|
+
|
223
|
+
This code:
|
224
|
+
|
225
|
+
template = ChefGen::Flavor::Amazing.new
|
226
|
+
template.files << 'spec/spec_helper.rb'
|
227
|
+
template.templates << '.rubocop.yml'
|
228
|
+
template.generate
|
229
|
+
|
230
|
+
is equivalent to manually creating these resources:
|
231
|
+
|
232
|
+
file "#{cookbook_dir}/spec/spec_helper.rb" do
|
233
|
+
source 'spec_spec_helper_rb'
|
234
|
+
end
|
235
|
+
|
236
|
+
template "#{cookbook_dir}/.rubocop.yml" do
|
237
|
+
source '_rubocop_yml.erb'
|
238
|
+
end
|
239
|
+
|
240
|
+
### TEMPLATE SNIPPETS
|
241
|
+
|
242
|
+
Many templates will use common patterns, such as providing a README.md and
|
243
|
+
CHANGELOG.md, providing the files necessary to create a ChefSpec unit
|
244
|
+
testing suite, or the files necessary to create a Test Kitchen integration
|
245
|
+
testing suite.
|
246
|
+
|
247
|
+
Rather than have every template author create these, this gem ships with a
|
248
|
+
number of snippets, which can be included in your plugin class like so:
|
249
|
+
|
250
|
+
require 'chef_gen/flavor'
|
251
|
+
require 'chef_gen/snippets'
|
252
|
+
|
253
|
+
module ChefGen
|
254
|
+
module Flavor
|
255
|
+
class Amazing < FlavorBase
|
256
|
+
include ChefGen::Snippet::ChefSpec
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
The snippets that ship with this gem are:
|
262
|
+
|
263
|
+
* `CookbookBase` - sets up the basic files any cookbook needs (README, CHANGELOG, etc.)
|
264
|
+
* `StyleRubocop` - sets up the files for style checking with Rubocop
|
265
|
+
* `ChefSpec` - sets up the files for basic ChefSpec unit testing
|
266
|
+
* `TestKitchen` - sets up the files for basic Test Kitchen integration testing
|
267
|
+
* `Recipes` - creates recipes/default.rb
|
268
|
+
* `Attributes` - creates attributes/default.rb
|
269
|
+
* `ExampleFile` - creates files/default/example.conf
|
270
|
+
* `ExampleTemplate` - creates templates/default/example.conf.erb
|
271
|
+
* `ResourceProvider` - sets up a sample LWRP resource and provider
|
272
|
+
|
273
|
+
You can also create your own snippet. A snippet is simply a module that
|
274
|
+
provides some number of public methods prefixed with `snippet\_`. Any such
|
275
|
+
methods will be called, passing the recipe object as the only parameter when
|
276
|
+
`#generate` is called. For example, a simplified ChefSpec snippet might look
|
277
|
+
like this:
|
278
|
+
|
279
|
+
module ChefGen
|
280
|
+
module Snippet
|
281
|
+
module ChefSpec
|
282
|
+
def snippet_chefspec(recipe)
|
283
|
+
@directories << 'spec'
|
284
|
+
@directories << File.join('spec', '/recipes')
|
285
|
+
@files << '.rspec'
|
286
|
+
@files << File.join('spec', 'spec_helper.rb')
|
287
|
+
@files << File.join('spec', 'recipes', 'default_spec.rb')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
## AUTHOR
|
294
|
+
|
295
|
+
James FitzGibbon - james.i.fitzgibbon@nordstrom.com - Nordstrom, Inc.
|
296
|
+
|
297
|
+
## LICENSE
|
298
|
+
|
299
|
+
Copyright 2015 Nordstrom, Inc.
|
300
|
+
|
301
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
302
|
+
use this file except in compliance with the License. You may obtain a copy
|
303
|
+
of the License at
|
304
|
+
|
305
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
306
|
+
|
307
|
+
Unless required by applicable law or agreed to in writing, software
|
308
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
309
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
310
|
+
License for the specific language governing permissions and limitations
|
311
|
+
under the License.
|