chef-cli 3.1.3 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/chef-cli.gemspec +1 -1
  4. data/lib/chef-cli/command/generate.rb +5 -3
  5. data/lib/chef-cli/command/generator_commands/cookbook.rb +32 -2
  6. data/lib/chef-cli/command/generator_commands/recipe.rb +7 -0
  7. data/lib/chef-cli/completions/chef.fish.erb +4 -5
  8. data/lib/chef-cli/helpers.rb +10 -7
  9. data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +50 -24
  10. data/lib/chef-cli/skeletons/code_generator/recipes/recipe.rb +11 -3
  11. data/lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb +36 -0
  12. data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +1 -0
  13. data/lib/chef-cli/skeletons/code_generator/templates/default/recipe.yml.erb +18 -0
  14. data/lib/chef-cli/version.rb +1 -1
  15. data/spec/unit/command/generate_spec.rb +7 -0
  16. data/spec/unit/command/generator_commands/cookbook_spec.rb +91 -226
  17. data/spec/unit/command/generator_commands/recipe_spec.rb +34 -0
  18. data/spec/unit/command/shell_init_spec.rb +10 -10
  19. data/spec/unit/helpers_spec.rb +111 -0
  20. metadata +7 -14
  21. data/lib/chef-cli/command/generator_commands/build_cookbook.rb +0 -126
  22. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +0 -146
  23. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +0 -21
  24. data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +0 -8
  25. data/lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json +0 -17
  26. data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +0 -175
  27. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +0 -7
  28. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +0 -10
  29. data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +0 -9
  30. data/spec/unit/command/generator_commands/build_cookbook_spec.rb +0 -377
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aef40ff73580003cb8253f756a4da57c36c0fa7266e9df50fa5b3ff877b2c2b
4
- data.tar.gz: a041fb63c6b24c45ddc3f90e40f8abf1f876cdeb3655ce1c2be09d87f17eb42a
3
+ metadata.gz: a13b7fe5a79e96a77dbe15637e0c7049ba7a2b1497c9b51ae1a8512dde66173e
4
+ data.tar.gz: cfa51c708cf8c115755dc5e243f6ac08b658bb71cb9dd4b015d8738de229ae26
5
5
  SHA512:
6
- metadata.gz: 0361a3d6fe8f08665baebc4b69e931f6ed1546288d705c5cb2e09ce208712674afbb2ff07e4c6a45a1e9db1e5cb05b5788d2171af6280b594ed50f3a940335cb
7
- data.tar.gz: d731fea15f7a1996687719a7f804e475020cef4d52f2da38b852ddd2e43c06f0493571cdb373ec23e3220d2fa1ac1e51aed7edf95cecf539a0c39a747f23b92b
6
+ metadata.gz: 974da449a8873d332523b92a0a263f675d80bd8b378317e645f80ea2bc5bdcff5fb476a038e7ce41268e1c88222d2625695aef90bf7311ddf2c7972b001c99f2
7
+ data.tar.gz: 6a3504dc2d8f14b4a1ad63085fb74661c18e89d78551c0d2fd65efdb392c588277fd9202bbada3c09471290743c1eee389268008b6d132d926a958b035024ffe
data/Gemfile CHANGED
@@ -10,11 +10,15 @@ group :test do
10
10
  gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command
11
11
  gem "chefstyle", "=1.6.2"
12
12
  gem "test-kitchen", ">= 2.11.1"
13
+
13
14
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
14
15
  gem "chef-zero", "~> 14"
15
16
  gem "chef", "~> 15"
16
17
  gem "chef-utils", "=16.6.14"
17
18
  end
19
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")
20
+ gem "ohai", "~> 16"
21
+ end
18
22
  end
19
23
 
20
24
  group :development do
data/chef-cli.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
29
29
  gem.license = "Apache-2.0"
30
30
  gem.homepage = "https://www.chef.io/"
31
31
 
32
- gem.required_ruby_version = ">= 2.5"
32
+ gem.required_ruby_version = ">= 2.6"
33
33
 
34
34
  gem.files = %w{Rakefile LICENSE} +
35
35
  Dir.glob("Gemfile*") + # Includes Gemfile and locks
@@ -29,7 +29,6 @@ require_relative "generator_commands/template"
29
29
  require_relative "generator_commands/repo"
30
30
  require_relative "generator_commands/policyfile"
31
31
  require_relative "generator_commands/generator_generator"
32
- require_relative "generator_commands/build_cookbook"
33
32
  require_relative "../dist"
34
33
 
35
34
  module ChefCLI
@@ -56,7 +55,7 @@ module ChefCLI
56
55
  generator(:repo, :Repo, "Generate a #{ChefCLI::Dist::INFRA_PRODUCT} code repository")
57
56
  generator(:policyfile, :Policyfile, "Generate a Policyfile for use with the install/push commands")
58
57
  generator(:generator, :GeneratorGenerator, "Copy #{ChefCLI::Dist::PRODUCT}'s generator cookbook so you can customize it")
59
- generator(:'build-cookbook', :BuildCookbook, "Generate a build cookbook for use with #{ChefCLI::Dist::WORKFLOW}")
58
+ generator(:'build-cookbook', :BuildCookbook, "DEPRECATED: Generate a build cookbook for use with #{ChefCLI::Dist::WORKFLOW}")
60
59
 
61
60
  def self.banner_headline
62
61
  <<~E
@@ -83,6 +82,10 @@ module ChefCLI
83
82
  end
84
83
 
85
84
  def run(params)
85
+ if params[0] == "build-cookbook"
86
+ warn "[DEPRECATION] Chef Workflow (Delivery) is end of life (EOL) as of December 31, 2020 and this generator subcommand has been removed".freeze
87
+ return 1
88
+ end
86
89
  if ( generator_spec = generator_for(params[0]) )
87
90
  params.shift
88
91
  generator = GeneratorCommands.build(generator_spec.class_name, params)
@@ -118,7 +121,6 @@ module ChefCLI
118
121
  def have_generator?(name)
119
122
  self.class.generators.map { |g| g.name.to_s }.include?(name)
120
123
  end
121
-
122
124
  end
123
125
  end
124
126
  end
@@ -55,10 +55,17 @@ module ChefCLI
55
55
  boolean: true,
56
56
  default: nil
57
57
 
58
+ option :specs,
59
+ short: "-s",
60
+ long: "--specs",
61
+ description: "Generate a cookbook with sample ChefSpec specs",
62
+ boolean: true,
63
+ default: nil
64
+
58
65
  option :workflow,
59
66
  short: "-w",
60
67
  long: "--workflow",
61
- description: "Generate a cookbook with a full #{ChefCLI::Dist::WORKFLOW} build cookbook.",
68
+ description: "DEPRECATED: Generate a cookbook with a full #{ChefCLI::Dist::WORKFLOW} build cookbook.",
62
69
  boolean: true,
63
70
  default: false
64
71
 
@@ -69,6 +76,13 @@ module ChefCLI
69
76
  boolean: true,
70
77
  default: false
71
78
 
79
+ option :yaml,
80
+ short: "-y",
81
+ long: "--yaml",
82
+ description: "Generate a cookbook with YAML Recipe configuration file as the default.",
83
+ boolean: true,
84
+ default: nil
85
+
72
86
  option :pipeline,
73
87
  long: "--pipeline PIPELINE",
74
88
  description: "Use PIPELINE to set target branch to something other than master for the #{ChefCLI::Dist::WORKFLOW} build_cookbook",
@@ -81,6 +95,7 @@ module ChefCLI
81
95
  @cookbook_name = nil
82
96
  @policy_mode = true
83
97
  @verbose = false
98
+ @specs = false
84
99
  super
85
100
  end
86
101
 
@@ -103,6 +118,7 @@ module ChefCLI
103
118
  end
104
119
 
105
120
  def emit_post_create_message
121
+ default_recipe_file = yaml ? "default.yml" : "default.rb"
106
122
  if have_delivery_config?
107
123
  msg("Your cookbook is ready. To setup the pipeline, type `cd #{cookbook_name_or_path}`, then run `delivery init`")
108
124
  else
@@ -112,7 +128,7 @@ module ChefCLI
112
128
  msg("\nWhy not start by writing an InSpec test? Tests for the default recipe are stored at:\n")
113
129
  msg("test/integration/default/default_test.rb")
114
130
  msg("\nIf you'd prefer to dive right in, the default recipe can be found at:")
115
- msg("\nrecipes/default.rb\n")
131
+ msg("\nrecipes/#{default_recipe_file}\n")
116
132
  end
117
133
  end
118
134
 
@@ -133,11 +149,13 @@ module ChefCLI
133
149
  Generator.add_attr_to_context(:workflow_project_git_initialized, have_git? && !cookbook_path_in_git_repo?)
134
150
 
135
151
  Generator.add_attr_to_context(:verbose, verbose?)
152
+ Generator.add_attr_to_context(:specs, specs?)
136
153
 
137
154
  Generator.add_attr_to_context(:use_policyfile, policy_mode?)
138
155
  Generator.add_attr_to_context(:pipeline, pipeline)
139
156
  Generator.add_attr_to_context(:kitchen, kitchen)
140
157
  Generator.add_attr_to_context(:vscode_dir, create_vscode_dir?)
158
+ Generator.add_attr_to_context(:yaml, yaml)
141
159
  end
142
160
 
143
161
  def kitchen
@@ -148,6 +166,10 @@ module ChefCLI
148
166
  config[:pipeline]
149
167
  end
150
168
 
169
+ def yaml
170
+ config[:yaml]
171
+ end
172
+
151
173
  def policy_name
152
174
  cookbook_name
153
175
  end
@@ -188,6 +210,10 @@ module ChefCLI
188
210
  @verbose
189
211
  end
190
212
 
213
+ def specs?
214
+ @specs
215
+ end
216
+
191
217
  #
192
218
  # Is there a .delivery/cli.toml in the current dir or any of the parent dirs
193
219
  #
@@ -223,6 +249,10 @@ module ChefCLI
223
249
  @verbose = true
224
250
  end
225
251
 
252
+ if config[:specs]
253
+ @specs = true
254
+ end
255
+
226
256
  true
227
257
  end
228
258
 
@@ -26,6 +26,13 @@ module ChefCLI
26
26
 
27
27
  banner "Usage: #{ChefCLI::Dist::EXEC} generate recipe [path/to/cookbook] NAME [options]"
28
28
 
29
+ option :yaml,
30
+ short: "-y",
31
+ long: "--yaml",
32
+ description: "Generate recipe using YAML configuration format.",
33
+ boolean: true,
34
+ default: nil
35
+
29
36
  options.merge!(SharedGeneratorOptions.options)
30
37
 
31
38
  def recipe
@@ -1,10 +1,9 @@
1
+
1
2
  # Fish Shell command-line completions for <%=ChefCLI::Dist::PRODUCT %>
2
3
 
3
- function __fish_chef_no_command --description 'Test if chef has yet to be given the main command'
4
- set -l cmd (commandline -opc)
5
- test (count $cmd) -eq 1
6
- end
4
+ # set a list of all the chef commands in the Ruby chef-cli
5
+ set -l chef_commands <%= commands.keys.join(' ') %>;
7
6
 
8
7
  <% commands.each do |command, desc| -%>
9
- complete -c chef -f -n '__fish_chef_no_command' -a <%= command %> -d "<%= desc %>"
8
+ complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>";
10
9
  <% end -%>
@@ -87,7 +87,7 @@ module ChefCLI
87
87
  # On Mac we place all of our symlinks under /usr/local/bin on other
88
88
  # platforms they are under /usr/bin
89
89
  def usr_bin_prefix
90
- @usr_bin_prefix ||= os_x? ? "/usr/local/bin" : "/usr/bin"
90
+ @usr_bin_prefix ||= macos? ? "/usr/local/bin" : "/usr/bin"
91
91
  end
92
92
 
93
93
  # Returns the full path to the given command under usr_bin_prefix
@@ -117,11 +117,11 @@ module ChefCLI
117
117
  @omnibus_env ||=
118
118
  begin
119
119
  user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
120
- path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"] ]
120
+ path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ]
121
121
  path << git_bin_dir if Dir.exist?(git_bin_dir)
122
122
  path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir)
123
123
  {
124
- "PATH" => path.join(File::PATH_SEPARATOR),
124
+ "PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR),
125
125
  "GEM_ROOT" => Gem.default_dir,
126
126
  "GEM_HOME" => Gem.user_dir,
127
127
  "GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR),
@@ -129,8 +129,6 @@ module ChefCLI
129
129
  end
130
130
  end
131
131
 
132
- private
133
-
134
132
  def omnibus_expand_path(*paths)
135
133
  dir = File.expand_path(File.join(paths))
136
134
  raise OmnibusInstallNotFound.new unless dir && File.directory?(dir)
@@ -138,6 +136,8 @@ module ChefCLI
138
136
  dir
139
137
  end
140
138
 
139
+ private
140
+
141
141
  def expected_omnibus_root
142
142
  File.expand_path(File.join(Gem.ruby, "..", "..", ".."))
143
143
  end
@@ -166,8 +166,11 @@ module ChefCLI
166
166
  end
167
167
  end
168
168
 
169
- # Returns true if we are on Mac OS X. Otherwise false
170
- def os_x?
169
+ # @return [Boolean] Returns true if we are on macOS. Otherwise false
170
+ #
171
+ # @api private
172
+ #
173
+ def macos?
171
174
  !!(RUBY_PLATFORM =~ /darwin/)
172
175
  end
173
176
  end
@@ -92,43 +92,56 @@ template "#{cookbook_dir}/test/integration/default/default_test.rb" do
92
92
  end
93
93
 
94
94
  # ChefSpec
95
- directory "#{cookbook_dir}/spec/unit/recipes" do
96
- recursive true
97
- end
98
-
99
- cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
100
- if context.use_policyfile
101
- source 'spec_helper_policyfile.rb'
102
- else
103
- source 'spec_helper.rb'
95
+ if context.specs
96
+ directory "#{cookbook_dir}/spec/unit/recipes" do
97
+ recursive true
104
98
  end
105
99
 
106
- action :create_if_missing
107
- end
100
+ cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
101
+ if context.use_policyfile
102
+ source 'spec_helper_policyfile.rb'
103
+ else
104
+ source 'spec_helper.rb'
105
+ end
108
106
 
109
- template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
110
- source 'recipe_spec.rb.erb'
111
- helpers(ChefCLI::Generator::TemplateHelper)
112
- action :create_if_missing
107
+ action :create_if_missing
108
+ end
109
+
110
+ template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
111
+ source 'recipe_spec.rb.erb'
112
+ helpers(ChefCLI::Generator::TemplateHelper)
113
+ action :create_if_missing
114
+ end
113
115
  end
114
116
 
115
117
  # Recipes
116
118
  directory "#{cookbook_dir}/recipes"
117
119
 
118
- template "#{cookbook_dir}/recipes/default.rb" do
119
- source 'recipe.rb.erb'
120
- helpers(ChefCLI::Generator::TemplateHelper)
121
- action :create_if_missing
120
+ if context.yaml
121
+ template "#{cookbook_dir}/recipes/default.yml" do
122
+ source 'recipe.yml.erb'
123
+ helpers(ChefCLI::Generator::TemplateHelper)
124
+ action :create_if_missing
125
+ end
126
+ else
127
+ template "#{cookbook_dir}/recipes/default.rb" do
128
+ source 'recipe.rb.erb'
129
+ helpers(ChefCLI::Generator::TemplateHelper)
130
+ action :create_if_missing
131
+ end
122
132
  end
123
133
 
124
134
  # the same will be done below if workflow was enabled so avoid double work and skip this
125
135
  unless context.enable_workflow
126
136
  directory "#{cookbook_dir}/.delivery"
127
137
 
128
- # Adding the delivery local-mode config
129
- cookbook_file "#{cookbook_dir}/.delivery/project.toml" do
130
- source 'delivery-project.toml'
131
- not_if { ::File.exist?("#{cookbook_dir}/.delivery/project.toml") }
138
+ template "#{cookbook_dir}/.delivery/project.toml" do
139
+ variables(
140
+ specs: context.specs
141
+ )
142
+ source 'delivery-project.toml.erb'
143
+ helpers(ChefCLI::Generator::TemplateHelper)
144
+ action :create_if_missing
132
145
  end
133
146
  end
134
147
 
@@ -177,4 +190,17 @@ if context.vscode_dir
177
190
  end
178
191
  end
179
192
 
180
- include_recipe '::build_cookbook' if context.enable_workflow
193
+ if context.enable_workflow
194
+ warn "\n---------WARNING---------\nThe --workflow flag is deprecated as #{ChefCLI::Dist::WORKFLOW} is EOL as of December 2020.\n\nThis flag will be ignored and will be removed in a future release.\n-------------------------\n\n"
195
+ directory "#{cookbook_dir}/.delivery"
196
+
197
+ template "#{cookbook_dir}/.delivery/project.toml" do
198
+ variables(
199
+ specs: context.specs
200
+ )
201
+ source 'delivery-project.toml.erb'
202
+ helpers(ChefCLI::Generator::TemplateHelper)
203
+ action :create_if_missing
204
+ end
205
+
206
+ end
@@ -1,6 +1,7 @@
1
1
  context = ChefCLI::Generator.context
2
2
  cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
3
3
  recipe_path = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.rb")
4
+ recipe_path_yml = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.yml")
4
5
  spec_helper_path = File.join(cookbook_dir, 'spec', 'spec_helper.rb')
5
6
  spec_dir = File.join(cookbook_dir, 'spec', 'unit', 'recipes')
6
7
  spec_path = File.join(spec_dir, "#{context.new_file_basename}_spec.rb")
@@ -44,7 +45,14 @@ template inspec_path do
44
45
  end
45
46
 
46
47
  # Recipe
47
- template recipe_path do
48
- source 'recipe.rb.erb'
49
- helpers(ChefCLI::Generator::TemplateHelper)
48
+ if context.yaml
49
+ template recipe_path_yml do
50
+ source 'recipe.yml.erb'
51
+ helpers(ChefCLI::Generator::TemplateHelper)
52
+ end
53
+ else
54
+ template recipe_path do
55
+ source 'recipe.rb.erb'
56
+ helpers(ChefCLI::Generator::TemplateHelper)
57
+ end
50
58
  end
@@ -0,0 +1,36 @@
1
+ # Delivery for Local Phases Execution
2
+ #
3
+ # This file allows you to execute test phases locally on a workstation or
4
+ # in a CI pipeline. The delivery-cli will read this file and execute the
5
+ # command(s) that are configured for each phase. You can customize them
6
+ # by just modifying the phase key on this file.
7
+ #
8
+ # By default these phases are configured for Cookbook Workflow only
9
+ #
10
+
11
+ [local_phases]
12
+ <% if @specs %>
13
+ unit = "chef exec rspec spec/"
14
+ <% else %>
15
+ unit = "echo skipping unit phase."
16
+ <% end %>
17
+ lint = "chef exec cookstyle"
18
+ # foodcritic has been deprecated in favor of cookstyle so we skip the syntax
19
+ # phase now.
20
+ syntax = "echo skipping syntax phase. Use lint phase instead."
21
+ provision = "chef exec kitchen create"
22
+ deploy = "chef exec kitchen converge"
23
+ smoke = "chef exec kitchen verify"
24
+ # The functional phase is optional, you can define it by uncommenting
25
+ # the line below and running the command: `delivery local functional`
26
+ # functional = ""
27
+ cleanup = "chef exec kitchen destroy"
28
+
29
+ # Remote project.toml file
30
+ #
31
+ # Instead of the local phases above, you may specify a remote URI location for
32
+ # the `project.toml` file. This is useful for teams that wish to centrally
33
+ # manage the behavior of the `delivery local` command across many different
34
+ # projects.
35
+ #
36
+ # remote_file = "https://url/project.toml"
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  driver:
3
3
  name: dokken
4
+ privileged: true # allows systemd services to start
4
5
 
5
6
  provisioner:
6
7
  name: dokken
@@ -0,0 +1,18 @@
1
+ #
2
+ # Cookbook:: <%= cookbook_name %>
3
+ # Recipe:: <%= recipe_name %>
4
+ #
5
+ <%= license_description('#') %>
6
+
7
+ ---
8
+ resources:
9
+ # Example Syntax
10
+ # Additional snippets are available using the Chef Infra Extension for Visual Studio Code
11
+ # - type: file
12
+ # name: '/path/to/file'
13
+ # content: 'content'
14
+ # owner: 'root'
15
+ # group: 'root'
16
+ # mode: '0755'
17
+ # action:
18
+ # - create