chef-gen-flavor-base 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.md +6 -0
- data/LICENSE +17 -0
- data/Manifest.txt +50 -0
- data/README.md +818 -0
- data/chef-gen-flavor-base.gemspec +84 -0
- data/lib/chef_gen/flavor_base.rb +185 -0
- data/lib/chef_gen/flavor_base/copy_helpers.rb +45 -0
- data/lib/chef_gen/flavor_base/resource_helpers.rb +110 -0
- data/lib/chef_gen/snippet/actions_taken.rb +82 -0
- data/lib/chef_gen/snippet/attributes.rb +35 -0
- data/lib/chef_gen/snippet/chef_spec.rb +121 -0
- data/lib/chef_gen/snippet/cookbook_base.rb +135 -0
- data/lib/chef_gen/snippet/debugging.rb +26 -0
- data/lib/chef_gen/snippet/example_file.rb +36 -0
- data/lib/chef_gen/snippet/example_template.rb +36 -0
- data/lib/chef_gen/snippet/git_init.rb +36 -0
- data/lib/chef_gen/snippet/guard.rb +70 -0
- data/lib/chef_gen/snippet/next_steps.rb +44 -0
- data/lib/chef_gen/snippet/no_clobber.rb +62 -0
- data/lib/chef_gen/snippet/recipes.rb +35 -0
- data/lib/chef_gen/snippet/resource_provider.rb +37 -0
- data/lib/chef_gen/snippet/standard_ignore.rb +85 -0
- data/lib/chef_gen/snippet/style_foodcritic.rb +73 -0
- data/lib/chef_gen/snippet/style_rubocop.rb +115 -0
- data/lib/chef_gen/snippet/style_tailor.rb +64 -0
- data/lib/chef_gen/snippet/test_kitchen.rb +129 -0
- data/lib/chef_gen/snippet_base.rb +46 -0
- data/lib/chef_gen/snippets.rb +24 -0
- data/shared/snippet/attributes/templates/default/attributes_default_rb.erb +8 -0
- data/shared/snippet/chef_spec/templates/default/_rspec.erb +2 -0
- data/shared/snippet/chef_spec/templates/default/spec_chef_runner_context_rb.erb +36 -0
- data/shared/snippet/chef_spec/templates/default/spec_recipes_default_spec_rb.erb +7 -0
- data/shared/snippet/chef_spec/templates/default/spec_spec_helper_rb.erb +95 -0
- data/shared/snippet/cookbook_base/templates/default/Berksfile.erb +12 -0
- data/shared/snippet/cookbook_base/templates/default/CHANGELOG_md.erb +5 -0
- data/shared/snippet/cookbook_base/templates/default/Gemfile.erb +18 -0
- data/shared/snippet/cookbook_base/templates/default/README_md.erb +92 -0
- data/shared/snippet/cookbook_base/templates/default/Rakefile.erb +20 -0
- data/shared/snippet/cookbook_base/templates/default/metadata_rb.erb +13 -0
- data/shared/snippet/example_file/files/default/files_default_example_conf +34 -0
- data/shared/snippet/example_template/files/default/templates_default_example_conf_erb +22 -0
- data/shared/snippet/guard/templates/default/Guardfile.erb +16 -0
- data/shared/snippet/recipes/templates/default/recipes_default_rb.erb +9 -0
- data/shared/snippet/resource_provider/templates/default/providers_default_rb.erb +20 -0
- data/shared/snippet/resource_provider/templates/default/resources_default_rb.erb +9 -0
- data/shared/snippet/style_rubocop/templates/default/_rubocop_yml.erb +31 -0
- data/shared/snippet/test_kitchen/libraries/kitchen_helper.rb +13 -0
- data/shared/snippet/test_kitchen/templates/default/_kitchen_yml.erb +30 -0
- data/shared/snippet/test_kitchen/templates/default/test_integration_default_serverspec_recipes_default_spec_rb.erb +16 -0
- data/shared/snippet/test_kitchen/templates/default/test_integration_default_serverspec_spec_helper_rb.erb +7 -0
- metadata +372 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# provides an accessor with a block of text to be displayed at
|
6
|
+
# the end of the generate phase; normally used to give the user
|
7
|
+
# some information about how to proceed. When used in conjunction
|
8
|
+
# with the ActionsTaken snippet, care should be taken to put this
|
9
|
+
# snippet after it in the list so that the next steps is the last
|
10
|
+
# thing that the user sees
|
11
|
+
class NextSteps < ChefGen::SnippetBase
|
12
|
+
# the name of the snippet
|
13
|
+
NAME = 'next_steps'
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# @!attribute [rw] next_steps
|
18
|
+
# @return [String] the actions taken by the flavor
|
19
|
+
|
20
|
+
# initializes the snippet in generate mode
|
21
|
+
# @return [void]
|
22
|
+
# @api private
|
23
|
+
def initialize_generate
|
24
|
+
super
|
25
|
+
@flavor.class.send(:attr_accessor, :next_steps)
|
26
|
+
hook_display_next_steps
|
27
|
+
end
|
28
|
+
|
29
|
+
# adds an after hook to declare resources to report on actions taken
|
30
|
+
# @return [void]
|
31
|
+
# @api private
|
32
|
+
def hook_display_next_steps
|
33
|
+
@flavor.class.after_add_resources do
|
34
|
+
steps = next_steps
|
35
|
+
@recipe.send(:ruby_block, 'display_next_steps') do
|
36
|
+
# :nocov:
|
37
|
+
block { $stdout.puts steps }
|
38
|
+
# :nocov:
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# disallows overwrite of @files and @templates unless -a clobber
|
6
|
+
# is passed on the command line
|
7
|
+
class NoClobber < ChefGen::SnippetBase
|
8
|
+
# the name of the snippet
|
9
|
+
NAME = 'no_clobber'
|
10
|
+
|
11
|
+
# @!attribute [rw] fail_on_clobber
|
12
|
+
# @return [Boolean] whether to fail on attempted clobber
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# initializes the snippet in generate mode
|
17
|
+
# @return [void]
|
18
|
+
# @api private
|
19
|
+
def initialize_generate
|
20
|
+
super
|
21
|
+
@flavor.class.send(:attr_accessor, :fail_on_clobber)
|
22
|
+
|
23
|
+
# default is false if '-a clobber' was passed, true otherwise
|
24
|
+
c = ChefDK::Generator.context
|
25
|
+
@flavor.fail_on_clobber = !c.respond_to?(:clobber)
|
26
|
+
|
27
|
+
hook_add_files
|
28
|
+
hook_add_templates
|
29
|
+
end
|
30
|
+
|
31
|
+
# adds a hook before add_files to fail on clobber
|
32
|
+
# @return [void]
|
33
|
+
# @api private
|
34
|
+
def hook_add_files
|
35
|
+
@flavor.class.before_add_files do |files, resource_action|
|
36
|
+
if :create == resource_action && fail_on_clobber
|
37
|
+
files.each do |file|
|
38
|
+
if File.exist?(destination_path(file))
|
39
|
+
fail "tried to overwrite file #{file}; pass '-a clobber' to override"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# adds a hook before add_templates to fail on clobber
|
47
|
+
# @return [void]
|
48
|
+
# @api private
|
49
|
+
def hook_add_templates
|
50
|
+
@flavor.class.before_add_templates do |templates, resource_action|
|
51
|
+
if :create == resource_action && fail_on_clobber
|
52
|
+
templates.each do |template|
|
53
|
+
if File.exist?(destination_path(template))
|
54
|
+
fail "tried to overwrite file #{template}; pass '-a clobber' to override"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# a cookbook that has recipes
|
6
|
+
class Recipes < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'recipes'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in setup mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_setup
|
16
|
+
super
|
17
|
+
snippet_content_path = File.expand_path(File.join(static_content_path(__FILE__))) + '/.'
|
18
|
+
@flavor.class.do_add_content do
|
19
|
+
tocopy << [snippet_content_path]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# initializes the snippet in generate mode
|
24
|
+
# @return [void]
|
25
|
+
# @api private
|
26
|
+
def initialize_generate
|
27
|
+
super
|
28
|
+
@flavor.class.do_declare_resources do
|
29
|
+
directories << 'recipes'
|
30
|
+
templates_if_missing << File.join('recipes', 'default.rb')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# a cookbook that has provides resources and providers
|
6
|
+
class ResourceProvider < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'resource_provider'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in setup mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_setup
|
16
|
+
super
|
17
|
+
snippet_content_path = File.expand_path(File.join(static_content_path(__FILE__))) + '/.'
|
18
|
+
@flavor.class.do_add_content do
|
19
|
+
tocopy << [snippet_content_path]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# initializes the snippet in generate mode
|
24
|
+
# @return [void]
|
25
|
+
# @api private
|
26
|
+
def initialize_generate
|
27
|
+
super
|
28
|
+
@flavor.class.do_declare_resources do
|
29
|
+
directories << 'resources'
|
30
|
+
directories << 'providers'
|
31
|
+
templates_if_missing << File.join('resources', 'default.rb')
|
32
|
+
templates_if_missing << File.join('providers', 'default.rb')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
require 'chef/mixin/params_validate'
|
4
|
+
|
5
|
+
module ChefGen
|
6
|
+
module Snippet
|
7
|
+
# populates the list of ignore patterns for chefignore and .gitignore
|
8
|
+
class StandardIgnore < ChefGen::SnippetBase
|
9
|
+
# the name of the snippet
|
10
|
+
NAME = 'standard_ignore'
|
11
|
+
|
12
|
+
# @!attribute [rw] chefignore_patterns
|
13
|
+
# @return [Array<String>] a list of patterns for chefignore
|
14
|
+
|
15
|
+
# @!attribute [rw] gitignore_patterns
|
16
|
+
# @return [Array<String>] a list of patterns for .gitignore
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# initializes the snippet in generate mode
|
21
|
+
# @return [void]
|
22
|
+
# @api private
|
23
|
+
def initialize_generate
|
24
|
+
super
|
25
|
+
add_accessors
|
26
|
+
declare_chefignore
|
27
|
+
declare_gitignore
|
28
|
+
end
|
29
|
+
|
30
|
+
# adds accessors to the flavor for chefignore and gitignore patterns
|
31
|
+
# @return [void]
|
32
|
+
# @api private
|
33
|
+
def add_accessors
|
34
|
+
@flavor.class.send(:attr_accessor, :chefignore_patterns)
|
35
|
+
@flavor.chefignore_patterns = %w(
|
36
|
+
.DS_Store Icon? nohup.out ehthumbs.db Thumbs.db
|
37
|
+
.sasscache \#* .#* *~ *.sw[az] *.bak REVISION TAGS*
|
38
|
+
tmtags *_flymake.* *_flymake *.tmproj .project .settings
|
39
|
+
mkmf.log a.out *.o *.pyc *.so *.com *.class *.dll
|
40
|
+
*.exe */rdoc/ .watchr test/* features/* Procfile
|
41
|
+
.git */.git .gitignore .gitmodules .gitconfig .gitattributes
|
42
|
+
.svn */.bzr/* */.hg/* tmp/*
|
43
|
+
)
|
44
|
+
|
45
|
+
@flavor.class.send(:attr_accessor, :gitignore_patterns)
|
46
|
+
@flavor.gitignore_patterns = %w(
|
47
|
+
*~ *# .#* \#*# .*.sw[az] *.un~
|
48
|
+
bin/* .bundle/* tmp/*
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
# add the chefignore file resource, with content from the list
|
53
|
+
# of patterns in the instance var set to reasonable defaults
|
54
|
+
# and lazily evaluated
|
55
|
+
# @return [void]
|
56
|
+
# @api private
|
57
|
+
def declare_chefignore
|
58
|
+
@flavor.class.do_declare_resources do
|
59
|
+
# :nocov:
|
60
|
+
content = Chef::DelayedEvaluator.new do
|
61
|
+
chefignore_patterns.sort.uniq.join("\n") + "\n"
|
62
|
+
end
|
63
|
+
# :nocov:
|
64
|
+
add_files(%w(chefignore), :create_if_missing, :file, content: content)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# add the .gitignore file resource, with content from the list
|
69
|
+
# of patterns in the instance var set to reasonable defaults
|
70
|
+
# and lazily evaluated
|
71
|
+
# @return [void]
|
72
|
+
# @api private
|
73
|
+
def declare_gitignore
|
74
|
+
@flavor.class.do_declare_resources do
|
75
|
+
# :nocov:
|
76
|
+
content = Chef::DelayedEvaluator.new do
|
77
|
+
gitignore_patterns.sort.uniq.join("\n") + "\n"
|
78
|
+
end
|
79
|
+
# :nocov:
|
80
|
+
add_files(%w(.gitignore), :create_if_missing, :file, content: content)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# sets up style testing using Foodcritic
|
6
|
+
class StyleFoodcritic < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'style_foodcritic'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in generate mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_generate
|
16
|
+
super
|
17
|
+
declare_cookbook_gems
|
18
|
+
declare_rake_tasks
|
19
|
+
declare_guard_sets
|
20
|
+
end
|
21
|
+
|
22
|
+
# declares cookbook_gems if the flavor supports it
|
23
|
+
# @return [void]
|
24
|
+
# @api private
|
25
|
+
def declare_cookbook_gems
|
26
|
+
@flavor.class.do_declare_resources do
|
27
|
+
if snippet?('cookbook_base')
|
28
|
+
cookbook_gems['foodcritic'] = '~> 4.0'
|
29
|
+
cookbook_gems['guard-foodcritic'] = '~> 1.1'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# declares rake tasks if the flavor supports it
|
35
|
+
# @return [void]
|
36
|
+
# @api private
|
37
|
+
def declare_rake_tasks
|
38
|
+
@flavor.class.do_declare_resources do
|
39
|
+
if snippet?('cookbook_base')
|
40
|
+
rake_tasks['foodcritic'] = <<'END'
|
41
|
+
require 'foodcritic'
|
42
|
+
require 'foodcritic/rake_task'
|
43
|
+
|
44
|
+
FoodCritic::Rake::LintTask.new(:foodcritic)
|
45
|
+
task style: :foodcritic
|
46
|
+
END
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# declares guard sets if the flavor supports it
|
52
|
+
# @return [void]
|
53
|
+
def declare_guard_sets
|
54
|
+
@flavor.class.do_declare_resources do
|
55
|
+
if snippet?('guard')
|
56
|
+
guard_sets['foodcritic'] = <<'END'
|
57
|
+
guard :foodcritic,
|
58
|
+
cookbook_paths: '.',
|
59
|
+
cli: '-f any -X spec -X test -X features' do
|
60
|
+
watch(%r{^attributes/.+\.rb$})
|
61
|
+
watch(%r{^resources/.+\.rb$})
|
62
|
+
watch(%r{^providers/.+\.rb$})
|
63
|
+
watch(%r{^libraries/.+\.rb$})
|
64
|
+
watch(%r{^recipes/.+\.rb$})
|
65
|
+
watch(%r{^metadata\.rb$})
|
66
|
+
end
|
67
|
+
END
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'chef_gen/snippet_base'
|
2
|
+
|
3
|
+
module ChefGen
|
4
|
+
module Snippet
|
5
|
+
# sets up style testing using Rubocop
|
6
|
+
class StyleRubocop < ChefGen::SnippetBase
|
7
|
+
# the name of the snippet
|
8
|
+
NAME = 'style_rubocop'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# initializes the snippet in setup mode
|
13
|
+
# @return [void]
|
14
|
+
# @api private
|
15
|
+
def initialize_setup
|
16
|
+
super
|
17
|
+
snippet_content_path = File.expand_path(File.join(static_content_path(__FILE__))) + '/.'
|
18
|
+
@flavor.class.do_add_content do
|
19
|
+
tocopy << [snippet_content_path]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# initializes the snippet in generate mode
|
24
|
+
# @return [void]
|
25
|
+
# @api private
|
26
|
+
def initialize_generate
|
27
|
+
super
|
28
|
+
@flavor.class.do_declare_resources do
|
29
|
+
templates << '.rubocop.yml'
|
30
|
+
end
|
31
|
+
declare_chefignore_patterns
|
32
|
+
declare_cookbook_gems
|
33
|
+
declare_rake_tasks
|
34
|
+
declare_guard_sets
|
35
|
+
end
|
36
|
+
|
37
|
+
# declares chefignore patterns if the flavor supports it
|
38
|
+
# @return [void]
|
39
|
+
# @api private
|
40
|
+
def declare_chefignore_patterns
|
41
|
+
@flavor.class.do_declare_resources do
|
42
|
+
chefignore_patterns << '.rubocop.yml' if snippet?('standard_ignore')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# declares cookbook_gems if the flavor supports it
|
47
|
+
# @return [void]
|
48
|
+
# @api private
|
49
|
+
def declare_cookbook_gems
|
50
|
+
@flavor.class.do_declare_resources do
|
51
|
+
if snippet?('cookbook_base')
|
52
|
+
cookbook_gems['rubocop'] = '~> 0.34'
|
53
|
+
cookbook_gems['guard-rubocop'] = '~> 1.1'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# declares rake tasks if the flavor supports it
|
59
|
+
# @return [void]
|
60
|
+
# @api private
|
61
|
+
def declare_rake_tasks
|
62
|
+
@flavor.class.do_declare_resources do
|
63
|
+
if snippet?('cookbook_base')
|
64
|
+
rake_tasks['rubocop'] = <<'END'
|
65
|
+
require 'rubocop/rake_task'
|
66
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
67
|
+
t.formatters = ['progress']
|
68
|
+
t.options = ['-D']
|
69
|
+
t.patterns = %w(
|
70
|
+
attributes/*.rb
|
71
|
+
recipes/*.rb
|
72
|
+
libraries/**/*.rb
|
73
|
+
resources/*.rb
|
74
|
+
providers/*.rb
|
75
|
+
spec/**/*.rb
|
76
|
+
test/**/*.rb
|
77
|
+
./metadata.rb
|
78
|
+
./Berksfile
|
79
|
+
./Gemfile
|
80
|
+
./Rakefile
|
81
|
+
)
|
82
|
+
end
|
83
|
+
task style: :rubocop
|
84
|
+
END
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# declares guard sets if the flavor supports it
|
90
|
+
# @return [void]
|
91
|
+
# @api private
|
92
|
+
def declare_guard_sets
|
93
|
+
@flavor.class.do_declare_resources do
|
94
|
+
if snippet?('guard')
|
95
|
+
guard_sets['rubocop'] = <<'END'
|
96
|
+
guard :rubocop, all_on_start: true, cli: ['-f', 'p', '-D'] do
|
97
|
+
watch(%r{^attributes/.+\.rb$})
|
98
|
+
watch(%r{^recipes/.+\.rb$})
|
99
|
+
watch(%r{^libraries/.+\.rb$})
|
100
|
+
watch(%r{^resources/.+\.rb$})
|
101
|
+
watch(%r{^providers/.+\.rb$})
|
102
|
+
watch(%r{^spec/.+\.rb$})
|
103
|
+
watch(%r{^test/.+\.rb$})
|
104
|
+
watch(%r{^metadata\.rb$})
|
105
|
+
watch(%r{^Berksfile$})
|
106
|
+
watch(%r{^Gemfile$})
|
107
|
+
watch(%r{^Rakefile$})
|
108
|
+
end
|
109
|
+
END
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|