@@ -72,29 +72,38 @@ You will need to include this in your Rakefile located in each recipe directory.
7272this will be a full test, but there are options to use only a smaller set of tests if you
7373choose.
7474
75- ### Full cookbook testing (usually what you want as this is the gate to production )
75+ ### Everything (usually what you want)
7676
7777For an individual cookbook repository, include a Rakefile with the following contents:
7878
7979``` ruby
80+ require ' rordan_gramsay/chef_tasks/dependencies'
8081require ' rordan_gramsay/chef_tasks/lint'
8182require ' rordan_gramsay/chef_tasks/kitchen'
8283require ' rordan_gramsay/chef_tasks/test'
8384
84- task default: [' test :all' ]
85+ task default: [' lint :all' ]
8586```
8687
87- This will provide the following testing options from the command line:
88+ This will provide the following testing and dependency management options from the command line:
8889
8990```
9091$ rake -T
9192
92- rake kitchen # Runs integration tests using Test Kitchen
93- rake lint # Lints cookbook using all tools
94- rake test # Runs all linting and integration tests
93+ rake dependency:check # Check if version pinning is done correctly
94+ rake dependency:clean # Remove pinned dependencies from metadata.rb
95+ rake dependency:migrate # [EXPERIMENTAL] Migrate cookbook dependencies from metadata.rb to Berksfile (for use with dependency:pin task)
96+ rake dependency:pin # Pin dependencies
97+ rake dependency:update # Update dependency graph
98+ rake kitchen # Runs integration tests using Test Kitchen
99+ rake lint # Lints cookbook using all tools
100+ rake test # Runs all linting and integration tests
95101```
96102
97- For a monolithic repo style of cookbook tracking, see the ** Recursive testing** section below.
103+ Rather than copy-paste, if you have this gem installed you may also run ` gramsay init ` in the base
104+ of the cookbook project directory and it will lay down a Rakefile with those contents for you.
105+
106+ ### Cookbook testing
98107
99108### Lint testing only
100109
@@ -114,29 +123,41 @@ $ rake -T
114123 rake lint # Lints cookbook using all tools
115124```
116125
117- ### Recursive testing
126+ ### Dependency management
127+
128+ Long story short, Berkshelf has a much richer ecosystem for handling cookbook dependencies with more
129+ nuance than the built-in Chef dependency resolver. To facilitate deterministic builds with a wrapper-cookbook
130+ approach, we have a set of rake tasks to handle pinning to exact versions of all dependencies.
118131
119- For a monolithic repository situation, where multiple cookbooks are stored in the
120- ` cookbooks/ ` directory relative to the project root, there is a set of rake tasks to
121- handle this mass testing. Add the following to a Rakefile in the monolithic repo root
122- directory:
132+ Pinning a dependency A that depends on B which, in turn, depends on C makes it so that you only need to
133+ declare the dependency on A to have the metadata reflect the resolved versions of A, B, and C in the
134+ ` metadata.rb ` . This way we can resolve the dependency graph ahead of time and leave the executing of those
135+ cookbooks to ` chef-client ` at runtime.
136+
137+ Cookbooks that have their name starting with ` role_ ` or ` wrapper_ ` will be treated as a wrapper cookbook
138+ and be subject to these deterministic builds (e.g., ` depends 'cats', '= 1.2.3' ` ). All other cookbooks will
139+ be treated like library cookbooks and have the pessimistic version constraint operator (` ~> ` ). This ensures
140+ their dependencies always remain in the same major version, so ` depends 'cats', '~> 3.0' ` ensures a cookbook
141+ matching both ` >= 3.0.0 ` and ` < 4.0.0 ` .
123142
124143``` ruby
125- require ' rordan_gramsay/chef_tasks/master_repo'
144+ require ' rordan_gramsay/chef_tasks/dependencies'
145+
146+ task default: [' dependency:check' ]
126147```
127148
128149This will provide the following testing options from the command line:
129150
130151```
131152$ rake -T
132153
133- rake lint # Runs linting, style checks, and overall formatting checks for each cookbook
134- rake test # Runs all linting and tests on all cookbooks
154+ rake dependency:check # Check if version pinning is done correctly
155+ rake dependency:clean # Remove pinned dependencies from metadata.rb
156+ rake dependency:migrate # [EXPERIMENTAL] Migrate cookbook dependencies from metadata.rb to Berksfile (for use with dependency:pin task)
157+ rake dependency:pin # Pin dependencies
158+ rake dependency:update # Update dependency graph
135159```
136160
137- In order to make use of this, each cookbook repo must also implement the tasks defined
138- in the cookbook Rakefiles.
139-
140161## Contributing
141162
142163See [ CONTRIBUTING.md] ( /CONTRIBUTING.md ) .
0 commit comments