Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Make generate repo default to policyfiles + cleanup generated readme content #2050

Merged
merged 23 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3610bfa
Fix capitalization of InSpec in more places
tas50 May 5, 2019
c247add
Make chef generate repo XYZ use policyfiles by default now
tas50 May 5, 2019
ef56c7b
Remove string literal comments from ruby code
tas50 May 5, 2019
0bd19b0
Improve readme and help information
tas50 May 5, 2019
9df17a8
Update the gitignore for non-hidden kitchen files
tas50 May 5, 2019
f749570
Move templates out of the default directory
tas50 May 5, 2019
f0d44ac
Use the new kitchen config for specifying a Chef Version
tas50 May 5, 2019
d8f4bf5
Update link to InSpec docs
tas50 May 5, 2019
2cb8acc
Add the product_name / product_version example to both kitchen configs
tas50 May 5, 2019
fc12b36
Remove more string literal comments and fix some specs
tas50 May 7, 2019
7a1ac96
Avoid a few Foodcritic warnings in the code generator
tas50 May 7, 2019
f7773ec
Improve the cookbook creation text
tas50 May 7, 2019
f90b642
Stick the templates back in default
tas50 May 8, 2019
10bfaa8
Chef Platform -> Hosted Chef
tas50 May 9, 2019
1facef6
More Chef -> Chef Infra Client
tas50 May 9, 2019
9b5f583
Add proper space after comments to build cookbook
tas50 May 9, 2019
de03b5f
Fix comments in the gitignore file
tas50 May 9, 2019
9837c62
Require Chef 14 in cookbooks and update Kitchen config to 15
tas50 May 9, 2019
341cd7e
Make the example dokken config a working example
tas50 May 9, 2019
4aa7e11
Auto generate modern ChefSpecs
tas50 May 9, 2019
18d9f4a
Fix chefstyle
tas50 May 9, 2019
85e15a6
Updates from code review
tas50 May 9, 2019
929b611
Add Chef Generate changes to the release notes
tas50 May 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ cookbooks that provide the desired recipes and meet dependency
constraints, and emits a `Policyfile.lock.json` describing the expanded
run list and locked cookbook set. The `Policyfile.lock.json` can be used
to install the cookbooks on another machine. The policy lock can be
uploaded to a Chef Server (via the `chef push` command) to apply the
uploaded to a Chef Infra Server (via the `chef push` command) to apply the
expanded run list and locked cookbook set to nodes in your
infrastructure. See the POLICYFILE_README.md for further details.

### `chef push`
`chef push POLICY_GROUP` uploads a Policyfile.lock.json along with the cookbooks it
references to a Chef Server. The policy lock is applied to a
references to a Chef Infra Server. The policy lock is applied to a
`POLICY_GROUP`, which is a set of nodes that share the same run list and
cookbook set. This command operates in compatibility mode and has the
same caveats as `chef install`. See the POLICYFILE_README.md for further
Expand All @@ -154,7 +154,7 @@ cause only attributes from the Policyfile.rb to be updated.

### `chef diff`
`chef diff` shows an itemized diff between Policyfile locks. It can
compare Policyfile locks from local disk, git, and/or the Chef Server,
compare Policyfile locks from local disk, git, and/or the Chef Infra Server,
based on the options given.

#### `chef verify`
Expand Down
16 changes: 13 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

**4.0 is not out yet. These are work in progress release notes**

## Improved Chef Generate command

The `chef generate` command has been updated to produce cookbooks and repositories the match Chef's best practices.
- `chef generate repo` now generates a Chef repository with Policyfiles by default. You can revert to the previous roles / environment behavior with the `--roles` flag.
- `chef generate cookbook` now includes ChefSpecs that utilize the ChefSpec 7.3+ format. This is a much simpler syntax that requires less updating as older platforms are deprecated.
- `chef generate cookbook` no longer creates cookbbook files with the unecessary `frozen_string_literal: true` comments.
- `chef generate cookbook` now generates cookbooks with metadata requiring Chef 14 or later.
- `chef generate cookbook --kitchen dokken` now generates a fully working kitchen-dokken config.
- `chef generate cookbook` now generates Test Kitchen configs with the `product_name`/`product_version` method of specifying Chef Infra Client releases as `require_chef_omnibus` will be removed in the next major Test Kitchen release.

## Updated Components and Tools

### InSpec 4
Expand All @@ -26,7 +36,7 @@ Chef Provisioning is no longer included with Chef DK, and will be officially end

### InSpec 3.6.6

ChefDK now ships with Inspec 3.6.6. See <https://github.com/inspec/inspec/releases/tag/v3.6.6> for more information on what's new.
ChefDK now ships with InSpec 3.6.6. See <https://github.com/inspec/inspec/releases/tag/v3.6.6> for more information on what's new.

### Fauxhai 6.11.0

Expand Down Expand Up @@ -59,7 +69,7 @@ ChefDK now ships with Chef 14.10.9. See <https://docs.chef.io/release_notes.html

## InSpec 3.4.1

ChefDK now ships with Inspec 3.4.1. See <https://github.com/inspec/inspec/releases/tag/v3.4.1> for more information on what's new.
ChefDK now ships with InSpec 3.4.1. See <https://github.com/inspec/inspec/releases/tag/v3.4.1> for more information on what's new.

## Updated Components and Tools

Expand Down Expand Up @@ -201,7 +211,7 @@ Foodcritic has been updated from 14.1 to 14.3. This updates the metadata that sh

### inSpec 3

This release updates Inspec from 2.2.112 to 3.0.12. This is a major milestone and includes the plugin system, global attributes, enhanced skip messaging, and more. Please head over to https://www.inspec.io/ for a full rundown.
This release updates InSpec from 2.2.112 to 3.0.12. This is a major milestone and includes the plugin system, global attributes, enhanced skip messaging, and more. Please head over to https://www.inspec.io/ for a full rundown.

### Kitchen AzureRM

Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/builtin_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

c.builtin "push-archive", :PushArchive, desc: "Push a policy archive to a policy group on the server"

c.builtin "show-policy", :ShowPolicy, desc: "Show policyfile objects on your Chef Server"
c.builtin "show-policy", :ShowPolicy, desc: "Show policyfile objects on your Chef Infra Server"

c.builtin "diff", :Diff, desc: "Generate an itemized diff of two Policyfile lock documents"

Expand Down
4 changes: 2 additions & 2 deletions lib/chef-dk/chef_server_api_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module ChefDK
# A wrapper for `Chef::ServerAPI` that supports multi-threading by creating a
# `Chef::ServerAPI` object per-thread.
#
# This is intended to be used for downloading cookbooks from the Chef Server,
# where the API of the Chef Server requires each file to be downloaded
# This is intended to be used for downloading cookbooks from the Chef Infa Server,
# where the API of the Chef Infra Server requires each file to be downloaded
# individually.
#
# It also configures `Chef::ServerAPI` to enable keepalives by default. To
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/delete_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeletePolicy < Base
Usage: chef delete-policy POLICY_NAME [options]
`chef delete-policy POLICY_NAME` deletes all revisions of the policy
`POLICY_NAME` on the configured Chef Server. All policy revisions will be
`POLICY_NAME` on the configured Chef Infra Server. All policy revisions will be
backed up locally, allowing you to undo this operation via the `chef undelete`
command.
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/delete_policy_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeletePolicyGroup < Base
Usage: chef delete-policy-group POLICY_GROUP [options]
`chef delete-policy-group POLICY_GROUP` deletes the policy group POLICY_GROUP on
the configured Chef Server. Policy Revisions associated to the policy group are
the configured Chef Infra Server. Policy Revisions associated to the policy group are
not deleted. The state of the policy group will be backed up locally, allowing
you to undo this operation via the `chef undelete` command.
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Diff < Base
When no git-specific flag is given, `chef diff` either compares the
current lockfile revision on disk to one on the server or compares two
lockfiles on the server. Lockfiles on the Chef Server are specified by
lockfiles on the server. Lockfiles on the Chef Infra Server are specified by
Policy Group. Examples:
* `chef diff staging`: compares the current lock with the one currently
Expand Down
10 changes: 5 additions & 5 deletions lib/chef-dk/command/generator_commands/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ class Cookbook < Base
option :berks,
short: "-b",
long: "--berks",
description: "Generate cookbooks with berkshelf integration",
description: "Generate cookbooks using Berkshelf dependency resolution.",
boolean: true,
default: nil

option :kitchen,
long: "--kitchen CONFIGURATION",
description: "Generate cookbooks with a specific kitchen configuration (dokken|vagrant) - defaults to vagrant",
description: "Generate cookbooks with a specific Test Kitchen configuration (dokken|vagrant) - defaults to vagrant",
default: "vagrant"

option :policy,
short: "-P",
long: "--policy",
description: "Use policyfiles instead of Berkshelf",
description: "Generate a cookbook using Policyfile dependency resolution.",
boolean: true,
default: nil

Expand Down Expand Up @@ -108,8 +108,8 @@ def emit_post_create_message
else
msg("Your cookbook is ready. Type `cd #{cookbook_name_or_path}` to enter it.")
msg("\nThere are several commands you can run to get started locally developing and testing your cookbook.")
msg("Type `delivery local --help` to see a full list.")
msg("\nWhy not start by writing a test? Tests for the default recipe are stored at:\n")
msg("Type `delivery local --help` to see a full list of local testing commands.")
msg("\nWhy not start by writing an InSpec test? Tests for the default recipe are stored at:\n")
msg("test/integration/default/default_test.rb")
msg("\nIf you'd prefer to dive right in, the default recipe can be found at:")
msg("\nrecipes/default.rb\n")
Expand Down
18 changes: 9 additions & 9 deletions lib/chef-dk/command/generator_commands/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class Repo < Base
option :policy_only,
short: "-p",
long: "--policy-only",
description: "Create a repository for policy only, not cookbooks",
description: "Create a repository to store Policyfiles only, not cookbooks.",
default: false

option :roles,
short: "-r",
long: "--roles",
description: "Create roles and environments directories instead of using policyfiles",
description: "Create roles and environments directories instead of using Policyfiles.",
default: nil

option :policy,
short: "-P",
long: "--policy",
description: "Use policyfiles instead of Berkshelf",
description: "Use Policyfiles instead of roles and environments.",
boolean: true,
default: nil

Expand All @@ -56,7 +56,7 @@ class Repo < Base
def initialize(params)
@params_valid = true
@repo_name = nil
@use_roles = true
@use_policy = true
super
end

Expand All @@ -76,7 +76,7 @@ def setup_context
super
Generator.add_attr_to_context(:repo_root, repo_root)
Generator.add_attr_to_context(:repo_name, repo_name)
Generator.add_attr_to_context(:use_roles, use_roles?)
Generator.add_attr_to_context(:use_policy, use_policy?)
end

def recipe
Expand All @@ -95,8 +95,8 @@ def repo_full_path
File.expand_path(repo_name_or_path, Dir.pwd)
end

def use_roles?
@use_roles
def use_policy?
@use_policy
end

def read_and_validate_params
Expand All @@ -109,8 +109,8 @@ def read_and_validate_params
err("Roles and Policyfiles are exclusive. Please only select one.")
@params_valid = false
end
if config[:policy]
@use_roles = false
if config[:roles]
@use_policy = false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Install < Base
cookbooks for the policy's run_list and caches them locally. It emits a
Policyfile.lock.json describing the locked cookbook set. You can use the
lockfile to install the locked cookbooks on another machine. You can also push
the lockfile to a "policy group" on a Chef Server and apply that exact set of
the lockfile to a "policy group" on a Chef Infra Server and apply that exact set of
cookbooks to nodes in your infrastructure.
See our detailed README for more information:
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Push < Base
banner(<<~E)
Usage: chef push POLICY_GROUP [ POLICY_FILE ] [options]
`chef push` Uploads an existing Policyfile.lock.json to a Chef Server, along
`chef push` Uploads an existing Policyfile.lock.json to a Chef Infra Server, along
with all the cookbooks contained in the policy lock. The policy lock is applied
to a specific POLICY_GROUP, which is a set of nodes that share the same
run_list and cookbooks.
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/push_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PushArchive < Base
banner(<<~E)
Usage: chef push-archive POLICY_GROUP ARCHIVE_FILE [options]
`chef push-archive` publishes a policy archive to a Chef Server. Policy
`chef push-archive` publishes a policy archive to a Chef Infra Server. Policy
archives can be created with `chef export -a`. The policy will be applied to
the given POLICY_GROUP, which is a set of nodes that share the same
run_list and cookbooks.
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/cookbook_locks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CookbookLock
attr_accessor :identifier

# A string in "X.Y.Z" version number format that uniquely identifies the
# cookbook version. This is for compatibility with Chef Server 11.x,
# cookbook version. This is for compatibility with Chef Infra Server 11.x,
# where cookbooks are stored by x.y.z version numbers.
attr_accessor :dotted_decimal_identifier

Expand Down
4 changes: 2 additions & 2 deletions lib/chef-dk/policyfile_services/export_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module PolicyfileServices

class ExportRepo

# Policy groups provide namespaces for policies so that a Chef Server can
# Policy groups provide namespaces for policies so that a Chef Infra Server can
# have multiple active iterations of a policy at once, but we don't need
# this when serving a single exported policy via Chef Zero, so hardcode
# it to a "well known" value:
Expand Down Expand Up @@ -294,7 +294,7 @@ def create_readme_md
### policy_groups/
Policy groups are used by Chef Server to manage multiple revisions of the same
Policy groups are used by Chef Infra Server to manage multiple revisions of the same
policy. However, exported policies contain only a single policy revision, so
this policy group name is hardcoded to "local" and should not be changed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
source 'https://supermarket.chef.io'

metadata
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
%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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Put files/directories that should be ignored in this file when uploading
# to a chef-server or Supermarket.
# to a Chef Infra Server or Supermarket.
# Lines that start with '# ' are comments.

# OS generated files #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bin/*

# test kitchen
.kitchen/
.kitchen.local.yml
kitchen.local.yml

# Chef
Berksfile.lock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Overview

Every Chef installation needs a Chef Repository. This is the place where cookbooks, roles, config files and other artifacts for managing systems with Chef will live. We strongly recommend storing this repository in a version control system such as Git and treat it like source code.

While we prefer Git, and make this repository available via GitHub, you are welcome to download a tar or zip archive and use your favorite version control system to manage the code.
Every Chef Infra installation needs a Chef Repository. This is the place where cookbooks, policyfiles, config files and other artifacts for managing systems with Chef Infra will live. We strongly recommend storing this repository in a version control system such as Git and treating it like source code.

# Repository Directories

Expand All @@ -15,9 +13,7 @@ This repository contains several directories, and each directory contains a READ

# Configuration

The config file, `.chef/config.rb` is a repository specific configuration file for knife. If you're using the Chef Platform, you can download one for your organization from the management console. You can generate a new one with `knife configure`. For more information about configuring Knife, see the Knife documentation.

<https://docs.chef.io/knife.html>
The config file, `.chef/config.rb` is a repository-specific configuration file for the knife command line tool. If you're using the Hosted Chef platform, you can download one for your organization from the management console. You can also generate a new config.rb by running `knife configure`. For more information about configuring Knife, see the Knife documentation at https://docs.chef.io/knife.html

# Next Steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An example cookbook

## Requirements

### Platform:
### Platforms:

_No platforms defined_

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true
# This is a Chef attributes file. It can be used to specify default and override
# attributes to be applied to nodes that run this cookbook.
# This is a Chef Infra Client attributes file. It can be used to specify default
# and override attributes to be applied to nodes that run this cookbook.

# Set a default name
default['example']['name'] = 'Sam Doe'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
name 'example'
description 'An example cookbook'
maintainer 'Example maintainer'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true
# This is a Chef recipe file. It can be used to specify resources which will
# apply configuration to a server.
# This is a Chef Infra Client recipe file. It can be used to specify resources
# which will apply configuration to a server.

log "Welcome to Chef, #{node['example']['name']}!" do
log "Welcome to Chef Infra Client, #{node['example']['name']}!" do
level :info
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Data Bags

This directory contains directories of the various data bags you create for your infrastructure. Each subdirectory corresponds to a data bag on the Chef Server, and contains JSON files of the items that go in the bag.
This directory contains directories of the various data bags you create for your infrastructure. Each subdirectory corresponds to a data bag on the Chef Infra Server, and contains JSON files of the items that go in the bag.

For example, in this directory you'll find an example data bag directory called `example`, which contains an item definition called `example_item.json`
For example, in this directory, you'll find an example data bag directory called `example`, which contains an item definition called `example_item.json`

Before uploading this item to the server, we must first create the data bag on the Chef Server.
Before uploading this item to the server, we must first create the data bag on the Chef Infra Server.

knife data bag create example
tas50 marked this conversation as resolved.
Show resolved Hide resolved

Then we can upload the items in the data bag's directory to the Chef Server.
Then we can upload the items in the data bag's directory to the Chef Infra Server.

knife data bag from file example example_item.json

For more information on data bags, see the Chef wiki page:
For more information on data bags, see the Chef docs site:

https://docs.chef.io/data_bags.html

Expand Down Expand Up @@ -51,6 +51,6 @@ Use the secret_key to view the contents.
password: abc123


For more information on encrypted data bags, see the Chef wiki page:
For more information on encrypted data bags, see the Chef docs site:

https://docs.chef.io/data_bags.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Create environments here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install environments on the server, use knife.
Create environments here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install environments on the Chef Infra Server, use the knife command.

For example, in this directory you'll find an example environment file called `example.json` which can be uploaded to the Chef Server:
For example, in this directory, you'll find an example environment file called `example.json` which can be uploaded to the Chef Infra Server:

knife environment from file environments/example.json

For more information on environments, see the Chef wiki page:
For more information on environments, see the Chef docs site:

https://docs.chef.io/environments.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Create policyfiles here. When using a chef-repo, give your policyfiles
Create Policyfiles here. When using a chef-repo, give your Policyfiles
the same filename as the name set in the policyfile itself, and use the
`.rb` file extension.

Expand Down
Loading