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.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/chef-cli.gemspec +1 -1
- data/lib/chef-cli/command/generate.rb +5 -3
- data/lib/chef-cli/command/generator_commands/cookbook.rb +32 -2
- data/lib/chef-cli/command/generator_commands/recipe.rb +7 -0
- data/lib/chef-cli/completions/chef.fish.erb +4 -5
- data/lib/chef-cli/helpers.rb +10 -7
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +50 -24
- data/lib/chef-cli/skeletons/code_generator/recipes/recipe.rb +11 -3
- data/lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb +36 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +1 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/recipe.yml.erb +18 -0
- data/lib/chef-cli/version.rb +1 -1
- data/spec/unit/command/generate_spec.rb +7 -0
- data/spec/unit/command/generator_commands/cookbook_spec.rb +91 -226
- data/spec/unit/command/generator_commands/recipe_spec.rb +34 -0
- data/spec/unit/command/shell_init_spec.rb +10 -10
- data/spec/unit/helpers_spec.rb +111 -0
- metadata +7 -14
- data/lib/chef-cli/command/generator_commands/build_cookbook.rb +0 -126
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +0 -146
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +0 -21
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +0 -8
- data/lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json +0 -17
- data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +0 -175
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +0 -7
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +0 -10
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +0 -9
- data/spec/unit/command/generator_commands/build_cookbook_spec.rb +0 -377
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "spec_helper"
|
18
|
+
require "chef-cli/helpers"
|
19
|
+
|
20
|
+
describe ChefCLI::Helpers do
|
21
|
+
context "path_check!" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(Gem).to receive(:ruby).and_return(ruby_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when installed via omnibus" do
|
28
|
+
before do
|
29
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return true
|
30
|
+
end
|
31
|
+
|
32
|
+
context "on unix" do
|
33
|
+
|
34
|
+
let(:user_bin_dir) { File.expand_path(File.join(Gem.user_dir, "bin")) }
|
35
|
+
let(:omnibus_embedded_bin_dir) { "/opt/chef-workstation/embedded/bin" }
|
36
|
+
let(:omnibus_bin_dir) { "/opt/chef-workstation/bin" }
|
37
|
+
let(:expected_PATH) { [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] }
|
38
|
+
let(:expected_GEM_ROOT) { Gem.default_dir }
|
39
|
+
let(:expected_GEM_HOME) { Gem.user_dir }
|
40
|
+
let(:expected_GEM_PATH) { Gem.path.join(File::PATH_SEPARATOR) }
|
41
|
+
let(:ruby_path) { "/opt/chef-workstation/embedded/bin/ruby" }
|
42
|
+
|
43
|
+
it "#omnibus_env path" do
|
44
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_bin_dir).and_return("/opt/chef-workstation/bin")
|
45
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_embedded_bin_dir).and_return("/opt/chef-workstation/embedded/bin")
|
46
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_env).and_return(
|
47
|
+
"PATH" => expected_PATH.flatten.uniq.join(File::PATH_SEPARATOR),
|
48
|
+
"GEM_ROOT" => expected_GEM_ROOT,
|
49
|
+
"GEM_HOME" => expected_GEM_HOME,
|
50
|
+
"GEM_PATH" => expected_GEM_PATH
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "on windows" do
|
56
|
+
let(:ruby_path) { "c:/opscode/chef-workstation/embedded/bin/ruby.exe" }
|
57
|
+
let(:user_bin_dir) { File.expand_path(File.join(Gem.user_dir, "bin")) }
|
58
|
+
let(:omnibus_embedded_bin_dir) { "c:/opscode/chef-workstation/embedded/bin" }
|
59
|
+
let(:omnibus_bin_dir) { "c:/opscode/chef-workstation/bin" }
|
60
|
+
let(:expected_GEM_ROOT) { Gem.default_dir }
|
61
|
+
let(:expected_GEM_HOME) { Gem.user_dir }
|
62
|
+
let(:expected_GEM_PATH) { Gem.path.join(File::PATH_SEPARATOR) }
|
63
|
+
let(:omnibus_root) { "c:/opscode/chef-workstation" }
|
64
|
+
let(:expected_PATH) { [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] }
|
65
|
+
|
66
|
+
before do
|
67
|
+
allow(ChefCLI::Helpers).to receive(:expected_omnibus_root).and_return(ruby_path)
|
68
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return(true)
|
69
|
+
allow(Chef::Platform).to receive(:windows?).and_return(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "#omnibus_env path" do
|
73
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_bin_dir).and_return("c:/opscode/chef-workstation/bin")
|
74
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_embedded_bin_dir).and_return("c:/opscode/chef-workstation/embedded/bin")
|
75
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_env).and_return(
|
76
|
+
"PATH" => expected_PATH.flatten.uniq.join(File::PATH_SEPARATOR),
|
77
|
+
"GEM_ROOT" => expected_GEM_ROOT,
|
78
|
+
"GEM_HOME" => expected_GEM_HOME,
|
79
|
+
"GEM_PATH" => expected_GEM_PATH
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when not installed via omnibus" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return false
|
89
|
+
end
|
90
|
+
let(:ruby_path) { "/Users/bog/.lots_o_rubies/2.1.2/bin/ruby" }
|
91
|
+
let(:expected_root_path) { "/Users/bog/.lots_o_rubies" }
|
92
|
+
|
93
|
+
before do
|
94
|
+
allow(File).to receive(:exist?).with(expected_root_path).and_return(false)
|
95
|
+
|
96
|
+
%i{
|
97
|
+
omnibus_root
|
98
|
+
omnibus_bin_dir
|
99
|
+
omnibus_embedded_bin_dir
|
100
|
+
}.each do |method_name|
|
101
|
+
allow(ChefCLI::Helpers).to receive(method_name).and_raise(ChefCLI::OmnibusInstallNotFound.new)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "skips the sanity check without error" do
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-cli
|
@@ -240,7 +240,6 @@ files:
|
|
240
240
|
- lib/chef-cli/command/generator_commands.rb
|
241
241
|
- lib/chef-cli/command/generator_commands/attribute.rb
|
242
242
|
- lib/chef-cli/command/generator_commands/base.rb
|
243
|
-
- lib/chef-cli/command/generator_commands/build_cookbook.rb
|
244
243
|
- lib/chef-cli/command/generator_commands/chef_exts/generator_desc_resource.rb
|
245
244
|
- lib/chef-cli/command/generator_commands/chef_exts/quieter_doc_formatter.rb
|
246
245
|
- lib/chef-cli/command/generator_commands/chef_exts/recipe_dsl_ext.rb
|
@@ -328,13 +327,9 @@ files:
|
|
328
327
|
- lib/chef-cli/service_exceptions.rb
|
329
328
|
- lib/chef-cli/shell_out.rb
|
330
329
|
- lib/chef-cli/skeletons/code_generator/files/default/Berksfile
|
331
|
-
- lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md
|
332
|
-
- lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml
|
333
|
-
- lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb
|
334
330
|
- lib/chef-cli/skeletons/code_generator/files/default/chefignore
|
335
331
|
- lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md
|
336
332
|
- lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README.md
|
337
|
-
- lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json
|
338
333
|
- lib/chef-cli/skeletons/code_generator/files/default/delivery-project.toml
|
339
334
|
- lib/chef-cli/skeletons/code_generator/files/default/gitignore
|
340
335
|
- lib/chef-cli/skeletons/code_generator/files/default/repo/README.md
|
@@ -354,7 +349,6 @@ files:
|
|
354
349
|
- lib/chef-cli/skeletons/code_generator/files/default/spec_helper_policyfile.rb
|
355
350
|
- lib/chef-cli/skeletons/code_generator/metadata.rb
|
356
351
|
- lib/chef-cli/skeletons/code_generator/recipes/attribute.rb
|
357
|
-
- lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb
|
358
352
|
- lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb
|
359
353
|
- lib/chef-cli/skeletons/code_generator/recipes/cookbook_file.rb
|
360
354
|
- lib/chef-cli/skeletons/code_generator/recipes/helpers.rb
|
@@ -372,10 +366,8 @@ files:
|
|
372
366
|
- lib/chef-cli/skeletons/code_generator/templates/default/Policyfile.rb.erb
|
373
367
|
- lib/chef-cli/skeletons/code_generator/templates/default/README.md.erb
|
374
368
|
- lib/chef-cli/skeletons/code_generator/templates/default/attribute.rb.erb
|
375
|
-
- lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb
|
376
|
-
- lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb
|
377
|
-
- lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb
|
378
369
|
- lib/chef-cli/skeletons/code_generator/templates/default/cookbook_file.erb
|
370
|
+
- lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb
|
379
371
|
- lib/chef-cli/skeletons/code_generator/templates/default/helpers.rb.erb
|
380
372
|
- lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb
|
381
373
|
- lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb
|
@@ -383,6 +375,7 @@ files:
|
|
383
375
|
- lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb
|
384
376
|
- lib/chef-cli/skeletons/code_generator/templates/default/metadata.rb.erb
|
385
377
|
- lib/chef-cli/skeletons/code_generator/templates/default/recipe.rb.erb
|
378
|
+
- lib/chef-cli/skeletons/code_generator/templates/default/recipe.yml.erb
|
386
379
|
- lib/chef-cli/skeletons/code_generator/templates/default/recipe_spec.rb.erb
|
387
380
|
- lib/chef-cli/skeletons/code_generator/templates/default/repo/gitignore.erb
|
388
381
|
- lib/chef-cli/skeletons/code_generator/templates/default/resource.rb.erb
|
@@ -415,7 +408,6 @@ files:
|
|
415
408
|
- spec/unit/command/generate_spec.rb
|
416
409
|
- spec/unit/command/generator_commands/attribute_spec.rb
|
417
410
|
- spec/unit/command/generator_commands/base_spec.rb
|
418
|
-
- spec/unit/command/generator_commands/build_cookbook_spec.rb
|
419
411
|
- spec/unit/command/generator_commands/chef_exts/generator_desc_resource_spec.rb
|
420
412
|
- spec/unit/command/generator_commands/chef_exts/recipe_dsl_ext_spec.rb
|
421
413
|
- spec/unit/command/generator_commands/cookbook_file_spec.rb
|
@@ -528,6 +520,7 @@ files:
|
|
528
520
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb
|
529
521
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb
|
530
522
|
- spec/unit/generator_spec.rb
|
523
|
+
- spec/unit/helpers_spec.rb
|
531
524
|
- spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb
|
532
525
|
- spec/unit/pager_spec.rb
|
533
526
|
- spec/unit/policyfile/artifactory_cookbook_source_spec.rb
|
@@ -594,7 +587,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
594
587
|
requirements:
|
595
588
|
- - ">="
|
596
589
|
- !ruby/object:Gem::Version
|
597
|
-
version: '2.
|
590
|
+
version: '2.6'
|
598
591
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
599
592
|
requirements:
|
600
593
|
- - ">="
|
@@ -630,7 +623,6 @@ test_files:
|
|
630
623
|
- spec/unit/command/generate_spec.rb
|
631
624
|
- spec/unit/command/generator_commands/attribute_spec.rb
|
632
625
|
- spec/unit/command/generator_commands/base_spec.rb
|
633
|
-
- spec/unit/command/generator_commands/build_cookbook_spec.rb
|
634
626
|
- spec/unit/command/generator_commands/chef_exts/generator_desc_resource_spec.rb
|
635
627
|
- spec/unit/command/generator_commands/chef_exts/recipe_dsl_ext_spec.rb
|
636
628
|
- spec/unit/command/generator_commands/cookbook_file_spec.rb
|
@@ -743,6 +735,7 @@ test_files:
|
|
743
735
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb
|
744
736
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb
|
745
737
|
- spec/unit/generator_spec.rb
|
738
|
+
- spec/unit/helpers_spec.rb
|
746
739
|
- spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb
|
747
740
|
- spec/unit/pager_spec.rb
|
748
741
|
- spec/unit/policyfile/artifactory_cookbook_source_spec.rb
|
@@ -1,126 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 2016-2019 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_relative "base"
|
19
|
-
require_relative "../../dist"
|
20
|
-
|
21
|
-
module ChefCLI
|
22
|
-
module Command
|
23
|
-
module GeneratorCommands
|
24
|
-
|
25
|
-
class BuildCookbook < Base
|
26
|
-
|
27
|
-
banner "Usage: #{ChefCLI::Dist::EXEC} generate build-cookbook NAME [options]"
|
28
|
-
|
29
|
-
attr_reader :errors
|
30
|
-
|
31
|
-
attr_reader :cookbook_name_or_path
|
32
|
-
|
33
|
-
option :pipeline,
|
34
|
-
long: "--pipeline PIPELINE",
|
35
|
-
description: "Use PIPELINE to set target branch to something other than master for the build_cookbook",
|
36
|
-
default: "master"
|
37
|
-
|
38
|
-
options.merge!(SharedGeneratorOptions.options)
|
39
|
-
|
40
|
-
def initialize(params)
|
41
|
-
@params_valid = true
|
42
|
-
@cookbook_name = nil
|
43
|
-
super
|
44
|
-
end
|
45
|
-
|
46
|
-
def run
|
47
|
-
read_and_validate_params
|
48
|
-
if params_valid?
|
49
|
-
setup_context
|
50
|
-
chef_runner.converge
|
51
|
-
0
|
52
|
-
else
|
53
|
-
err(opt_parser)
|
54
|
-
1
|
55
|
-
end
|
56
|
-
rescue ChefCLI::ChefRunnerError => e
|
57
|
-
err("ERROR: #{e}")
|
58
|
-
1
|
59
|
-
end
|
60
|
-
|
61
|
-
def setup_context
|
62
|
-
super
|
63
|
-
Generator.add_attr_to_context(:workflow_project_dir, workflow_project_dir)
|
64
|
-
|
65
|
-
Generator.add_attr_to_context(:workflow_project_git_initialized, workflow_project_git_initialized?)
|
66
|
-
Generator.add_attr_to_context(:build_cookbook_parent_is_cookbook, build_cookbook_parent_is_cookbook?)
|
67
|
-
|
68
|
-
Generator.add_attr_to_context(:pipeline, pipeline)
|
69
|
-
end
|
70
|
-
|
71
|
-
def pipeline
|
72
|
-
config[:pipeline]
|
73
|
-
end
|
74
|
-
|
75
|
-
def recipe
|
76
|
-
"build_cookbook"
|
77
|
-
end
|
78
|
-
|
79
|
-
def build_cookbook_parent_is_cookbook?
|
80
|
-
metadata_json_path = File.join(workflow_project_dir, "metadata.json")
|
81
|
-
metadata_rb_path = File.join(workflow_project_dir, "metadata.rb")
|
82
|
-
|
83
|
-
File.exist?(metadata_json_path) || File.exist?(metadata_rb_path)
|
84
|
-
end
|
85
|
-
|
86
|
-
def workflow_project_dir
|
87
|
-
project_dir = File.expand_path(cookbook_name_or_path, Dir.pwd)
|
88
|
-
# Detect if we were invoked with arguments like
|
89
|
-
#
|
90
|
-
# chef generate build-cookbook project/.delivery/build_cookbook
|
91
|
-
#
|
92
|
-
# If so, normalize paths so we don't make a directory structure like
|
93
|
-
# `.delivery/.delivery/build_cookbook`.
|
94
|
-
#
|
95
|
-
# Note that we don't check the name of the build cookbook the user
|
96
|
-
# asked for and we hard-code to naming it "build_cookbook". We also
|
97
|
-
# don't catch the case that the user requested something like
|
98
|
-
# `project/.delivery/build_cookbook/extra-thing-that-shouldn't-be-here`
|
99
|
-
Pathname.new(project_dir).ascend do |dir|
|
100
|
-
if File.basename(dir) == ".delivery"
|
101
|
-
project_dir = File.dirname(dir)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
project_dir
|
105
|
-
end
|
106
|
-
|
107
|
-
def workflow_project_git_initialized?
|
108
|
-
File.exist?(File.join(workflow_project_dir, ".git"))
|
109
|
-
end
|
110
|
-
|
111
|
-
def read_and_validate_params
|
112
|
-
arguments = parse_options(params)
|
113
|
-
@cookbook_name_or_path = arguments[0]
|
114
|
-
unless @cookbook_name_or_path
|
115
|
-
@params_valid = false
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def params_valid?
|
120
|
-
@params_valid
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
# build_cookbook
|
2
|
-
|
3
|
-
A build cookbook for running the parent project through Chef Workflow
|
4
|
-
|
5
|
-
This build cookbook should be customized to suit the needs of the parent project. Using this cookbook can be done outside of Chef Workflow, too. If the parent project is a Chef cookbook, we've detected that and "wrapped" [delivery-truck](https://github.com/chef-cookbooks/delivery-truck). That means it is a dependency, and each of its pipeline phase recipes is included in the appropriate phase recipes in this cookbook. If the parent project is not a cookbook, it's left as an exercise to the reader to customize the recipes as needed for each phase in the pipeline.
|
6
|
-
|
7
|
-
## .delivery/config.json
|
8
|
-
|
9
|
-
In the parent directory to this build_cookbook, the `config.json` can be modified as necessary. For example, phases can be skipped, publishing information can be added, and so on. Refer to customer support or the Chef Workflow documentation for assistance on what options are available for this configuration.
|
10
|
-
|
11
|
-
## Test Kitchen - Local Verify Testing
|
12
|
-
|
13
|
-
This cookbook also has a `kitchen.yml` which can be used to create local build nodes with Test Kitchen to perform the verification phases, `unit`, `syntax`, and `lint`. When running `kitchen converge`, the instances will be set up like Chef Workflow "build nodes" with the [delivery_build cookbook](https://github.com/chef-cookbooks/delivery_build). The reason for this is to make sure that the same exact kind of nodes are used by this build cookbook are run on the local workstation as would run Workflow. It will run `delivery job verify PHASE` for the parent project.
|
14
|
-
|
15
|
-
Modify the `kitchen.yml` if necessary to change the platforms or other configuration to run the verify phases. After making changes in the parent project, `cd` into this directory (`.delivery/build_cookbook`), and run:
|
16
|
-
|
17
|
-
```
|
18
|
-
kitchen test
|
19
|
-
```
|
20
|
-
|
21
|
-
## Recipes
|
22
|
-
|
23
|
-
Each of the recipes in this build_cookbook are run in the named phase during the Chef Workflow pipeline. The `unit`, `syntax`, and `lint` recipes are additionally run when using Test Kitchen for local testing as noted in the above section.
|
24
|
-
|
25
|
-
## Making Changes - Cookbook Example
|
26
|
-
|
27
|
-
When making changes in the parent project (that which lives in `../..` from this directory), or in the recipes in this build cookbook, there is a bespoke workflow for Chef Workflow. As an example, we'll discuss a Chef Cookbook as the parent.
|
28
|
-
|
29
|
-
First, create a new branch for the changes.
|
30
|
-
|
31
|
-
```
|
32
|
-
git checkout -b testing-build-cookbook
|
33
|
-
```
|
34
|
-
|
35
|
-
Next, increment the version in the metadata.rb. This should be in the _parent_, not in this, the build_cookbook. If this is not done, the verify phase will fail.
|
36
|
-
|
37
|
-
```
|
38
|
-
% git diff
|
39
|
-
<SNIP>
|
40
|
-
-version '0.1.0'
|
41
|
-
+version '0.1.1'
|
42
|
-
```
|
43
|
-
|
44
|
-
The change we'll use for an example is to install the `zsh` package. Write a failing ChefSpec in the cookbook project's `spec/unit/recipes/default_spec.rb`.
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
require 'spec_helper'
|
48
|
-
|
49
|
-
describe 'godzilla::default' do
|
50
|
-
context 'When all attributes are default, on Ubuntu 18.04' do
|
51
|
-
let(:chef_run) do
|
52
|
-
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04')
|
53
|
-
runner.converge(described_recipe)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'installs zsh' do
|
57
|
-
expect(chef_run).to install_package('zsh')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
Commit the local changes as work in progress. The `delivery job` expects to use a clean git repository.
|
64
|
-
|
65
|
-
```
|
66
|
-
git add ../..
|
67
|
-
git commit -m 'WIP: Testing changes'
|
68
|
-
```
|
69
|
-
|
70
|
-
From _this_ directory (`.delivery/build_cookbook`, relative to the parent cookbook project), run
|
71
|
-
|
72
|
-
```
|
73
|
-
cd .delivery/build_cookbook
|
74
|
-
kitchen converge
|
75
|
-
```
|
76
|
-
|
77
|
-
This will take some time at first, because the VMs need to be created, Chef Infra Client installed, the Delivery CLI installed, etc. Later runs will be faster until they are destroyed. It will also fail on the first VM, as expected, because we wrote the test first. Now edit the parent cookbook project's default recipe to install `zsh`.
|
78
|
-
|
79
|
-
```
|
80
|
-
cd ../../
|
81
|
-
$EDITOR/recipes/default.rb
|
82
|
-
```
|
83
|
-
|
84
|
-
It should look like this:
|
85
|
-
|
86
|
-
```
|
87
|
-
package 'zsh'
|
88
|
-
```
|
89
|
-
|
90
|
-
Create another commit.
|
91
|
-
|
92
|
-
```
|
93
|
-
git add .
|
94
|
-
git commit -m 'WIP: Install zsh in default recipe'
|
95
|
-
```
|
96
|
-
|
97
|
-
Now rerun kitchen from the build_cookbook.
|
98
|
-
|
99
|
-
```
|
100
|
-
cd .delivery/build_cookbook
|
101
|
-
kitchen converge
|
102
|
-
```
|
103
|
-
|
104
|
-
This will take a while because it will now pass on the first VM and then create the second VM. We should have warned you this was a good time for a coffee break.
|
105
|
-
|
106
|
-
```
|
107
|
-
Recipe: test::default
|
108
|
-
|
109
|
-
- execute HOME=/home/vagrant delivery job verify unit --server localhost --ent test --org kitchen
|
110
|
-
* execute[HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen] action run
|
111
|
-
- execute HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen
|
112
|
-
|
113
|
-
- execute HOME=/home/vagrant delivery job verify syntax --server localhost --ent test --org kitchen
|
114
|
-
|
115
|
-
Running handlers:
|
116
|
-
Running handlers complete
|
117
|
-
Chef Infra Client finished, 3/32 resources updated in 54.665445968 seconds
|
118
|
-
Finished converging <default-centos-8> (1m26.83s).
|
119
|
-
```
|
120
|
-
|
121
|
-
Victory is ours! Our verify phase passed on the build nodes.
|
122
|
-
|
123
|
-
We are ready to run this through our Workflow pipeline. Simply run `delivery review` on the local system from the parent project, and it will open a browser window up to the change we just added.
|
124
|
-
|
125
|
-
```
|
126
|
-
cd ../..
|
127
|
-
delivery review
|
128
|
-
```
|
129
|
-
|
130
|
-
## FAQ
|
131
|
-
|
132
|
-
### Why don't I just run rspec and cookstyle on my local system?
|
133
|
-
|
134
|
-
An objection to the Test Kitchen approach is that it is much faster to run the unit, lint, and syntax commands for the project on the local system. That is totally true, and also totally valid. Do that for the really fast feedback loop. However, the dance we do with Test Kitchen brings a much higher degree of confidence in the changes we're making, that everything will run on the build nodes in Chef Workflow. We strongly encourage this approach before actually pushing the changes to Workflow.
|
135
|
-
|
136
|
-
### Why do I have to make a commit every time?
|
137
|
-
|
138
|
-
When running `delivery job`, it expects to merge the commit for the changeset against the clean master branch. If we don't save our progress by making a commit, our local changes aren't run through `delivery job` in the Test Kitchen build instances. We can always perform an interactive rebase, and modify the original changeset message in Workflow with `delivery review --edit`. The latter won't modify the git commits, only the changeset in Workflow.
|
139
|
-
|
140
|
-
### What do I do next?
|
141
|
-
|
142
|
-
Make changes in the cookbook project as required for organizational goals and needs. Modify the `build_cookbook` as necessary for the pipeline phases that the cookbook should go through.
|
143
|
-
|
144
|
-
### What if I get stuck?
|
145
|
-
|
146
|
-
Contact Chef Support, or your Chef Customer Success team and they will help you get unstuck.
|