chef-dk 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +192 -0
  3. data/LICENSE +201 -0
  4. data/README.md +198 -0
  5. data/Rakefile +18 -0
  6. data/bin/chef +25 -0
  7. data/lib/chef-dk.rb +19 -0
  8. data/lib/chef-dk/builtin_commands.rb +31 -0
  9. data/lib/chef-dk/chef_runner.rb +83 -0
  10. data/lib/chef-dk/cli.rb +135 -0
  11. data/lib/chef-dk/command/base.rb +71 -0
  12. data/lib/chef-dk/command/exec.rb +33 -0
  13. data/lib/chef-dk/command/gem.rb +47 -0
  14. data/lib/chef-dk/command/generate.rb +97 -0
  15. data/lib/chef-dk/command/generator_commands.rb +417 -0
  16. data/lib/chef-dk/command/shell_init.rb +80 -0
  17. data/lib/chef-dk/command/verify.rb +226 -0
  18. data/lib/chef-dk/commands_map.rb +115 -0
  19. data/lib/chef-dk/component_test.rb +142 -0
  20. data/lib/chef-dk/cookbook_metadata.rb +36 -0
  21. data/lib/chef-dk/cookbook_omnifetch.rb +29 -0
  22. data/lib/chef-dk/cookbook_profiler/git.rb +95 -0
  23. data/lib/chef-dk/cookbook_profiler/identifiers.rb +79 -0
  24. data/lib/chef-dk/cookbook_profiler/null_scm.rb +32 -0
  25. data/lib/chef-dk/exceptions.rb +46 -0
  26. data/lib/chef-dk/generator.rb +70 -0
  27. data/lib/chef-dk/helpers.rb +95 -0
  28. data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +46 -0
  29. data/lib/chef-dk/policyfile/community_cookbook_source.rb +84 -0
  30. data/lib/chef-dk/policyfile/cookbook_sources.rb +20 -0
  31. data/lib/chef-dk/policyfile/cookbook_spec.rb +96 -0
  32. data/lib/chef-dk/policyfile/dsl.rb +148 -0
  33. data/lib/chef-dk/policyfile/null_cookbook_source.rb +37 -0
  34. data/lib/chef-dk/policyfile_compiler.rb +217 -0
  35. data/lib/chef-dk/policyfile_lock.rb +243 -0
  36. data/lib/chef-dk/shell_out.rb +36 -0
  37. data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +3 -0
  38. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +96 -0
  39. data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +9 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +16 -0
  41. data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +8 -0
  42. data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
  43. data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +65 -0
  44. data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +12 -0
  45. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +50 -0
  46. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
  47. data/lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb +23 -0
  48. data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +9 -0
  49. data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
  50. data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
  51. data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
  52. data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
  53. data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +8 -0
  54. data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +16 -0
  55. data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +8 -0
  56. data/lib/chef-dk/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
  57. data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +0 -0
  58. data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
  59. data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
  60. data/lib/chef-dk/version.rb +20 -0
  61. data/spec/shared/setup_git_cookbooks.rb +53 -0
  62. data/spec/spec_helper.rb +32 -0
  63. data/spec/test_helpers.rb +59 -0
  64. data/spec/unit/chef_runner_spec.rb +70 -0
  65. data/spec/unit/cli_spec.rb +151 -0
  66. data/spec/unit/command/base_spec.rb +88 -0
  67. data/spec/unit/command/exec_spec.rb +123 -0
  68. data/spec/unit/command/generate_spec.rb +102 -0
  69. data/spec/unit/command/generator_commands_spec.rb +504 -0
  70. data/spec/unit/command/shell_init_spec.rb +109 -0
  71. data/spec/unit/command/verify_spec.rb +311 -0
  72. data/spec/unit/commands_map_spec.rb +57 -0
  73. data/spec/unit/component_test_spec.rb +126 -0
  74. data/spec/unit/cookbook_metadata_spec.rb +62 -0
  75. data/spec/unit/cookbook_profiler/git_spec.rb +127 -0
  76. data/spec/unit/cookbook_profiler/identifiers_spec.rb +79 -0
  77. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
  78. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
  79. data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
  80. data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
  81. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
  82. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
  83. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
  84. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
  85. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
  86. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
  87. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
  88. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
  89. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
  90. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
  91. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
  92. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
  93. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/.kitchen.yml +16 -0
  94. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
  95. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
  96. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
  97. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
  98. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
  99. data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
  100. data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
  101. data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
  102. data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +36 -0
  103. data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
  104. data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
  105. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
  106. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
  107. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
  108. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
  109. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
  110. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
  111. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
  112. data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
  113. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
  114. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
  115. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
  116. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
  117. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
  118. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
  119. data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
  120. data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
  121. data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
  122. data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
  123. data/spec/unit/fixtures/example_cookbook/README.md +4 -0
  124. data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
  125. data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
  126. data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
  127. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
  128. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
  129. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
  130. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
  131. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
  132. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
  133. data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
  134. data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +34 -0
  135. data/spec/unit/policyfile/community_cookbook_source_spec.rb +51 -0
  136. data/spec/unit/policyfile/cookbook_spec_spec.rb +200 -0
  137. data/spec/unit/policyfile/null_cookbook_source_spec.rb +35 -0
  138. data/spec/unit/policyfile_builder_spec.rb +489 -0
  139. data/spec/unit/policyfile_demands_spec.rb +484 -0
  140. data/spec/unit/policyfile_evaluation_spec.rb +284 -0
  141. data/spec/unit/shell_out_spec.rb +34 -0
  142. metadata +422 -0
@@ -0,0 +1,243 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy 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,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef-dk/cookbook_profiler/identifiers'
19
+ require 'chef-dk/cookbook_profiler/null_scm'
20
+ require 'chef-dk/cookbook_profiler/git'
21
+
22
+ module ChefDK
23
+ class PolicyfileLock
24
+
25
+ # CachedCookbook objects represent a cookbook that has been fetched from an
26
+ # upstream canonical source and stored (presumed unmodified).
27
+ class CachedCookbook
28
+
29
+ # The cookbook name (without any version or other info suffixed)
30
+ attr_reader :name
31
+
32
+ # The directory name in the cookbook cache where the cookbook is stored.
33
+ # By convention, this should be the name of the cookbook followed by a
34
+ # hyphen and then some sort of version identifier (depending on the
35
+ # cookbook source).
36
+ attr_accessor :cache_key
37
+
38
+ # A URI pointing to the canonical source of the cookbook.
39
+ attr_accessor :origin
40
+
41
+ # A string that uniquely identifies the cookbook version. If not
42
+ # explicitly set, an identifier is generated based on the cookbook's
43
+ # content.
44
+ attr_writer :identifier
45
+
46
+ # A string in "X.Y.Z" version number format that uniquely identifies the
47
+ # cookbook version. This is for compatibility with Chef Server 11.x,
48
+ # where cookbooks are stored by x.y.z version numbers.
49
+ attr_writer :dotted_decimal_identifier
50
+
51
+ # The root of the cookbook cache.
52
+ attr_reader :cache_path
53
+
54
+ def initialize(name, cache_path)
55
+ @name = name
56
+ @cache_path = cache_path
57
+ @origin = nil
58
+ @cache_key = nil
59
+ @identifier = nil
60
+ @dotted_decimal_identifier = nil
61
+ end
62
+
63
+ def cookbook_path
64
+ File.join(cache_path, cache_key)
65
+ end
66
+
67
+ def identifier
68
+ @identifier || identifiers.content_identifier
69
+ end
70
+
71
+ def dotted_decimal_identifier
72
+ @dotted_decimal_identifier || identifiers.dotted_decimal_identifier
73
+ end
74
+
75
+ def to_lock
76
+ validate!
77
+ {
78
+ "version" => identifiers.semver_version,
79
+ "identifier" => identifier,
80
+ "dotted_decimal_identifier" => dotted_decimal_identifier,
81
+ "cache_key" => cache_key,
82
+ "origin" => origin
83
+ }
84
+ end
85
+
86
+ def identifiers
87
+ @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_path)
88
+ end
89
+
90
+ def validate!
91
+ unless File.exist?(cookbook_path)
92
+ raise CachedCookbookNotFound, "Cookbook `#{name}' not found at expected cache location `#{cookbook_path}'"
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ # LocalCookbook objects represent cookbooks that are sourced from the local
99
+ # filesystem and are assumed to be under active development.
100
+ class LocalCookbook
101
+
102
+ # A relative or absolute path to the cookbook. If a relative path is
103
+ # given, it is resolved relative to #relative_paths_root
104
+ attr_accessor :source
105
+
106
+ # A string that uniquely identifies the cookbook version. If not
107
+ # explicitly set, an identifier is generated based on the cookbook's
108
+ # content.
109
+ attr_writer :identifier
110
+
111
+ # A string in "X.Y.Z" version number format that uniquely identifies the
112
+ # cookbook version. This is for compatibility with Chef Server 11.x,
113
+ # where cookbooks are stored by x.y.z version numbers.
114
+ attr_writer :dotted_decimal_identifier
115
+
116
+ # The root path from which source is expanded.
117
+ attr_accessor :relative_paths_root
118
+
119
+ def initialize(name, relative_paths_root)
120
+ @name = name
121
+ @identifier = nil
122
+ @relative_paths_root = relative_paths_root
123
+ end
124
+
125
+ def cookbook_path
126
+ File.expand_path(source, relative_paths_root)
127
+ end
128
+
129
+ def scm_profiler
130
+ if File.exist?(File.join(cookbook_path, ".git"))
131
+ CookbookProfiler::Git.new(cookbook_path)
132
+ else
133
+ CookbookProfiler::NullSCM.new(cookbook_path)
134
+ end
135
+ end
136
+
137
+ def identifier
138
+ @identifier || identifiers.content_identifier
139
+ end
140
+
141
+ def dotted_decimal_identifier
142
+ @dotted_decimal_identifier || identifiers.dotted_decimal_identifier
143
+ end
144
+
145
+ def to_lock
146
+
147
+ {
148
+ "version" => identifiers.semver_version,
149
+ "identifier" => identifier,
150
+ "dotted_decimal_identifier" => dotted_decimal_identifier,
151
+ "source" => source,
152
+ "cache_key" => nil,
153
+ "scm_info" => scm_profiler.profile_data
154
+ }
155
+ end
156
+
157
+ def identifiers
158
+ @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_path)
159
+ end
160
+
161
+ end
162
+
163
+ def self.build(options = {})
164
+ lock = new(options)
165
+ yield lock
166
+ lock
167
+ end
168
+
169
+ def self.build_from_compiler(compiler, options = {})
170
+ lock = new(options)
171
+ lock.build_from_compiler(compiler)
172
+ lock
173
+ end
174
+
175
+ attr_accessor :name
176
+ attr_accessor :run_list
177
+
178
+ attr_reader :cookbook_locks
179
+ attr_reader :cache_path
180
+ attr_reader :relative_paths_root
181
+
182
+ def initialize(options = {})
183
+ @name = nil
184
+ @run_list = []
185
+ @cookbook_locks = {}
186
+ @relative_paths_root = Dir.pwd
187
+ handle_options(options)
188
+ end
189
+
190
+ def cached_cookbook(name)
191
+ cached_cookbook = CachedCookbook.new(name, cache_path)
192
+ yield cached_cookbook
193
+ @cookbook_locks[name] = cached_cookbook
194
+ end
195
+
196
+ def local_cookbook(name)
197
+ local_cookbook = LocalCookbook.new(name, relative_paths_root)
198
+ yield local_cookbook
199
+ @cookbook_locks[name] = local_cookbook
200
+ end
201
+
202
+ def to_lock
203
+ {}.tap do |lock|
204
+ lock["name"] = name
205
+ lock["run_list"] = run_list
206
+ lock["cookbook_locks"] = cookbook_locks_for_lockfile
207
+ end
208
+ end
209
+
210
+ def cookbook_locks_for_lockfile
211
+ cookbook_locks.inject({}) do |locks_map, (name, cookbook_spec)|
212
+ locks_map[name] = cookbook_spec.to_lock
213
+ locks_map
214
+ end
215
+ end
216
+
217
+ def build_from_compiler(compiler)
218
+ @run_list = compiler.expanded_run_list
219
+
220
+ compiler.all_cookbook_specs.each do |cookbook_name, spec|
221
+ if spec.mirrors_canonical_upstream?
222
+ cached_cookbook(cookbook_name) do |cached_cb|
223
+ cached_cb.cache_key = spec.cache_key
224
+ cached_cb.origin = spec.uri
225
+ end
226
+ else
227
+ local_cookbook(cookbook_name) do |local_cb|
228
+ local_cb.source = spec.relative_path
229
+ local_cb.relative_paths_root = spec.relative_paths_root
230
+ end
231
+ end
232
+ end
233
+ self
234
+ end
235
+
236
+ private
237
+
238
+ def handle_options(options)
239
+ @cache_path = options[:cache_path]
240
+ @relative_paths_root = options[:relative_paths_root] if options.key?(:relative_paths_root)
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy 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,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'mixlib/shellout'
19
+
20
+ module ChefDK
21
+
22
+ # A subclass of Mixlib::ShellOut that conforms to the API expected by
23
+ # CookbookOmnifetch
24
+ class ShellOut < Mixlib::ShellOut
25
+ def self.shell_out(*command_args)
26
+ cmd = new(*command_args)
27
+ cmd.run_command
28
+ cmd
29
+ end
30
+
31
+ def success?
32
+ !error?
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ source "https://api.berkshelf.com"
2
+
3
+ metadata
@@ -0,0 +1,96 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+ CHANGELOG*
81
+
82
+ # Strainer #
83
+ ############
84
+ Colanderfile
85
+ Strainerfile
86
+ .colander
87
+ .strainer
88
+
89
+ # Vagrant #
90
+ ###########
91
+ .vagrant
92
+ Vagrantfile
93
+
94
+ # Travis #
95
+ ##########
96
+ .travis.yml
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'demo::default' do
4
+ let(:chef_run) { ChefSpec::Runner.new.converge("demo::default") }
5
+
6
+ it "converges successfully" do
7
+ chef_run # This should not raise an error
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ *~
4
+ *#
5
+ .#*
6
+ \#*#
7
+ .*.sw[a-z]
8
+ *.un~
9
+
10
+ # Bundler
11
+ Gemfile.lock
12
+ bin/*
13
+ .bundle/*
14
+
15
+ .kitchen/
16
+ .kitchen.local.yml
@@ -0,0 +1,8 @@
1
+ require 'chefspec'
2
+
3
+ current_dir = File.dirname(__FILE__)
4
+
5
+ RSpec.configure do |config|
6
+ # Point to the cookbooks directory
7
+ config.cookbook_path = File.join(current_dir, '../cookbooks')
8
+ end
@@ -0,0 +1,8 @@
1
+ name 'code_generator'
2
+ maintainer 'Chef Software, Inc.'
3
+ maintainer_email 'dev@getchef.com'
4
+ license 'Apache 2 License'
5
+ description 'Generates Chef code for Chef DK'
6
+ long_description 'Generates Chef code for Chef DK'
7
+ version '0.1.0'
8
+
@@ -0,0 +1,65 @@
1
+
2
+
3
+ context = ChefDK::Generator.context
4
+ app_dir = File.join(context.app_root, context.app_name)
5
+ cookbooks_dir = context.cookbook_root
6
+ cookbook_dir = File.join(cookbooks_dir, context.cookbook_name)
7
+
8
+ cookbook_dir = File.join(cookbooks_dir, context.app_name)
9
+
10
+ # app root dir
11
+ directory app_dir
12
+
13
+ # Top level files
14
+
15
+ # TK
16
+ template "#{app_dir}/.kitchen.yml" do
17
+ source 'kitchen.yml.erb'
18
+ helpers(ChefDK::Generator::TemplateHelper)
19
+ end
20
+
21
+ # README
22
+ template "#{app_dir}/README.md" do
23
+ helpers(ChefDK::Generator::TemplateHelper)
24
+ end
25
+
26
+ # Generated Cookbook:
27
+
28
+ # cookbook collection dir
29
+ directory cookbooks_dir
30
+
31
+ # cookbook collection dir
32
+ directory cookbook_dir
33
+
34
+ # metadata.rb
35
+ template "#{cookbook_dir}/metadata.rb" do
36
+ helpers(ChefDK::Generator::TemplateHelper)
37
+ end
38
+
39
+ # chefignore
40
+ cookbook_file "#{cookbook_dir}/chefignore"
41
+
42
+ # Berks
43
+ cookbook_file "#{cookbook_dir}/Berksfile"
44
+
45
+ # Recipes
46
+
47
+ directory "#{cookbook_dir}/recipes"
48
+
49
+ template "#{cookbook_dir}/recipes/default.rb" do
50
+ source "default_recipe.rb.erb"
51
+ helpers(ChefDK::Generator::TemplateHelper)
52
+ end
53
+
54
+ # git
55
+ if context.have_git
56
+
57
+ execute("initialize-git") do
58
+ command("git init .")
59
+ cwd app_dir
60
+ end
61
+
62
+ cookbook_file "#{app_dir}/.gitignore" do
63
+ source "gitignore"
64
+ end
65
+ end