Skip to content

Commit e4c86b5

Browse files
committed
Add generated delivery build cookbook
1 parent 5670052 commit e4c86b5

21 files changed

+367
-0
lines changed

.delivery/build_cookbook/.kitchen.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
driver:
3+
name: vagrant
4+
synced_folders:
5+
- [<%= File.join(ENV['PWD'], '..', '..')%>, '/tmp/repo-data']
6+
7+
provisioner:
8+
name: chef_zero
9+
encrypted_data_bag_secret_key_path: 'secrets/fakey-mcfakerton'
10+
data_bags_path: './data_bags'
11+
product_name: chefdk
12+
13+
platforms:
14+
- name: ubuntu-16.04
15+
- name: centos-7
16+
17+
suites:
18+
- name: default
19+
run_list:
20+
- recipe[test]
21+
attributes:

.delivery/build_cookbook/Berksfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://supermarket.chef.io'
2+
3+
metadata
4+
5+
group :delivery do
6+
cookbook 'test', path: './test/fixtures/cookbooks/test'
7+
end

.delivery/build_cookbook/LICENSE

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Copyright 2020 The Authors
2+
3+
All rights reserved, do not redistribute.

.delivery/build_cookbook/README.md

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# build_cookbook
2+
3+
A build cookbook for running the parent project through Chef Delivery
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 Delivery, 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 Delivery 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 Delivery "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 Delivery. 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 Delivery 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 Delivery. 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 16.04' do
51+
let(:chef_run) do
52+
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.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 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 awhile 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 Client finished, 3/32 resources updated in 54.665445968 seconds
118+
Finished converging <default-centos-71> (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 Delivery 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 foodcritic/rubocop 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 Delivery. We strongly encourage this approach before actually pushing the changes to Delivery.
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 Delivery with `delivery review --edit`. The latter won't modify the git commits, only the changeset in Delivery.
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.

.delivery/build_cookbook/chefignore

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Put files/directories that should be ignored in this file when uploading
2+
# to a chef-server or supermarket.
3+
# Lines that start with '# ' are comments.
4+
5+
# OS generated files #
6+
######################
7+
.DS_Store
8+
Icon?
9+
nohup.out
10+
ehthumbs.db
11+
Thumbs.db
12+
13+
# SASS #
14+
########
15+
.sass-cache
16+
17+
# EDITORS #
18+
###########
19+
\#*
20+
.#*
21+
*~
22+
*.sw[a-z]
23+
*.bak
24+
REVISION
25+
TAGS*
26+
tmtags
27+
*_flymake.*
28+
*_flymake
29+
*.tmproj
30+
.project
31+
.settings
32+
mkmf.log
33+
34+
## COMPILED ##
35+
##############
36+
a.out
37+
*.o
38+
*.pyc
39+
*.so
40+
*.com
41+
*.class
42+
*.dll
43+
*.exe
44+
*/rdoc/
45+
46+
# Testing #
47+
###########
48+
.watchr
49+
.rspec
50+
spec/*
51+
spec/fixtures/*
52+
test/*
53+
features/*
54+
examples/*
55+
Guardfile
56+
Procfile
57+
.kitchen*
58+
kitchen.yml*
59+
.rubocop.yml
60+
spec/*
61+
Rakefile
62+
.travis.yml
63+
.foodcritic
64+
.codeclimate.yml
65+
66+
# SCM #
67+
#######
68+
.git
69+
*/.git
70+
.gitignore
71+
.gitmodules
72+
.gitconfig
73+
.gitattributes
74+
.svn
75+
*/.bzr/*
76+
*/.hg/*
77+
*/.svn/*
78+
79+
# Berkshelf #
80+
#############
81+
Berksfile
82+
Berksfile.lock
83+
cookbooks/*
84+
tmp
85+
86+
# Bundler #
87+
###########
88+
vendor/*
89+
90+
# Policyfile #
91+
##############
92+
Policyfile.rb
93+
Policyfile.lock.json
94+
95+
# Cookbooks #
96+
#############
97+
CONTRIBUTING*
98+
CHANGELOG*
99+
TESTING*
100+
101+
# Vagrant #
102+
###########
103+
.vagrant
104+
Vagrantfile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id": "delivery_builder_keys"}

.delivery/build_cookbook/metadata.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name 'build_cookbook'
2+
maintainer 'The Authors'
3+
maintainer_email '[email protected]'
4+
license 'all_rights'
5+
version '0.1.0'
6+
chef_version '>= 13.0'
7+
8+
depends 'delivery-truck'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: default
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::default'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: deploy
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::deploy'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: functional
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::functional'
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: lint
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::lint'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: provision
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::provision'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: publish
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::publish'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: quality
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::quality'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: security
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::security'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: smoke
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::smoke'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: syntax
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::syntax'
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Cookbook:: build_cookbook
3+
# Recipe:: unit
4+
#
5+
# Copyright:: 2020, The Authors, All Rights Reserved.
6+
include_recipe 'delivery-truck::unit'

.delivery/build_cookbook/secrets/fakey-mcfakerton

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name 'test'
2+
version '0.1.0'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
%w(unit lint syntax).each do |phase|
3+
# TODO: This works on Linux/Unix. Not Windows.
4+
execute "HOME=/home/vagrant delivery job verify #{phase} --server localhost --ent test --org kitchen" do
5+
cwd '/tmp/repo-data'
6+
user 'vagrant'
7+
environment('GIT_DISCOVERY_ACROSS_FILESYSTEM' => '1')
8+
end
9+
end

0 commit comments

Comments
 (0)