galvanize 0.1.2
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +242 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/bin/console +12 -0
- data/bin/gal +10 -0
- data/bin/galvanize +10 -0
- data/bin/setup +8 -0
- data/galvanize.gemspec +25 -0
- data/lib/chef-dk/command/generator_commands/habichef.rb +82 -0
- data/lib/chef-dk/configurable-patch.rb +15 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +4 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/build_cookbook/README.md +146 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +21 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +109 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/cookbook_readmes/README.md +66 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/delivery-config.json +17 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/delivery-project.toml +36 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +22 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +24 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +27 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +7 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/data_bags/README.md +56 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/data_bags/example/example_item.json +4 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/dot-chef-repo.txt +6 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/README.md +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/example.json +13 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/policyfiles/README.md +24 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/roles/README.md +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/roles/example.json +13 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper_policyfile.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +13 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/build_cookbook.rb +177 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +161 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +25 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/habichef.rb +92 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/helpers.rb +21 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/policyfile.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +52 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/repo.rb +68 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/resource.rb +13 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/CHANGELOG.md.erb +11 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.apachev2.erb +201 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/Policyfile.rb.erb +25 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +7 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +10 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +8 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/gitignore +28 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/habitat/README.md.erb +96 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/habitat/default.toml.erb +18 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/habitat/plan.sh.erb +16 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/helpers.rb.erb +39 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/inspec_default_test.rb.erb +16 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +26 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +31 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +33 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +20 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/policyfiles/base.rb.erb +30 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe_spec.rb.erb +35 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +128 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +1 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
- data/lib/galvanize.rb +7 -0
- data/lib/galvanize/version.rb +3 -0
- metadata +130 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
This directory typically contains Chef cookbooks. This repository was
|
|
2
|
+
generated with the '--policy-only' option, which means you have chosen
|
|
3
|
+
to use a workflow where each cookbook is treated as an independent
|
|
4
|
+
software project. As a result, any cookbooks present in this directory
|
|
5
|
+
are independent git projects, and the contents of this directory have
|
|
6
|
+
been added to .gitignore.
|
|
7
|
+
|
|
8
|
+
Love,
|
|
9
|
+
Chef
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
This directory contains the cookbooks used to configure systems in your infrastructure with Chef - an example basic cookbook called `example` has been automatically created for you.
|
|
2
|
+
|
|
3
|
+
Knife needs to be configured to know where the cookbooks are located with the `cookbook_path` setting. If this is not set, then several cookbook operations will fail to work properly.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
cookbook_path ["./cookbooks"]
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
This setting tells knife to look for the cookbooks directory in the present working directory. This means the knife cookbook subcommands need to be run in the `chef-repo` directory itself. To make sure that the cookbooks can be found elsewhere inside the repository, use an absolute path. This is a Ruby file, so something like the following can be used:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
current_dir = File.dirname(__FILE__)
|
|
13
|
+
cookbook_path ["#{current_dir}/../cookbooks"]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Which will set `current_dir` to the location of the knife.rb file itself (e.g. `~/chef-repo/.chef/knife.rb`).
|
|
17
|
+
|
|
18
|
+
Configure knife to use your preferred copyright holder, email contact and license. Add the following lines to `.chef/knife.rb`.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
cookbook_copyright "Example, Com."
|
|
22
|
+
cookbook_email "cookbooks@example.com"
|
|
23
|
+
cookbook_license "apachev2"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Supported values for `cookbook_license` are "apachev2", "mit","gplv2","gplv3", or "none". These settings are used to prefill comments in the default recipe, and the corresponding values in the metadata.rb. You are free to change the the comments in those files.
|
|
27
|
+
|
|
28
|
+
Create new cookbooks in this directory with Chef.
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
chef generate cookbook COOKBOOK
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This will create all the cookbook directory components. You don't need to use them all, and can delete the ones you don't need. It also creates a README file, metadata.rb and default recipe.
|
|
35
|
+
|
|
36
|
+
You can also download cookbooks directly from the Chef Supermarket site. There are two subcommands to help with this depending on what your preference is.
|
|
37
|
+
|
|
38
|
+
The first and recommended method is to use a vendor branch if you're using Git. This is automatically handled with Knife.
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
knife cookbook site install COOKBOOK
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This will:
|
|
45
|
+
|
|
46
|
+
- Download the cookbook tarball from the Chef Supermarket.
|
|
47
|
+
- Ensure its on the git master branch.
|
|
48
|
+
- Checks for an existing vendor branch, and creates if it doesn't.
|
|
49
|
+
- Checks out the vendor branch (chef-vendor-COOKBOOK).
|
|
50
|
+
- Removes the existing (old) version.
|
|
51
|
+
- Untars the cookbook tarball it downloaded in the first step.
|
|
52
|
+
- Adds the cookbook files to the git index and commits.
|
|
53
|
+
- Creates a tag for the version downloaded.
|
|
54
|
+
- Checks out the master branch again.
|
|
55
|
+
- Merges the cookbook into master.
|
|
56
|
+
- Repeats the above for all the cookbooks dependencies, downloading them from the community site
|
|
57
|
+
|
|
58
|
+
The last step will ensure that any local changes or modifications you have made to the cookbook are preserved, so you can keep your changes through upstream updates.
|
|
59
|
+
|
|
60
|
+
If you're not using Git, use the site download subcommand to download the tarball.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
knife cookbook site download COOKBOOK
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This creates the COOKBOOK.tar.gz from in the current directory (e.g., `~/chef-repo`). We recommend following a workflow similar to the above for your version control tool.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2",
|
|
3
|
+
"build_cookbook": {
|
|
4
|
+
"name": "build_cookbook",
|
|
5
|
+
"path": ".delivery/build_cookbook"
|
|
6
|
+
},
|
|
7
|
+
"delivery-truck": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"enable_cookstyle": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"skip_phases": [],
|
|
13
|
+
"job_dispatch": {
|
|
14
|
+
"version": "v2"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": []
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Delivery Prototype for Local Phases Execution
|
|
2
|
+
#
|
|
3
|
+
# The purpose of this file is to prototype a new way to execute
|
|
4
|
+
# phases locally on your workstation. The delivery-cli will read
|
|
5
|
+
# this file and execute the command(s) that are configured for
|
|
6
|
+
# each phase. You can customize them by just modifying the phase
|
|
7
|
+
# key on this file.
|
|
8
|
+
#
|
|
9
|
+
# By default these phases are configured for Cookbook Workflow only
|
|
10
|
+
#
|
|
11
|
+
# As this is still a prototype we are not modifying the current
|
|
12
|
+
# config.json file and it will continue working as usual.
|
|
13
|
+
|
|
14
|
+
[local_phases]
|
|
15
|
+
unit = "chef exec rspec spec/"
|
|
16
|
+
lint = "chef exec cookstyle"
|
|
17
|
+
# Foodcritic includes rules only appropriate for community cookbooks
|
|
18
|
+
# uploaded to Supermarket. We turn off any rules tagged "supermarket"
|
|
19
|
+
# by default. If you plan to share this cookbook you should remove
|
|
20
|
+
# '-t ~supermarket' below to enable supermarket rules.
|
|
21
|
+
syntax = "chef exec foodcritic . -t ~supermarket"
|
|
22
|
+
provision = "chef exec kitchen create"
|
|
23
|
+
deploy = "chef exec kitchen converge"
|
|
24
|
+
smoke = "chef exec kitchen verify"
|
|
25
|
+
# The functional phase is optional, you can define it by uncommenting
|
|
26
|
+
# the line below and running the command: `delivery local functional`
|
|
27
|
+
# functional = ""
|
|
28
|
+
cleanup = "chef exec kitchen destroy"
|
|
29
|
+
|
|
30
|
+
# Remote project.toml file
|
|
31
|
+
#
|
|
32
|
+
# Specify a remote URI location for the `project.toml` file.
|
|
33
|
+
# This is useful for teams that wish to centrally manage the behavior
|
|
34
|
+
# of the `delivery local` command across many different projects.
|
|
35
|
+
#
|
|
36
|
+
# remote_file = "https://url/project.toml"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.vagrant
|
|
2
|
+
*~
|
|
3
|
+
*#
|
|
4
|
+
.#*
|
|
5
|
+
\#*#
|
|
6
|
+
.*.sw[a-z]
|
|
7
|
+
*.un~
|
|
8
|
+
|
|
9
|
+
# Bundler
|
|
10
|
+
Gemfile.lock
|
|
11
|
+
gems.locked
|
|
12
|
+
bin/*
|
|
13
|
+
.bundle/*
|
|
14
|
+
|
|
15
|
+
# test kitchen
|
|
16
|
+
.kitchen/
|
|
17
|
+
.kitchen.local.yml
|
|
18
|
+
|
|
19
|
+
# Chef
|
|
20
|
+
Berksfile.lock
|
|
21
|
+
.zero-knife.rb
|
|
22
|
+
Policyfile.lock.json
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
# Repository Directories
|
|
8
|
+
|
|
9
|
+
This repository contains several directories, and each directory contains a README file that describes what it is for in greater detail, and how to use it for managing your systems with Chef.
|
|
10
|
+
|
|
11
|
+
- `cookbooks/` - Cookbooks you download or create.
|
|
12
|
+
- `data_bags/` - Store data bags and items in .json in the repository.
|
|
13
|
+
- `roles/` - Store roles in .rb or .json in the repository.
|
|
14
|
+
- `environments/` - Store environments in .rb or .json in the repository.
|
|
15
|
+
|
|
16
|
+
# Configuration
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
|
|
20
|
+
<https://docs.chef.io/knife.html>
|
|
21
|
+
|
|
22
|
+
# Next Steps
|
|
23
|
+
|
|
24
|
+
Read the README file in each of the subdirectories for more information about what goes in those directories.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Example
|
|
2
|
+
|
|
3
|
+
An example cookbook
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
### Platform:
|
|
8
|
+
|
|
9
|
+
_No platforms defined_
|
|
10
|
+
|
|
11
|
+
### Cookbooks:
|
|
12
|
+
|
|
13
|
+
_No dependencies defined_
|
|
14
|
+
|
|
15
|
+
## Attributes
|
|
16
|
+
|
|
17
|
+
- `node['example']['name']` - Defaults to `Sam Doe`.
|
|
18
|
+
|
|
19
|
+
## Recipes
|
|
20
|
+
|
|
21
|
+
- example::default
|
|
22
|
+
|
|
23
|
+
## License and Maintainer
|
|
24
|
+
|
|
25
|
+
Maintainer:: (<>)
|
|
26
|
+
|
|
27
|
+
License:: All rights reserved
|
data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# This is a Chef attributes file. It can be used to specify default and override
|
|
3
|
+
# attributes to be applied to nodes that run this cookbook.
|
|
4
|
+
|
|
5
|
+
# Set a default name
|
|
6
|
+
default['example']['name'] = 'Sam Doe'
|
|
7
|
+
|
|
8
|
+
# For further information, see the Chef documentation (https://docs.chef.io/attributes.html).
|
data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# This is a Chef recipe file. It can be used to specify resources which will
|
|
3
|
+
# apply configuration to a server.
|
|
4
|
+
|
|
5
|
+
log "Welcome to Chef, #{node['example']['name']}!" do
|
|
6
|
+
level :info
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# For more information, see the documentation: https://docs.chef.io/recipes.html
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Data Bags
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
For example, in this directory you'll find an example data bag directory called `example`, which contains an item definition called `example_item.json`
|
|
6
|
+
|
|
7
|
+
Before uploading this item to the server, we must first create the data bag on the Chef Server.
|
|
8
|
+
|
|
9
|
+
knife data bag create example
|
|
10
|
+
|
|
11
|
+
Then we can upload the items in the data bag's directory to the Chef Server.
|
|
12
|
+
|
|
13
|
+
knife data bag from file example example_item.json
|
|
14
|
+
|
|
15
|
+
For more information on data bags, see the Chef wiki page:
|
|
16
|
+
|
|
17
|
+
https://docs.chef.io/data_bags.html
|
|
18
|
+
|
|
19
|
+
# Encrypted Data Bags
|
|
20
|
+
|
|
21
|
+
Encrypted data bags allow you to encrypt the contents of your data bags. The content of attributes will no longer be searchable. To use encrypted data bags, first you must have or create a secret key.
|
|
22
|
+
|
|
23
|
+
openssl rand -base64 512 > secret_key
|
|
24
|
+
|
|
25
|
+
You may use this secret_key to add items to a data bag during a create.
|
|
26
|
+
|
|
27
|
+
knife data bag create --secret-file secret_key passwords mysql
|
|
28
|
+
|
|
29
|
+
You may also use it when adding ITEMs from files,
|
|
30
|
+
|
|
31
|
+
knife data bag create passwords
|
|
32
|
+
knife data bag from file passwords data_bags/passwords/mysql.json --secret-file secret_key
|
|
33
|
+
|
|
34
|
+
The JSON for the ITEM must contain a key named "id" with a value equal to "ITEM" and the contents will be encrypted when uploaded. For example,
|
|
35
|
+
|
|
36
|
+
{
|
|
37
|
+
"id": "mysql",
|
|
38
|
+
"password": "abc123"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Without the secret_key, the contents are encrypted.
|
|
42
|
+
|
|
43
|
+
knife data bag show passwords mysql
|
|
44
|
+
id: mysql
|
|
45
|
+
password: 2I0XUUve1TXEojEyeGsjhw==
|
|
46
|
+
|
|
47
|
+
Use the secret_key to view the contents.
|
|
48
|
+
|
|
49
|
+
knife data bag show passwords mysql --secret-file secret_key
|
|
50
|
+
id: mysql
|
|
51
|
+
password: abc123
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
For more information on encrypted data bags, see the Chef wiki page:
|
|
55
|
+
|
|
56
|
+
https://docs.chef.io/data_bags.html
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Create environments here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install environments on the server, use knife.
|
|
2
|
+
|
|
3
|
+
For example, in this directory you'll find an example environment file called `example.json` which can be uploaded to the Chef Server:
|
|
4
|
+
|
|
5
|
+
knife environment from file environments/example.json
|
|
6
|
+
|
|
7
|
+
For more information on environments, see the Chef wiki page:
|
|
8
|
+
|
|
9
|
+
https://docs.chef.io/environments.html
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example",
|
|
3
|
+
"description": "This is an example environment defined as JSON",
|
|
4
|
+
"chef_type": "environment",
|
|
5
|
+
"json_class": "Chef::Environment",
|
|
6
|
+
"default_attributes": {
|
|
7
|
+
},
|
|
8
|
+
"override_attributes": {
|
|
9
|
+
},
|
|
10
|
+
"cookbook_versions": {
|
|
11
|
+
"example": "= 1.0.0"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Create policyfiles here. When using a chef-repo, give your policyfiles
|
|
2
|
+
the same filename as the name set in the policyfile itself, and use the
|
|
3
|
+
`.rb` file extension.
|
|
4
|
+
|
|
5
|
+
Compile the policy with a command like this:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
chef install policyfiles/my-app-frontend.rb
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This will create a lockfile `policyfiles/my-app-frontend.lock.json`.
|
|
12
|
+
|
|
13
|
+
To update locked dependencies, run `chef update` like this:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
chef update policyfiles/my-app-frontend.rb
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
You can upload the policy (with associated cookbooks) to the server
|
|
20
|
+
using a command like:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
chef push staging policyfiles/my-app-frontend.rb
|
|
24
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Create roles here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install roles on the server, use knife.
|
|
2
|
+
|
|
3
|
+
For example, in this directory you'll find an example role file called `example.json` which can be uploaded to the Chef Server:
|
|
4
|
+
|
|
5
|
+
knife role from file roles/example.json
|
|
6
|
+
|
|
7
|
+
For more information on roles, see the Chef wiki page:
|
|
8
|
+
|
|
9
|
+
https://docs.chef.io/roles.html
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
context = ChefDK::Generator.context
|
|
4
|
+
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
|
|
5
|
+
attribute_dir = File.join(cookbook_dir, 'attributes')
|
|
6
|
+
attribute_path = File.join(cookbook_dir, 'attributes', "#{context.new_file_basename}.rb")
|
|
7
|
+
|
|
8
|
+
directory attribute_dir
|
|
9
|
+
|
|
10
|
+
template attribute_path do
|
|
11
|
+
source 'attribute.rb.erb'
|
|
12
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
|
13
|
+
end
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
context = ChefDK::Generator.context
|
|
4
|
+
delivery_project_dir = context.delivery_project_dir
|
|
5
|
+
pipeline = context.pipeline
|
|
6
|
+
dot_delivery_dir = File.join(delivery_project_dir, '.delivery')
|
|
7
|
+
config_json = File.join(dot_delivery_dir, 'config.json')
|
|
8
|
+
project_toml = File.join(dot_delivery_dir, 'project.toml')
|
|
9
|
+
|
|
10
|
+
generator_desc('Ensuring delivery configuration')
|
|
11
|
+
|
|
12
|
+
directory dot_delivery_dir
|
|
13
|
+
|
|
14
|
+
cookbook_file config_json do
|
|
15
|
+
source 'delivery-config.json'
|
|
16
|
+
not_if { File.exist?(config_json) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Adding a new prototype file for delivery-cli local commands
|
|
20
|
+
cookbook_file project_toml do
|
|
21
|
+
source 'delivery-project.toml'
|
|
22
|
+
not_if { File.exist?(project_toml) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
generator_desc('Ensuring correct delivery build cookbook content')
|
|
26
|
+
|
|
27
|
+
build_cookbook_dir = File.join(dot_delivery_dir, 'build_cookbook')
|
|
28
|
+
|
|
29
|
+
# cookbook root dir
|
|
30
|
+
directory build_cookbook_dir
|
|
31
|
+
|
|
32
|
+
# metadata.rb
|
|
33
|
+
template "#{build_cookbook_dir}/metadata.rb" do
|
|
34
|
+
source 'build_cookbook/metadata.rb.erb'
|
|
35
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
|
36
|
+
action :create_if_missing
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# README
|
|
40
|
+
cookbook_file "#{build_cookbook_dir}/README.md" do
|
|
41
|
+
source 'build_cookbook/README.md'
|
|
42
|
+
action :create_if_missing
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# LICENSE
|
|
46
|
+
template "#{build_cookbook_dir}/LICENSE" do
|
|
47
|
+
source "LICENSE.#{context.license}.erb"
|
|
48
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
|
49
|
+
action :create_if_missing
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# chefignore
|
|
53
|
+
cookbook_file "#{build_cookbook_dir}/chefignore"
|
|
54
|
+
|
|
55
|
+
# Berksfile
|
|
56
|
+
template "#{build_cookbook_dir}/Berksfile" do
|
|
57
|
+
source 'build_cookbook/Berksfile.erb'
|
|
58
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
|
59
|
+
action :create_if_missing
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Recipes
|
|
63
|
+
directory "#{build_cookbook_dir}/recipes"
|
|
64
|
+
|
|
65
|
+
%w(default deploy functional lint provision publish quality security smoke syntax unit).each do |phase|
|
|
66
|
+
template "#{build_cookbook_dir}/recipes/#{phase}.rb" do
|
|
67
|
+
source 'build_cookbook/recipe.rb.erb'
|
|
68
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
|
69
|
+
variables phase: phase
|
|
70
|
+
action :create_if_missing
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Test Kitchen build node
|
|
75
|
+
cookbook_file "#{build_cookbook_dir}/kitchen.yml" do
|
|
76
|
+
source 'build_cookbook/kitchen.yml'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
directory "#{build_cookbook_dir}/data_bags/keys" do
|
|
80
|
+
recursive true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
file "#{build_cookbook_dir}/data_bags/keys/delivery_builder_keys.json" do
|
|
84
|
+
content '{"id": "delivery_builder_keys"}'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
directory "#{build_cookbook_dir}/secrets"
|
|
88
|
+
|
|
89
|
+
file "#{build_cookbook_dir}/secrets/fakey-mcfakerton"
|
|
90
|
+
|
|
91
|
+
directory "#{build_cookbook_dir}/test/fixtures/cookbooks/test/recipes" do
|
|
92
|
+
recursive true
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
file "#{build_cookbook_dir}/test/fixtures/cookbooks/test/metadata.rb" do
|
|
96
|
+
content %(name 'test'
|
|
97
|
+
version '0.1.0')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
cookbook_file "#{build_cookbook_dir}/test/fixtures/cookbooks/test/recipes/default.rb" do
|
|
101
|
+
source 'build_cookbook/test-fixture-recipe.rb'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Construct git history as if we did all the work in a feature branch which we
|
|
105
|
+
# merged into master at the end, which looks like this:
|
|
106
|
+
#
|
|
107
|
+
# ```
|
|
108
|
+
# git log --graph --oneline
|
|
109
|
+
# * 5fec5bd Merge branch 'add-delivery-configuration'
|
|
110
|
+
# |\
|
|
111
|
+
# | * 967bb9f Add generated delivery build cookbook
|
|
112
|
+
# | * 1558e0a Add generated delivery configuration
|
|
113
|
+
# |/
|
|
114
|
+
# * db22790 Add generated cookbook content
|
|
115
|
+
# ```
|
|
116
|
+
#
|
|
117
|
+
if context.have_git && context.delivery_project_git_initialized && !context.skip_git_init
|
|
118
|
+
|
|
119
|
+
generator_desc('Adding delivery configuration to feature branch')
|
|
120
|
+
|
|
121
|
+
execute('git-create-feature-branch') do
|
|
122
|
+
command('git checkout -t -b add-delivery-configuration')
|
|
123
|
+
cwd delivery_project_dir
|
|
124
|
+
not_if { shell_out('git branch', cwd: delivery_project_dir).stdout.match(/add-delivery-configuration/) }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
execute('git-add-delivery-config-json') do
|
|
128
|
+
command('git add .delivery/config.json')
|
|
129
|
+
cwd delivery_project_dir
|
|
130
|
+
only_if { shell_out('git status -u --porcelain', cwd: delivery_project_dir).stdout.match(%r{.delivery/config.json}) }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Adding the new prototype file to the feature branch
|
|
134
|
+
# so it gets checked in with the delivery config commit
|
|
135
|
+
execute('git-add-delivery-project-toml') do
|
|
136
|
+
command('git add .delivery/project.toml')
|
|
137
|
+
cwd delivery_project_dir
|
|
138
|
+
only_if { shell_out('git status -u --porcelain', cwd: delivery_project_dir).stdout.match(%r{.delivery/project.toml}) }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
execute('git-commit-delivery-config') do
|
|
142
|
+
command('git commit -m "Add generated delivery configuration"')
|
|
143
|
+
cwd delivery_project_dir
|
|
144
|
+
only_if { shell_out('git status -u --porcelain', cwd: delivery_project_dir).stdout.match(/config\.json|project\.toml/) }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
generator_desc('Adding build cookbook to feature branch')
|
|
148
|
+
|
|
149
|
+
execute('git-add-delivery-build-cookbook-files') do
|
|
150
|
+
command('git add .delivery')
|
|
151
|
+
cwd delivery_project_dir
|
|
152
|
+
only_if { shell_out('git status -u --porcelain', cwd: delivery_project_dir).stdout.match(/\.delivery/) }
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
execute('git-commit-delivery-build-cookbook') do
|
|
156
|
+
command('git commit -m "Add generated delivery build cookbook"')
|
|
157
|
+
cwd delivery_project_dir
|
|
158
|
+
only_if { shell_out('git status -u --porcelain', cwd: delivery_project_dir).stdout.match(/\.delivery/) }
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
execute("git-return-to-#{pipeline}-branch") do
|
|
162
|
+
command("git checkout #{pipeline}")
|
|
163
|
+
cwd delivery_project_dir
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
generator_desc('Merging delivery content feature branch to master')
|
|
167
|
+
|
|
168
|
+
execute('git-merge-delivery-config-branch') do
|
|
169
|
+
command('git merge --no-ff add-delivery-configuration')
|
|
170
|
+
cwd delivery_project_dir
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
execute('git-remove-delivery-config-branch') do
|
|
174
|
+
command('git branch -D add-delivery-configuration')
|
|
175
|
+
cwd delivery_project_dir
|
|
176
|
+
end
|
|
177
|
+
end
|