From 456608d3d2a5ba206bc23a4b935556a7df0b394b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 17 Sep 2020 14:26:42 -0700 Subject: [PATCH] Replace the full Delivery experience with delivery local mode Delivery local mode is a simple toml file that defines bits of work to do in test Signed-off-by: Tim Smith --- .delivery/build_cookbook/.kitchen.yml | 21 --- .delivery/build_cookbook/Berksfile | 9 -- .delivery/build_cookbook/LICENSE | 3 - .delivery/build_cookbook/README.md | 146 ------------------ .delivery/build_cookbook/chefignore | 107 ------------- .../data_bags/keys/delivery_builder_keys.json | 1 - .delivery/build_cookbook/metadata.rb | 7 - .delivery/build_cookbook/recipes/default.rb | 6 - .delivery/build_cookbook/recipes/deploy.rb | 6 - .../build_cookbook/recipes/functional.rb | 6 - .delivery/build_cookbook/recipes/lint.rb | 6 - .delivery/build_cookbook/recipes/provision.rb | 6 - .delivery/build_cookbook/recipes/publish.rb | 6 - .delivery/build_cookbook/recipes/quality.rb | 6 - .delivery/build_cookbook/recipes/security.rb | 6 - .delivery/build_cookbook/recipes/smoke.rb | 6 - .delivery/build_cookbook/recipes/syntax.rb | 6 - .delivery/build_cookbook/recipes/unit.rb | 6 - .../build_cookbook/secrets/fakey-mcfakerton | 0 .../test/fixtures/cookbooks/test/metadata.rb | 2 - .../cookbooks/test/recipes/default.rb | 7 - .delivery/config.json | 12 -- .delivery/project.toml | 26 +--- 23 files changed, 1 insertion(+), 406 deletions(-) delete mode 100644 .delivery/build_cookbook/.kitchen.yml delete mode 100644 .delivery/build_cookbook/Berksfile delete mode 100644 .delivery/build_cookbook/LICENSE delete mode 100644 .delivery/build_cookbook/README.md delete mode 100644 .delivery/build_cookbook/chefignore delete mode 100644 .delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json delete mode 100644 .delivery/build_cookbook/metadata.rb delete mode 100644 .delivery/build_cookbook/recipes/default.rb delete mode 100644 .delivery/build_cookbook/recipes/deploy.rb delete mode 100644 .delivery/build_cookbook/recipes/functional.rb delete mode 100644 .delivery/build_cookbook/recipes/lint.rb delete mode 100644 .delivery/build_cookbook/recipes/provision.rb delete mode 100644 .delivery/build_cookbook/recipes/publish.rb delete mode 100644 .delivery/build_cookbook/recipes/quality.rb delete mode 100644 .delivery/build_cookbook/recipes/security.rb delete mode 100644 .delivery/build_cookbook/recipes/smoke.rb delete mode 100644 .delivery/build_cookbook/recipes/syntax.rb delete mode 100644 .delivery/build_cookbook/recipes/unit.rb delete mode 100644 .delivery/build_cookbook/secrets/fakey-mcfakerton delete mode 100644 .delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb delete mode 100644 .delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb delete mode 100644 .delivery/config.json diff --git a/.delivery/build_cookbook/.kitchen.yml b/.delivery/build_cookbook/.kitchen.yml deleted file mode 100644 index 2d3fce6..0000000 --- a/.delivery/build_cookbook/.kitchen.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -driver: - name: vagrant - synced_folders: - - [<%= File.join(ENV['PWD'], '..', '..')%>, '/tmp/repo-data'] - -provisioner: - name: chef_zero - encrypted_data_bag_secret_key_path: 'secrets/fakey-mcfakerton' - data_bags_path: './data_bags' - -platforms: - - name: ubuntu-16.04 - - name: centos-7.2 - -suites: - - name: default - run_list: - - recipe[delivery_build::default] - - recipe[test] - attributes: diff --git a/.delivery/build_cookbook/Berksfile b/.delivery/build_cookbook/Berksfile deleted file mode 100644 index fe9c94f..0000000 --- a/.delivery/build_cookbook/Berksfile +++ /dev/null @@ -1,9 +0,0 @@ -source 'https://supermarket.chef.io' - -metadata - -group :delivery do - cookbook 'delivery_build', git: 'https://github.com/chef-cookbooks/delivery_build' - cookbook 'delivery-base', git: 'https://github.com/chef-cookbooks/delivery-base' - cookbook 'test', path: './test/fixtures/cookbooks/test' -end diff --git a/.delivery/build_cookbook/LICENSE b/.delivery/build_cookbook/LICENSE deleted file mode 100644 index d31c097..0000000 --- a/.delivery/build_cookbook/LICENSE +++ /dev/null @@ -1,3 +0,0 @@ -Copyright 2017 The Authors - -All rights reserved, do not redistribute. diff --git a/.delivery/build_cookbook/README.md b/.delivery/build_cookbook/README.md deleted file mode 100644 index 1ecf0b7..0000000 --- a/.delivery/build_cookbook/README.md +++ /dev/null @@ -1,146 +0,0 @@ -# build_cookbook - -A build cookbook for running the parent project through Chef Delivery - -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. - -## .delivery/config.json - -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. - -## Test Kitchen - Local Verify Testing - -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. - -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: - -``` -kitchen test -``` - -## Recipes - -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. - -## Making Changes - Cookbook Example - -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. - -First, create a new branch for the changes. - -``` -git checkout -b testing-build-cookbook -``` - -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. - -``` -% git diff - --version '0.1.0' -+version '0.1.1' -``` - -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`. - -```ruby -require 'spec_helper' - -describe 'godzilla::default' do - context 'When all attributes are default, on an unspecified platform' do - let(:chef_run) do - runner = ChefSpec::ServerRunner.new - runner.converge(described_recipe) - end - - it 'installs zsh' do - expect(chef_run).to install_package('zsh') - end - end -end -``` - -Commit the local changes as work in progress. The `delivery job` expects to use a clean git repository. - -``` -git add ../.. -git commit -m 'WIP: Testing changes' -``` - -From _this_ directory (`.delivery/build_cookbook`, relative to the parent cookbook project), run - -``` -cd .delivery/build_cookbook -kitchen converge -``` - -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`. - -``` -cd ../../ -$EDITOR/recipes/default.rb -``` - -It should look like this: - -``` -package 'zsh' -``` - -Create another commit. - -``` -git add . -git commit -m 'WIP: Install zsh in default recipe' -``` - -Now rerun kitchen from the build_cookbook. - -``` -cd .delivery/build_cookbook -kitchen converge -``` - -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. - -``` -Recipe: test::default - -- execute HOME=/home/vagrant delivery job verify unit --server localhost --ent test --org kitchen - * execute[HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen] action run - - execute HOME=/home/vagrant delivery job verify lint --server localhost --ent test --org kitchen - - - execute HOME=/home/vagrant delivery job verify syntax --server localhost --ent test --org kitchen - -Running handlers: -Running handlers complete -Chef Client finished, 3/32 resources updated in 54.665445968 seconds -Finished converging (1m26.83s). -``` - -Victory is ours! Our verify phase passed on the build nodes. - -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. - -``` -cd ../.. -delivery review -``` - -## FAQ - -### Why don't I just run rspec and foodcritic/rubocop on my local system? - -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. - -### Why do I have to make a commit every time? - -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. - -### What do I do next? - -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. - -### What if I get stuck? - -Contact Chef Support, or your Chef Customer Success team and they will help you get unstuck. diff --git a/.delivery/build_cookbook/chefignore b/.delivery/build_cookbook/chefignore deleted file mode 100644 index 38e7379..0000000 --- a/.delivery/build_cookbook/chefignore +++ /dev/null @@ -1,107 +0,0 @@ -# Put files/directories that should be ignored in this file when uploading -# to a chef-server or supermarket. -# Lines that start with '# ' are comments. - -# OS generated files # -###################### -.DS_Store -Icon? -nohup.out -ehthumbs.db -Thumbs.db - -# SASS # -######## -.sass-cache - -# EDITORS # -########### -\#* -.#* -*~ -*.sw[a-z] -*.bak -REVISION -TAGS* -tmtags -*_flymake.* -*_flymake -*.tmproj -.project -.settings -mkmf.log - -## COMPILED ## -############## -a.out -*.o -*.pyc -*.so -*.com -*.class -*.dll -*.exe -*/rdoc/ - -# Testing # -########### -.watchr -.rspec -spec/* -spec/fixtures/* -test/* -features/* -examples/* -Guardfile -Procfile -.kitchen* -.rubocop.yml -spec/* -Rakefile -.travis.yml -.foodcritic -.codeclimate.yml - -# SCM # -####### -.git -*/.git -.gitignore -.gitmodules -.gitconfig -.gitattributes -.svn -*/.bzr/* -*/.hg/* -*/.svn/* - -# Berkshelf # -############# -Berksfile -Berksfile.lock -cookbooks/* -tmp - -# Policyfile # -############## -Policyfile.rb -Policyfile.lock.json - -# Cookbooks # -############# -CONTRIBUTING* -CHANGELOG* -TESTING* -MAINTAINERS.toml - -# Strainer # -############ -Colanderfile -Strainerfile -.colander -.strainer - -# Vagrant # -########### -.vagrant -Vagrantfile diff --git a/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json b/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json deleted file mode 100644 index af375ea..0000000 --- a/.delivery/build_cookbook/data_bags/keys/delivery_builder_keys.json +++ /dev/null @@ -1 +0,0 @@ -{"id": "delivery_builder_keys"} \ No newline at end of file diff --git a/.delivery/build_cookbook/metadata.rb b/.delivery/build_cookbook/metadata.rb deleted file mode 100644 index 10330e7..0000000 --- a/.delivery/build_cookbook/metadata.rb +++ /dev/null @@ -1,7 +0,0 @@ -name 'build_cookbook' -maintainer 'The Authors' -maintainer_email 'you@example.com' -license 'all_rights' -version '0.1.0' - -depends 'delivery-truck' diff --git a/.delivery/build_cookbook/recipes/default.rb b/.delivery/build_cookbook/recipes/default.rb deleted file mode 100644 index b2746b5..0000000 --- a/.delivery/build_cookbook/recipes/default.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: default -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::default' diff --git a/.delivery/build_cookbook/recipes/deploy.rb b/.delivery/build_cookbook/recipes/deploy.rb deleted file mode 100644 index 9a61010..0000000 --- a/.delivery/build_cookbook/recipes/deploy.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: deploy -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::deploy' diff --git a/.delivery/build_cookbook/recipes/functional.rb b/.delivery/build_cookbook/recipes/functional.rb deleted file mode 100644 index cae646d..0000000 --- a/.delivery/build_cookbook/recipes/functional.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: functional -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::functional' diff --git a/.delivery/build_cookbook/recipes/lint.rb b/.delivery/build_cookbook/recipes/lint.rb deleted file mode 100644 index 40aee0c..0000000 --- a/.delivery/build_cookbook/recipes/lint.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: lint -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::lint' diff --git a/.delivery/build_cookbook/recipes/provision.rb b/.delivery/build_cookbook/recipes/provision.rb deleted file mode 100644 index 57d0a78..0000000 --- a/.delivery/build_cookbook/recipes/provision.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: provision -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::provision' diff --git a/.delivery/build_cookbook/recipes/publish.rb b/.delivery/build_cookbook/recipes/publish.rb deleted file mode 100644 index ad890fd..0000000 --- a/.delivery/build_cookbook/recipes/publish.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: publish -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::publish' diff --git a/.delivery/build_cookbook/recipes/quality.rb b/.delivery/build_cookbook/recipes/quality.rb deleted file mode 100644 index f5d4d74..0000000 --- a/.delivery/build_cookbook/recipes/quality.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: quality -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::quality' diff --git a/.delivery/build_cookbook/recipes/security.rb b/.delivery/build_cookbook/recipes/security.rb deleted file mode 100644 index 7d47af1..0000000 --- a/.delivery/build_cookbook/recipes/security.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: security -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::security' diff --git a/.delivery/build_cookbook/recipes/smoke.rb b/.delivery/build_cookbook/recipes/smoke.rb deleted file mode 100644 index 2203cbd..0000000 --- a/.delivery/build_cookbook/recipes/smoke.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: smoke -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::smoke' diff --git a/.delivery/build_cookbook/recipes/syntax.rb b/.delivery/build_cookbook/recipes/syntax.rb deleted file mode 100644 index 7147f96..0000000 --- a/.delivery/build_cookbook/recipes/syntax.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: syntax -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::syntax' diff --git a/.delivery/build_cookbook/recipes/unit.rb b/.delivery/build_cookbook/recipes/unit.rb deleted file mode 100644 index fa6d9ba..0000000 --- a/.delivery/build_cookbook/recipes/unit.rb +++ /dev/null @@ -1,6 +0,0 @@ -# -# Cookbook:: build_cookbook -# Recipe:: unit -# -# Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'delivery-truck::unit' diff --git a/.delivery/build_cookbook/secrets/fakey-mcfakerton b/.delivery/build_cookbook/secrets/fakey-mcfakerton deleted file mode 100644 index e69de29..0000000 diff --git a/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb b/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb deleted file mode 100644 index 1725039..0000000 --- a/.delivery/build_cookbook/test/fixtures/cookbooks/test/metadata.rb +++ /dev/null @@ -1,2 +0,0 @@ -name 'test' -version '0.1.0' \ No newline at end of file diff --git a/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb b/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb deleted file mode 100644 index c26a70a..0000000 --- a/.delivery/build_cookbook/test/fixtures/cookbooks/test/recipes/default.rb +++ /dev/null @@ -1,7 +0,0 @@ -%w(unit lint syntax).each do |phase| - # TODO: This works on Linux/Unix. Not Windows. - execute "HOME=/home/vagrant delivery job verify #{phase} --server localhost --ent test --org kitchen" do - cwd '/tmp/repo-data' - user 'vagrant' - end -end diff --git a/.delivery/config.json b/.delivery/config.json deleted file mode 100644 index 6c0e69f..0000000 --- a/.delivery/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "2", - "build_cookbook": { - "name": "build_cookbook", - "path": ".delivery/build_cookbook" - }, - "skip_phases": [], - "job_dispatch": { - "version": "v2" - }, - "dependencies": [] -} diff --git a/.delivery/project.toml b/.delivery/project.toml index ac93ca8..6d5e361 100644 --- a/.delivery/project.toml +++ b/.delivery/project.toml @@ -1,25 +1 @@ -# Delivery Prototype for Local Phases Execution -# -# The purpose of this file is to prototype a new way to execute -# phases locally on your workstation. The delivery-cli will read -# this file and execute the command(s) that are configured for -# each phase. You can customize them by just modifying the phase -# key on this file. -# -# By default these phases are configured for Cookbook Workflow only -# -# As this is still a prototype we are not modifying the current -# config.json file and it will continue working as usual. - -[local_phases] -unit = "rspec spec/" -lint = "cookstyle" -# Foodcritic includes rules only appropriate for community cookbooks -# uploaded to Supermarket. We turn off any rules tagged "supermarket" -# by default. If you plan to share this cookbook you should remove -# '-t ~supermarket' below to enable supermarket rules. -syntax = "foodcritic . --exclude spec -f any -t ~supermarket" -provision = "chef exec kitchen create" -deploy = "chef exec kitchen converge" -smoke = "chef exec kitchen verify" -cleanup = "chef exec kitchen destroy" +remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml"