idlc-sdk-pfm 1.0.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/.yardopts +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/pfm +8 -0
- data/docs/GettingStarted.md +299 -0
- data/idlc-sdk-pfm.gemspec +44 -0
- data/lib/idlc-sdk-pfm/builtin_commands.rb +11 -0
- data/lib/idlc-sdk-pfm/cli.rb +150 -0
- data/lib/idlc-sdk-pfm/command/apply.rb +71 -0
- data/lib/idlc-sdk-pfm/command/base.rb +195 -0
- data/lib/idlc-sdk-pfm/command/build.rb +120 -0
- data/lib/idlc-sdk-pfm/command/configure.rb +41 -0
- data/lib/idlc-sdk-pfm/command/destroy.rb +61 -0
- data/lib/idlc-sdk-pfm/command/exec.rb +24 -0
- data/lib/idlc-sdk-pfm/command/format.rb +64 -0
- data/lib/idlc-sdk-pfm/command/generate.rb +83 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/base.rb +50 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/server_build.rb +58 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/Berksfile +3 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/build_cookbook/.kitchen.yml +21 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/build_cookbook/README.md +146 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +8 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/chefignore +107 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +9 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/cookbook_readmes/README.md +54 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/delivery-config.json +12 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/delivery-project.toml +36 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/gitignore +21 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/README.md +24 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +27 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +7 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +6 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +8 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/data_bags/README.md +56 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/data_bags/example/example_item.json +4 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/dot-chef-repo.txt +6 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/environments/README.md +9 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/environments/example.json +13 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/policies/README.md +24 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/roles/README.md +9 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/repo/roles/example.json +13 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/spec_helper.rb +2 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/files/default/spec_helper_policyfile.rb +2 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/metadata.rb +7 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/app.rb +89 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/attribute.rb +12 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/build_cookbook.rb +182 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/cookbook.rb +144 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/lwrp.rb +23 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/policyfile.rb +8 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/recipe.rb +51 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/repo.rb +67 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/template.rb +32 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/LICENSE.apachev2.erb +201 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/Policyfile.rb.erb +25 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/README.md.erb +4 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +7 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +10 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +8 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/inspec_default_test.rb.erb +18 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/kitchen.yml.erb +26 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +33 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/metadata.rb.erb +20 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/recipe_spec.rb.erb +22 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/repo/gitignore.erb +128 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
- data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/templates/default/template.erb +0 -0
- data/lib/idlc-sdk-pfm/command/generator_commands.rb +34 -0
- data/lib/idlc-sdk-pfm/command/plan.rb +80 -0
- data/lib/idlc-sdk-pfm/command/templates/app/files/config/client.rb.template +9 -0
- data/lib/idlc-sdk-pfm/command/templates/app/files/config/init.ps1.userdata +16 -0
- data/lib/idlc-sdk-pfm/command/templates/base/files/config/client.rb.template +6 -0
- data/lib/idlc-sdk-pfm/command/templates/base/files/config/init.ps1.userdata +219 -0
- data/lib/idlc-sdk-pfm/command/validate.rb +85 -0
- data/lib/idlc-sdk-pfm/command/validator_commands/base.rb +65 -0
- data/lib/idlc-sdk-pfm/command/validator_commands/infrastructure.rb +46 -0
- data/lib/idlc-sdk-pfm/command/validator_commands/server_build.rb +135 -0
- data/lib/idlc-sdk-pfm/command/validator_commands.rb +32 -0
- data/lib/idlc-sdk-pfm/commands_map.rb +61 -0
- data/lib/idlc-sdk-pfm/generator.rb +52 -0
- data/lib/idlc-sdk-pfm/helpers.rb +49 -0
- data/lib/idlc-sdk-pfm/settings.rb +205 -0
- data/lib/idlc-sdk-pfm/validator.rb +52 -0
- data/lib/idlc-sdk-pfm/version.rb +3 -0
- data/lib/idlc-sdk-pfm.rb +24 -0
- metadata +342 -0
@@ -0,0 +1,89 @@
|
|
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
|
+
# app root dir
|
9
|
+
directory app_dir
|
10
|
+
|
11
|
+
# Top level files
|
12
|
+
|
13
|
+
# Test Kitchen
|
14
|
+
template "#{app_dir}/.kitchen.yml" do
|
15
|
+
source 'kitchen.yml.erb'
|
16
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Inspec
|
20
|
+
directory "#{app_dir}/test/smoke/default" do
|
21
|
+
recursive true
|
22
|
+
end
|
23
|
+
|
24
|
+
template "#{app_dir}/test/smoke/default/default_test.rb" do
|
25
|
+
source 'inspec_default_test.rb.erb'
|
26
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
27
|
+
action :create_if_missing
|
28
|
+
end
|
29
|
+
|
30
|
+
# README
|
31
|
+
template "#{app_dir}/README.md" do
|
32
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Generated Cookbook:
|
36
|
+
|
37
|
+
# cookbook collection dir
|
38
|
+
directory cookbooks_dir
|
39
|
+
|
40
|
+
# cookbook collection dir
|
41
|
+
directory cookbook_dir
|
42
|
+
|
43
|
+
# metadata.rb
|
44
|
+
template "#{cookbook_dir}/metadata.rb" do
|
45
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
46
|
+
end
|
47
|
+
|
48
|
+
# chefignore
|
49
|
+
cookbook_file "#{cookbook_dir}/chefignore"
|
50
|
+
|
51
|
+
# Berks
|
52
|
+
cookbook_file "#{cookbook_dir}/Berksfile"
|
53
|
+
|
54
|
+
# Recipes
|
55
|
+
|
56
|
+
directory "#{cookbook_dir}/recipes"
|
57
|
+
|
58
|
+
template "#{cookbook_dir}/recipes/default.rb" do
|
59
|
+
source 'recipe.rb.erb'
|
60
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Chefspec
|
64
|
+
directory "#{cookbook_dir}/spec/unit/recipes" do
|
65
|
+
recursive true
|
66
|
+
end
|
67
|
+
|
68
|
+
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
69
|
+
action :create_if_missing
|
70
|
+
end
|
71
|
+
|
72
|
+
template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
|
73
|
+
source 'recipe_spec.rb.erb'
|
74
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
75
|
+
action :create_if_missing
|
76
|
+
end
|
77
|
+
|
78
|
+
# git
|
79
|
+
if context.have_git
|
80
|
+
unless context.skip_git_init
|
81
|
+
execute('initialize-git') do
|
82
|
+
command('git init .')
|
83
|
+
cwd app_dir
|
84
|
+
end
|
85
|
+
end
|
86
|
+
cookbook_file "#{app_dir}/.gitignore" do
|
87
|
+
source 'gitignore'
|
88
|
+
end
|
89
|
+
end
|
data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/attribute.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
attribute_dir = File.join(cookbook_dir, 'attributes')
|
5
|
+
attribute_path = File.join(cookbook_dir, 'attributes', "#{context.new_file_basename}.rb")
|
6
|
+
|
7
|
+
directory attribute_dir
|
8
|
+
|
9
|
+
template attribute_path do
|
10
|
+
source 'attribute.rb.erb'
|
11
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
12
|
+
end
|
data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/build_cookbook.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
delivery_project_dir = context.delivery_project_dir
|
4
|
+
pipeline = context.pipeline
|
5
|
+
dot_delivery_dir = File.join(delivery_project_dir, '.delivery')
|
6
|
+
config_json = File.join(dot_delivery_dir, 'config.json')
|
7
|
+
project_toml = File.join(dot_delivery_dir, 'project.toml')
|
8
|
+
|
9
|
+
generator_desc('Ensuring delivery configuration')
|
10
|
+
|
11
|
+
directory dot_delivery_dir
|
12
|
+
|
13
|
+
cookbook_file config_json do
|
14
|
+
source 'delivery-config.json'
|
15
|
+
not_if { File.exist?(config_json) }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Adding a new prototype file for delivery-cli local commands
|
19
|
+
cookbook_file project_toml do
|
20
|
+
source 'delivery-project.toml'
|
21
|
+
not_if { File.exist?(project_toml) }
|
22
|
+
end
|
23
|
+
|
24
|
+
generator_desc('Ensuring correct delivery build cookbook content')
|
25
|
+
|
26
|
+
build_cookbook_dir = File.join(dot_delivery_dir, 'build_cookbook')
|
27
|
+
|
28
|
+
# cookbook root dir
|
29
|
+
directory build_cookbook_dir
|
30
|
+
|
31
|
+
# metadata.rb
|
32
|
+
template "#{build_cookbook_dir}/metadata.rb" do
|
33
|
+
source 'build_cookbook/metadata.rb.erb'
|
34
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
35
|
+
action :create_if_missing
|
36
|
+
end
|
37
|
+
|
38
|
+
# README
|
39
|
+
cookbook_file "#{build_cookbook_dir}/README.md" do
|
40
|
+
source 'build_cookbook/README.md'
|
41
|
+
action :create_if_missing
|
42
|
+
end
|
43
|
+
|
44
|
+
# LICENSE
|
45
|
+
template "#{build_cookbook_dir}/LICENSE" do
|
46
|
+
source "LICENSE.#{context.license}.erb"
|
47
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
48
|
+
action :create_if_missing
|
49
|
+
end
|
50
|
+
|
51
|
+
# chefignore
|
52
|
+
cookbook_file "#{build_cookbook_dir}/chefignore"
|
53
|
+
|
54
|
+
# Berksfile
|
55
|
+
template "#{build_cookbook_dir}/Berksfile" do
|
56
|
+
source 'build_cookbook/Berksfile.erb'
|
57
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
58
|
+
action :create_if_missing
|
59
|
+
end
|
60
|
+
|
61
|
+
# Recipes
|
62
|
+
directory "#{build_cookbook_dir}/recipes"
|
63
|
+
|
64
|
+
%w(default deploy functional lint provision publish quality security smoke syntax unit).each do |phase|
|
65
|
+
template "#{build_cookbook_dir}/recipes/#{phase}.rb" do
|
66
|
+
source 'build_cookbook/recipe.rb.erb'
|
67
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
68
|
+
variables phase: phase
|
69
|
+
action :create_if_missing
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Test Kitchen build node
|
74
|
+
cookbook_file "#{build_cookbook_dir}/.kitchen.yml" do
|
75
|
+
source 'build_cookbook/.kitchen.yml'
|
76
|
+
end
|
77
|
+
|
78
|
+
directory "#{build_cookbook_dir}/data_bags/keys" do
|
79
|
+
recursive true
|
80
|
+
end
|
81
|
+
|
82
|
+
file "#{build_cookbook_dir}/data_bags/keys/delivery_builder_keys.json" do
|
83
|
+
content '{"id": "delivery_builder_keys"}'
|
84
|
+
end
|
85
|
+
|
86
|
+
directory "#{build_cookbook_dir}/secrets"
|
87
|
+
|
88
|
+
file "#{build_cookbook_dir}/secrets/fakey-mcfakerton"
|
89
|
+
|
90
|
+
directory "#{build_cookbook_dir}/test/fixtures/cookbooks/test/recipes" do
|
91
|
+
recursive true
|
92
|
+
end
|
93
|
+
|
94
|
+
file "#{build_cookbook_dir}/test/fixtures/cookbooks/test/metadata.rb" do
|
95
|
+
content %(name 'test'
|
96
|
+
version '0.1.0')
|
97
|
+
end
|
98
|
+
|
99
|
+
cookbook_file "#{build_cookbook_dir}/test/fixtures/cookbooks/test/recipes/default.rb" do
|
100
|
+
source 'build_cookbook/test-fixture-recipe.rb'
|
101
|
+
end
|
102
|
+
|
103
|
+
# Construct git history as if we did all the work in a feature branch which we
|
104
|
+
# merged into master at the end, which looks like this:
|
105
|
+
#
|
106
|
+
# ```
|
107
|
+
# git log --graph --oneline
|
108
|
+
# * 5fec5bd Merge branch 'add-delivery-configuration'
|
109
|
+
# |\
|
110
|
+
# | * 967bb9f Add generated delivery build cookbook
|
111
|
+
# | * 1558e0a Add generated delivery configuration
|
112
|
+
# |/
|
113
|
+
# * db22790 Add generated cookbook content
|
114
|
+
# ```
|
115
|
+
#
|
116
|
+
if context.have_git && context.delivery_project_git_initialized && !context.skip_git_init
|
117
|
+
|
118
|
+
generator_desc('Adding delivery configuration to feature branch')
|
119
|
+
|
120
|
+
execute('git-create-feature-branch') do
|
121
|
+
command('git checkout -t -b add-delivery-configuration')
|
122
|
+
cwd delivery_project_dir
|
123
|
+
|
124
|
+
not_if 'git branch |grep "add-delivery-configuration"'
|
125
|
+
end
|
126
|
+
|
127
|
+
execute('git-add-delivery-config-json') do
|
128
|
+
command('git add .delivery/config.json')
|
129
|
+
cwd delivery_project_dir
|
130
|
+
|
131
|
+
only_if 'git status -u --porcelain |grep ".delivery/config.json"'
|
132
|
+
end
|
133
|
+
|
134
|
+
# Adding the new prototype file to the feature branch
|
135
|
+
# so it gets checked in with the delivery config commit
|
136
|
+
execute('git-add-delivery-project-toml') do
|
137
|
+
command('git add .delivery/project.toml')
|
138
|
+
cwd delivery_project_dir
|
139
|
+
|
140
|
+
only_if 'git status -u --porcelain |grep ".delivery/project.toml"'
|
141
|
+
end
|
142
|
+
|
143
|
+
execute('git-commit-delivery-config') do
|
144
|
+
command('git commit -m "Add generated delivery configuration"')
|
145
|
+
cwd delivery_project_dir
|
146
|
+
|
147
|
+
only_if 'git status -u --porcelain | egrep "config.json|project.toml"'
|
148
|
+
end
|
149
|
+
|
150
|
+
generator_desc('Adding build cookbook to feature branch')
|
151
|
+
|
152
|
+
execute('git-add-delivery-build-cookbook-files') do
|
153
|
+
command('git add .delivery')
|
154
|
+
cwd delivery_project_dir
|
155
|
+
|
156
|
+
only_if 'git status -u --porcelain |grep ".delivery"'
|
157
|
+
end
|
158
|
+
|
159
|
+
execute('git-commit-delivery-build-cookbook') do
|
160
|
+
command('git commit -m "Add generated delivery build cookbook"')
|
161
|
+
cwd delivery_project_dir
|
162
|
+
|
163
|
+
only_if 'git status -u --porcelain |grep ".delivery"'
|
164
|
+
end
|
165
|
+
|
166
|
+
execute("git-return-to-#{pipeline}-branch") do
|
167
|
+
command("git checkout #{pipeline}")
|
168
|
+
cwd delivery_project_dir
|
169
|
+
end
|
170
|
+
|
171
|
+
generator_desc('Merging delivery content feature branch to master')
|
172
|
+
|
173
|
+
execute('git-merge-delivery-config-branch') do
|
174
|
+
command('git merge --no-ff add-delivery-configuration')
|
175
|
+
cwd delivery_project_dir
|
176
|
+
end
|
177
|
+
|
178
|
+
execute('git-remove-delivery-config-branch') do
|
179
|
+
command('git branch -D add-delivery-configuration')
|
180
|
+
cwd delivery_project_dir
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
|
5
|
+
silence_chef_formatter unless context.verbose
|
6
|
+
|
7
|
+
generator_desc('Ensuring correct cookbook file content')
|
8
|
+
|
9
|
+
# cookbook root dir
|
10
|
+
directory cookbook_dir
|
11
|
+
|
12
|
+
# metadata.rb
|
13
|
+
spdx_license = case context.license
|
14
|
+
when 'apachev2'
|
15
|
+
'Apache-2.0'
|
16
|
+
when 'mit'
|
17
|
+
'MIT'
|
18
|
+
when 'gplv2'
|
19
|
+
'GPL-2.0'
|
20
|
+
when 'gplv3'
|
21
|
+
'GPL-3.0'
|
22
|
+
else
|
23
|
+
'All Rights Reserved'
|
24
|
+
end
|
25
|
+
|
26
|
+
template "#{cookbook_dir}/metadata.rb" do
|
27
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
28
|
+
variables(
|
29
|
+
spdx_license: spdx_license
|
30
|
+
)
|
31
|
+
action :create_if_missing
|
32
|
+
end
|
33
|
+
|
34
|
+
# README
|
35
|
+
template "#{cookbook_dir}/README.md" do
|
36
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
37
|
+
action :create_if_missing
|
38
|
+
end
|
39
|
+
|
40
|
+
# chefignore
|
41
|
+
cookbook_file "#{cookbook_dir}/chefignore"
|
42
|
+
|
43
|
+
if context.use_berkshelf
|
44
|
+
|
45
|
+
# Berks
|
46
|
+
cookbook_file "#{cookbook_dir}/Berksfile" do
|
47
|
+
action :create_if_missing
|
48
|
+
end
|
49
|
+
else
|
50
|
+
|
51
|
+
# Policyfile
|
52
|
+
template "#{cookbook_dir}/Policyfile.rb" do
|
53
|
+
source 'Policyfile.rb.erb'
|
54
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# Test Kitchen
|
60
|
+
template "#{cookbook_dir}/.kitchen.yml" do
|
61
|
+
if context.use_berkshelf
|
62
|
+
source 'kitchen.yml.erb'
|
63
|
+
else
|
64
|
+
source 'kitchen_policyfile.yml.erb'
|
65
|
+
end
|
66
|
+
|
67
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
68
|
+
action :create_if_missing
|
69
|
+
end
|
70
|
+
|
71
|
+
# Inspec
|
72
|
+
directory "#{cookbook_dir}/test/smoke/default" do
|
73
|
+
recursive true
|
74
|
+
end
|
75
|
+
|
76
|
+
template "#{cookbook_dir}/test/smoke/default/default_test.rb" do
|
77
|
+
source 'inspec_default_test.rb.erb'
|
78
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
79
|
+
action :create_if_missing
|
80
|
+
end
|
81
|
+
|
82
|
+
# Chefspec
|
83
|
+
directory "#{cookbook_dir}/spec/unit/recipes" do
|
84
|
+
recursive true
|
85
|
+
end
|
86
|
+
|
87
|
+
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
88
|
+
if context.use_berkshelf
|
89
|
+
source 'spec_helper.rb'
|
90
|
+
else
|
91
|
+
source 'spec_helper_policyfile.rb'
|
92
|
+
end
|
93
|
+
|
94
|
+
action :create_if_missing
|
95
|
+
end
|
96
|
+
|
97
|
+
template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
|
98
|
+
source 'recipe_spec.rb.erb'
|
99
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
100
|
+
action :create_if_missing
|
101
|
+
end
|
102
|
+
|
103
|
+
# Recipes
|
104
|
+
|
105
|
+
directory "#{cookbook_dir}/recipes"
|
106
|
+
|
107
|
+
template "#{cookbook_dir}/recipes/default.rb" do
|
108
|
+
source 'recipe.rb.erb'
|
109
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
110
|
+
action :create_if_missing
|
111
|
+
end
|
112
|
+
|
113
|
+
# git
|
114
|
+
if context.have_git
|
115
|
+
unless context.skip_git_init
|
116
|
+
|
117
|
+
generator_desc('Committing cookbook files to git')
|
118
|
+
|
119
|
+
execute('initialize-git') do
|
120
|
+
command('git init .')
|
121
|
+
cwd cookbook_dir
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
cookbook_file "#{cookbook_dir}/.gitignore" do
|
127
|
+
source 'gitignore'
|
128
|
+
end
|
129
|
+
|
130
|
+
unless context.skip_git_init
|
131
|
+
|
132
|
+
execute('git-add-new-files') do
|
133
|
+
command('git add .')
|
134
|
+
cwd cookbook_dir
|
135
|
+
end
|
136
|
+
|
137
|
+
execute('git-commit-new-files') do
|
138
|
+
command('git commit -m "Add generated cookbook content"')
|
139
|
+
cwd cookbook_dir
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
include_recipe '::build_cookbook' if context.enable_delivery
|
data/lib/idlc-sdk-pfm/command/generator_commands/skeletons/code_generator/recipes/cookbook_file.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
files_dir = File.join(cookbook_dir, 'files', 'default')
|
5
|
+
cookbook_file_path = File.join(cookbook_dir, 'files', 'default', context.new_file_basename)
|
6
|
+
|
7
|
+
directory files_dir do
|
8
|
+
recursive true
|
9
|
+
end
|
10
|
+
|
11
|
+
if context.content_source
|
12
|
+
|
13
|
+
file cookbook_file_path do
|
14
|
+
content(IO.read(context.context_source))
|
15
|
+
end
|
16
|
+
|
17
|
+
else
|
18
|
+
|
19
|
+
template cookbook_file_path do
|
20
|
+
source 'cookbook_file.erb'
|
21
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
|
5
|
+
resource_dir = File.join(cookbook_dir, 'resources')
|
6
|
+
resource_path = File.join(resource_dir, "#{context.new_file_basename}.rb")
|
7
|
+
|
8
|
+
provider_dir = File.join(cookbook_dir, 'providers')
|
9
|
+
provider_path = File.join(provider_dir, "#{context.new_file_basename}.rb")
|
10
|
+
|
11
|
+
directory resource_dir
|
12
|
+
|
13
|
+
template resource_path do
|
14
|
+
source 'resource.rb.erb'
|
15
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
16
|
+
end
|
17
|
+
|
18
|
+
directory provider_dir
|
19
|
+
|
20
|
+
template provider_path do
|
21
|
+
source 'provider.rb.erb'
|
22
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
recipe_path = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.rb")
|
5
|
+
spec_helper_path = File.join(cookbook_dir, 'spec', 'spec_helper.rb')
|
6
|
+
spec_dir = File.join(cookbook_dir, 'spec', 'unit', 'recipes')
|
7
|
+
spec_path = File.join(spec_dir, "#{context.new_file_basename}_spec.rb")
|
8
|
+
inspec_dir = File.join(cookbook_dir, 'test', 'smoke', 'default')
|
9
|
+
inspec_path = File.join(inspec_dir, "#{context.new_file_basename}_test.rb")
|
10
|
+
|
11
|
+
if File.directory?(File.join(cookbook_dir, 'test', 'recipes'))
|
12
|
+
Chef::Log.deprecation <<-EOH
|
13
|
+
It appears that you have Inspec tests located at "test/recipes". This location can
|
14
|
+
cause issues with Foodcritic and has been deprecated in favor of "test/smoke/default".
|
15
|
+
Please move your existing Inspec tests to the newly created "test/smoke/default"
|
16
|
+
directory, and update the 'inspec_tests' value in your .kitchen.yml file(s) to
|
17
|
+
point to "test/smoke/default".
|
18
|
+
EOH
|
19
|
+
end
|
20
|
+
|
21
|
+
# Chefspec
|
22
|
+
directory spec_dir do
|
23
|
+
recursive true
|
24
|
+
end
|
25
|
+
|
26
|
+
cookbook_file spec_helper_path do
|
27
|
+
action :create_if_missing
|
28
|
+
end
|
29
|
+
|
30
|
+
template spec_path do
|
31
|
+
source 'recipe_spec.rb.erb'
|
32
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
33
|
+
action :create_if_missing
|
34
|
+
end
|
35
|
+
|
36
|
+
# Inspec
|
37
|
+
directory inspec_dir do
|
38
|
+
recursive true
|
39
|
+
end
|
40
|
+
|
41
|
+
template inspec_path do
|
42
|
+
source 'inspec_default_test.rb.erb'
|
43
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
44
|
+
action :create_if_missing
|
45
|
+
end
|
46
|
+
|
47
|
+
# Recipe
|
48
|
+
template recipe_path do
|
49
|
+
source 'recipe.rb.erb'
|
50
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
context = ChefDK::Generator.context
|
2
|
+
repo_dir = File.join(context.repo_root, context.repo_name)
|
3
|
+
|
4
|
+
# repo root dir
|
5
|
+
directory repo_dir
|
6
|
+
|
7
|
+
# Top level files
|
8
|
+
template "#{repo_dir}/LICENSE" do
|
9
|
+
source "LICENSE.#{context.license}.erb"
|
10
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
11
|
+
action :create_if_missing
|
12
|
+
end
|
13
|
+
|
14
|
+
cookbook_file "#{repo_dir}/.chef-repo.txt" do
|
15
|
+
source 'repo/dot-chef-repo.txt'
|
16
|
+
action :create_if_missing
|
17
|
+
end
|
18
|
+
|
19
|
+
cookbook_file "#{repo_dir}/README.md" do
|
20
|
+
source 'repo/README.md'
|
21
|
+
action :create_if_missing
|
22
|
+
end
|
23
|
+
|
24
|
+
cookbook_file "#{repo_dir}/chefignore" do
|
25
|
+
source 'chefignore'
|
26
|
+
action :create_if_missing
|
27
|
+
end
|
28
|
+
|
29
|
+
directories_to_create = %w( cookbooks data_bags )
|
30
|
+
|
31
|
+
directories_to_create += if context.use_roles
|
32
|
+
%w( roles environments )
|
33
|
+
else
|
34
|
+
%w( policies )
|
35
|
+
end
|
36
|
+
|
37
|
+
directories_to_create.each do |tlo|
|
38
|
+
remote_directory "#{repo_dir}/#{tlo}" do
|
39
|
+
source "repo/#{tlo}"
|
40
|
+
action :create_if_missing
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
cookbook_file "#{repo_dir}/cookbooks/README.md" do
|
45
|
+
if context.policy_only
|
46
|
+
source 'cookbook_readmes/README-policy.md'
|
47
|
+
else
|
48
|
+
source 'cookbook_readmes/README.md'
|
49
|
+
end
|
50
|
+
action :create_if_missing
|
51
|
+
end
|
52
|
+
|
53
|
+
# git
|
54
|
+
if context.have_git
|
55
|
+
unless context.skip_git_init
|
56
|
+
execute('initialize-git') do
|
57
|
+
command('git init .')
|
58
|
+
cwd repo_dir
|
59
|
+
not_if { File.exist?("#{repo_dir}/.gitignore") }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
template "#{repo_dir}/.gitignore" do
|
63
|
+
source 'repo/gitignore.erb'
|
64
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
65
|
+
action :create_if_missing
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
context = ChefDK::Generator.context
|
3
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
4
|
+
template_dir = File.join(cookbook_dir, 'templates', 'default')
|
5
|
+
template_filename = context.new_file_basename
|
6
|
+
|
7
|
+
unless File.extname(template_filename) == '.erb'
|
8
|
+
# new_file_basename is a frozen string, so we have to create an entirely
|
9
|
+
# new string here instead of using concat.
|
10
|
+
template_filename = "#{template_filename}.erb"
|
11
|
+
end
|
12
|
+
|
13
|
+
template_path = File.join(cookbook_dir, 'templates', template_filename)
|
14
|
+
|
15
|
+
directory template_dir do
|
16
|
+
recursive true
|
17
|
+
end
|
18
|
+
|
19
|
+
if context.content_source
|
20
|
+
|
21
|
+
file template_path do
|
22
|
+
content(IO.read(context.context_source))
|
23
|
+
end
|
24
|
+
|
25
|
+
else
|
26
|
+
|
27
|
+
template template_path do
|
28
|
+
source 'template.erb'
|
29
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|