chef-dk 1.1.16 → 1.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +12 -4
- data/Gemfile.lock +84 -68
- data/Rakefile +9 -0
- data/acceptance/Gemfile +3 -0
- data/acceptance/Gemfile.lock +43 -27
- data/chef-dk.gemspec +3 -2
- data/lib/chef-dk/command/install.rb +1 -1
- data/lib/chef-dk/exceptions.rb +10 -0
- data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +52 -8
- data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -1
- data/lib/chef-dk/policyfile/cookbook_location_specification.rb +2 -2
- data/lib/chef-dk/policyfile/dsl.rb +4 -2
- data/lib/chef-dk/policyfile/source_uri.rb +57 -0
- data/lib/chef-dk/policyfile/storage_config.rb +3 -0
- data/lib/chef-dk/policyfile_compiler.rb +4 -4
- data/lib/chef-dk/policyfile_services/install.rb +4 -2
- data/lib/chef-dk/skeletons/code_generator/files/default/delivery-project.toml +14 -3
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/build_cookbook.rb +2 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +121 -4
- data/lib/chef-dk/version.rb +1 -1
- data/omnibus_overrides.rb +2 -0
- data/spec/unit/command/generator_commands/cookbook_spec.rb +16 -5
- data/spec/unit/command/install_spec.rb +2 -2
- data/spec/unit/fixtures/cookbooks_api/chef_server_universe.json +56 -0
- data/spec/unit/fixtures/cookbooks_api/pruned_chef_server_universe.json +30 -0
- data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +29 -8
- data/spec/unit/policyfile/cookbook_location_specification_spec.rb +22 -0
- data/spec/unit/policyfile/source_uri_spec.rb +36 -0
- data/spec/unit/policyfile/storage_config_spec.rb +12 -0
- data/spec/unit/policyfile_services/push_spec.rb +16 -0
- data/version_policy.rb +9 -5
- metadata +40 -13
@@ -38,6 +38,9 @@ module ChefDK
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def use_policyfile(policyfile_filename)
|
41
|
+
if policyfile_filename.end_with?(".lock.json")
|
42
|
+
return use_policyfile_lock(policyfile_filename)
|
43
|
+
end
|
41
44
|
unless policyfile_filename.end_with?(".rb")
|
42
45
|
raise InvalidPolicyfileFilename, "Policyfile filenames must end with `.rb' extension (you gave: `#{policyfile_filename}')"
|
43
46
|
end
|
@@ -38,8 +38,8 @@ module ChefDK
|
|
38
38
|
# Cookbooks from these sources lock that cookbook to exactly one version
|
39
39
|
SOURCE_TYPES_WITH_FIXED_VERSIONS = [:git, :path].freeze
|
40
40
|
|
41
|
-
def self.evaluate(policyfile_string, policyfile_filename, ui: nil)
|
42
|
-
compiler = new(ui: ui)
|
41
|
+
def self.evaluate(policyfile_string, policyfile_filename, ui: nil, chef_config: nil)
|
42
|
+
compiler = new(ui: ui, chef_config: chef_config)
|
43
43
|
compiler.evaluate_policyfile(policyfile_string, policyfile_filename)
|
44
44
|
compiler
|
45
45
|
end
|
@@ -56,9 +56,9 @@ module ChefDK
|
|
56
56
|
attr_reader :storage_config
|
57
57
|
attr_reader :install_report
|
58
58
|
|
59
|
-
def initialize(ui: nil)
|
59
|
+
def initialize(ui: nil, chef_config: nil)
|
60
60
|
@storage_config = Policyfile::StorageConfig.new
|
61
|
-
@dsl = Policyfile::DSL.new(storage_config)
|
61
|
+
@dsl = Policyfile::DSL.new(storage_config, chef_config: chef_config)
|
62
62
|
@artifact_server_cookbook_location_specs = {}
|
63
63
|
|
64
64
|
@merged_graph = nil
|
@@ -34,10 +34,12 @@ module ChefDK
|
|
34
34
|
attr_reader :ui
|
35
35
|
attr_reader :storage_config
|
36
36
|
attr_reader :overwrite
|
37
|
+
attr_reader :chef_config
|
37
38
|
|
38
|
-
def initialize(policyfile: nil, ui: nil, root_dir: nil, overwrite: false)
|
39
|
+
def initialize(policyfile: nil, ui: nil, root_dir: nil, overwrite: false, config: nil)
|
39
40
|
@ui = ui
|
40
41
|
@overwrite = overwrite
|
42
|
+
@chef_config = config
|
41
43
|
|
42
44
|
policyfile_rel_path = policyfile || "Policyfile.rb"
|
43
45
|
policyfile_full_path = File.expand_path(policyfile_rel_path, root_dir)
|
@@ -66,7 +68,7 @@ module ChefDK
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def policyfile_compiler
|
69
|
-
@policyfile_compiler ||= ChefDK::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui: ui)
|
71
|
+
@policyfile_compiler ||= ChefDK::PolicyfileCompiler.evaluate(policyfile_content, policyfile_expanded_path, ui: ui, chef_config: chef_config)
|
70
72
|
end
|
71
73
|
|
72
74
|
def expanded_run_list
|
@@ -12,14 +12,25 @@
|
|
12
12
|
# config.json file and it will continue working as usual.
|
13
13
|
|
14
14
|
[local_phases]
|
15
|
-
unit = "rspec spec/"
|
16
|
-
lint = "cookstyle"
|
15
|
+
unit = "chef exec rspec spec/"
|
16
|
+
lint = "chef exec cookstyle"
|
17
17
|
# Foodcritic includes rules only appropriate for community cookbooks
|
18
18
|
# uploaded to Supermarket. We turn off any rules tagged "supermarket"
|
19
19
|
# by default. If you plan to share this cookbook you should remove
|
20
20
|
# '-t ~supermarket' below to enable supermarket rules.
|
21
|
-
syntax = "foodcritic . --exclude spec -f any -t ~supermarket"
|
21
|
+
syntax = "chef exec foodcritic . --exclude spec -f any -t ~supermarket"
|
22
22
|
provision = "chef exec kitchen create"
|
23
23
|
deploy = "chef exec kitchen converge"
|
24
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 = ""
|
25
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"
|
@@ -116,6 +116,8 @@ if context.have_git && context.delivery_project_git_initialized && !context.skip
|
|
116
116
|
execute("git-create-feature-branch") do
|
117
117
|
command("git checkout -t -b add-delivery-configuration")
|
118
118
|
cwd delivery_project_dir
|
119
|
+
|
120
|
+
not_if "git branch |grep \"add-delivery-configuration\""
|
119
121
|
end
|
120
122
|
|
121
123
|
execute("git-add-delivery-config-json") do
|
@@ -1,11 +1,128 @@
|
|
1
|
-
.
|
1
|
+
## Below are example of common git excludes.
|
2
|
+
## Please note that /cookbooks folder is ignored. This allows users to
|
3
|
+
## clone individual cookbooks into the /cookbook folder of the chef repo
|
4
|
+
## and work on them in parallel. This pattern also allows for chef-workstation
|
5
|
+
## pattern, where base repo also builds out a dynamic chef workstation.
|
6
|
+
## Examples of workstation cookbooks:
|
7
|
+
## https://github.com/mwrock/chef_workstation
|
8
|
+
## https://github.com/Nordstrom/chefdk_bootstrap
|
9
|
+
|
2
10
|
|
3
|
-
|
4
|
-
|
5
|
-
###
|
11
|
+
## Ignore Chef related files and secrets
|
12
|
+
.chef
|
6
13
|
.chef/*.pem
|
7
14
|
.chef/encrypted_data_bag_secret
|
8
15
|
<%- if policy_only -%>
|
9
16
|
cookbooks/**
|
10
17
|
!cookbooks/README.md
|
11
18
|
<%- end -%>
|
19
|
+
|
20
|
+
## Ignore Chef-Zero files
|
21
|
+
clients
|
22
|
+
nodes
|
23
|
+
|
24
|
+
# ## OS junk files
|
25
|
+
# [Tt]humbs.db
|
26
|
+
# *.DS_Store
|
27
|
+
|
28
|
+
# ## Example of the workstation pattern.
|
29
|
+
# !/cookbooks/chef_workstation/files/default/bundler/Gemfile
|
30
|
+
# !/cookbooks/chef_workstation/files/default/bundler/Gemfile.lock
|
31
|
+
# cookbooks/*
|
32
|
+
# !cookbooks/chef_workstation
|
33
|
+
|
34
|
+
# ##Chef
|
35
|
+
# .kitchen/
|
36
|
+
# .vagrant
|
37
|
+
# nodes
|
38
|
+
# metadata.json
|
39
|
+
|
40
|
+
# ##ruby
|
41
|
+
# *.gem
|
42
|
+
# Gemfile
|
43
|
+
# Gemfile.lock
|
44
|
+
.rake_test_cache
|
45
|
+
|
46
|
+
# ## Rails Heroku and other bits to ignore
|
47
|
+
# *.log
|
48
|
+
# *.sqlite3
|
49
|
+
# db/*.sqlite3
|
50
|
+
# .bundle
|
51
|
+
# log/*
|
52
|
+
# tmp/*
|
53
|
+
# public/system/*
|
54
|
+
|
55
|
+
# ##nodejs
|
56
|
+
# node_modules
|
57
|
+
|
58
|
+
# # Nuget (exclude all exes except for the one in the global build folder)
|
59
|
+
# nuget.exe
|
60
|
+
# !build/nuget/nuget.exe
|
61
|
+
# *.nupkg
|
62
|
+
# # NuGet packages (based on default naming convention)
|
63
|
+
# [Bb]uild/[Pp]ackages/
|
64
|
+
|
65
|
+
# # Build System # common build output folders
|
66
|
+
# build-common/
|
67
|
+
# output/
|
68
|
+
|
69
|
+
# ## Probably not a good idea to be keeing VM inages in source control
|
70
|
+
# *.vhd
|
71
|
+
# *.vhdx
|
72
|
+
|
73
|
+
# ## Pester Test summary
|
74
|
+
# Test.xml
|
75
|
+
|
76
|
+
# ##Webstorm files
|
77
|
+
# *.idea
|
78
|
+
# .idea
|
79
|
+
# .idea/
|
80
|
+
|
81
|
+
# ##Mono (or something?) files
|
82
|
+
# *.pidb
|
83
|
+
# *.userprefs
|
84
|
+
|
85
|
+
# ## Visual Studio files
|
86
|
+
# *.docstates
|
87
|
+
# *.[Oo]bj
|
88
|
+
# *.dat
|
89
|
+
# *.crc
|
90
|
+
# *.dbmdl
|
91
|
+
# *.pdb
|
92
|
+
# *.user
|
93
|
+
# *.aps
|
94
|
+
# *.pch
|
95
|
+
# *.vspscc
|
96
|
+
# *.vssscc
|
97
|
+
# *_i.c
|
98
|
+
# *_p.c
|
99
|
+
# *.ncb
|
100
|
+
# *.suo
|
101
|
+
# *.tlb
|
102
|
+
# *.tlh
|
103
|
+
# *.bak
|
104
|
+
# *.[Cc]ache
|
105
|
+
# *.ilk
|
106
|
+
# *.log
|
107
|
+
# *.lib
|
108
|
+
# *.sbr
|
109
|
+
# *.schemaview
|
110
|
+
# ipch/
|
111
|
+
# [Oo]bj/
|
112
|
+
# [Bb]in/*
|
113
|
+
# [Dd]ebug*/
|
114
|
+
# [Rr]elease*/
|
115
|
+
# Ankh.NoLoad
|
116
|
+
|
117
|
+
# ##Tooling
|
118
|
+
# _ReSharper*/
|
119
|
+
# *.[Rr]e[Ss]harper
|
120
|
+
# [Tt]est[Rr]esult*
|
121
|
+
# .[Jj]ust[Cc]ode
|
122
|
+
# *ncrunch*
|
123
|
+
|
124
|
+
# ##Subversion files
|
125
|
+
# .svn
|
126
|
+
|
127
|
+
# ## Office Temp Files
|
128
|
+
# ~$*
|
data/lib/chef-dk/version.rb
CHANGED
data/omnibus_overrides.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# DO NOT EDIT. Generated by "rake dependencies". Edit version_policy.rb instead.
|
2
|
+
override :rubygems, version: "2.6.10"
|
2
3
|
override :bundler, version: "1.12.5"
|
3
4
|
override "libffi", version: "3.2.1"
|
4
5
|
override "libiconv", version: "1.14"
|
@@ -16,3 +17,4 @@ override "util-macros", version: "1.19.0"
|
|
16
17
|
override "xproto", version: "7.0.28"
|
17
18
|
override "zlib", version: "1.2.8"
|
18
19
|
override "libzmq", version: "4.0.5"
|
20
|
+
override "kitchen-dokken", version: "1.1.0"
|
@@ -193,18 +193,29 @@ EOF
|
|
193
193
|
# config.json file and it will continue working as usual.
|
194
194
|
|
195
195
|
[local_phases]
|
196
|
-
unit = "rspec spec/"
|
197
|
-
lint = "cookstyle"
|
196
|
+
unit = "chef exec rspec spec/"
|
197
|
+
lint = "chef exec cookstyle"
|
198
198
|
# Foodcritic includes rules only appropriate for community cookbooks
|
199
199
|
# uploaded to Supermarket. We turn off any rules tagged "supermarket"
|
200
200
|
# by default. If you plan to share this cookbook you should remove
|
201
201
|
# '-t ~supermarket' below to enable supermarket rules.
|
202
|
-
syntax = "foodcritic . --exclude spec -f any -t ~supermarket"
|
202
|
+
syntax = "chef exec foodcritic . --exclude spec -f any -t ~supermarket"
|
203
203
|
provision = "chef exec kitchen create"
|
204
204
|
deploy = "chef exec kitchen converge"
|
205
205
|
smoke = "chef exec kitchen verify"
|
206
|
+
# The functional phase is optional, you can define it by uncommenting
|
207
|
+
# the line below and running the command: `delivery local functional`
|
208
|
+
# functional = ""
|
206
209
|
cleanup = "chef exec kitchen destroy"
|
207
|
-
|
210
|
+
|
211
|
+
# Remote project.toml file
|
212
|
+
#
|
213
|
+
# Specify a remote URI location for the `project.toml` file.
|
214
|
+
# This is useful for teams that wish to centrally manage the behavior
|
215
|
+
# of the `delivery local` command across many different projects.
|
216
|
+
#
|
217
|
+
# remote_file = "https://url/project.toml"
|
218
|
+
PROJECT_DOT_TOML
|
208
219
|
end
|
209
220
|
|
210
221
|
it "exists with default config for Cookbook Workflow" do
|
@@ -252,7 +263,7 @@ cleanup = "chef exec kitchen destroy"
|
|
252
263
|
# Cookbook:: build_cookbook
|
253
264
|
# Recipe:: publish
|
254
265
|
#
|
255
|
-
# Copyright::
|
266
|
+
# Copyright:: 2017, The Authors, All Rights Reserved.
|
256
267
|
include_recipe 'delivery-truck::publish'
|
257
268
|
CONFIG_DOT_JSON
|
258
269
|
end
|
@@ -78,7 +78,7 @@ describe ChefDK::Command::Install do
|
|
78
78
|
|
79
79
|
it "creates the installer service with a `nil` policyfile path" do
|
80
80
|
expect(ChefDK::PolicyfileServices::Install).to receive(:new).
|
81
|
-
with(policyfile: nil, ui: command.ui, root_dir: Dir.pwd).
|
81
|
+
with(hash_including(policyfile: nil, ui: command.ui, root_dir: Dir.pwd)).
|
82
82
|
and_return(install_service)
|
83
83
|
expect(command.installer).to eq(install_service)
|
84
84
|
end
|
@@ -95,7 +95,7 @@ describe ChefDK::Command::Install do
|
|
95
95
|
|
96
96
|
it "creates the installer service with the specified policyfile path" do
|
97
97
|
expect(ChefDK::PolicyfileServices::Install).to receive(:new).
|
98
|
-
with(policyfile: "MyPolicy.rb", ui: command.ui, root_dir: Dir.pwd).
|
98
|
+
with(hash_including(policyfile: "MyPolicy.rb", ui: command.ui, root_dir: Dir.pwd)).
|
99
99
|
and_return(install_service)
|
100
100
|
expect(command.installer).to eq(install_service)
|
101
101
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"yum": {
|
3
|
+
"4.1.0": {
|
4
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/yum/4.1.0",
|
5
|
+
"location_type": "chef_server",
|
6
|
+
"dependencies": {
|
7
|
+
|
8
|
+
}
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"windows": {
|
12
|
+
"2.1.1": {
|
13
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/windows/2.1.1",
|
14
|
+
"location_type": "chef_server",
|
15
|
+
"dependencies": {
|
16
|
+
"ohai": ">= 4.0.0"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"ubuntu": {
|
21
|
+
"2.0.0": {
|
22
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/ubuntu/2.0.0",
|
23
|
+
"location_type": "chef_server",
|
24
|
+
"dependencies": {
|
25
|
+
"apt": ">= 0.0.0"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
"ohai": {
|
30
|
+
"4.2.3": {
|
31
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/ohai/4.2.3",
|
32
|
+
"location_type": "chef_server",
|
33
|
+
"dependencies": {
|
34
|
+
"compat_resource": ">= 12.14.7"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"compat_resource": {
|
39
|
+
"12.16.3": {
|
40
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/compat_resource/12.16.3",
|
41
|
+
"location_type": "chef_server",
|
42
|
+
"dependencies": {
|
43
|
+
|
44
|
+
}
|
45
|
+
}
|
46
|
+
},
|
47
|
+
"apt": {
|
48
|
+
"5.0.1": {
|
49
|
+
"location_path": "https://chef.example.com/organizations/example/cookbooks/apt/5.0.1",
|
50
|
+
"location_type": "chef_server",
|
51
|
+
"dependencies": {
|
52
|
+
"compat_resource": ">= 12.16.3"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"yum": {
|
3
|
+
"4.1.0": {
|
4
|
+
}
|
5
|
+
},
|
6
|
+
"windows": {
|
7
|
+
"2.1.1": {
|
8
|
+
"ohai": ">= 4.0.0"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"ubuntu": {
|
12
|
+
"2.0.0": {
|
13
|
+
"apt": ">= 0.0.0"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"ohai": {
|
17
|
+
"4.2.3": {
|
18
|
+
"compat_resource": ">= 12.14.7"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"compat_resource": {
|
22
|
+
"12.16.3": {
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"apt": {
|
26
|
+
"5.0.1": {
|
27
|
+
"compat_resource": ">= 12.16.3"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
@@ -16,19 +16,40 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require 'spec_helper'
|
19
|
-
|
20
19
|
require 'chef-dk/policyfile/chef_server_cookbook_source'
|
21
20
|
|
22
21
|
describe ChefDK::Policyfile::ChefServerCookbookSource do
|
22
|
+
subject { described_class.new(cookbook_source) }
|
23
23
|
|
24
|
-
let(:cookbook_source) {
|
24
|
+
let(:cookbook_source) { 'https://chef.example.com/organizations/example' }
|
25
25
|
|
26
|
-
|
27
|
-
expect { cookbook_source.universe_graph }.to raise_error(ChefDK::UnsupportedFeature)
|
28
|
-
end
|
26
|
+
let(:http_connection) { double('ChefDK::AuthenticatedHTTP') }
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
let(:universe_response_encoded) { JSON.parse(IO.read(File.join(fixtures_path, 'cookbooks_api/chef_server_universe.json'))) }
|
29
|
+
|
30
|
+
let(:pruned_universe) { JSON.parse(IO.read(File.join(fixtures_path, "cookbooks_api/pruned_chef_server_universe.json"))) }
|
33
31
|
|
32
|
+
describe 'fetching the Universe graph' do
|
33
|
+
|
34
|
+
before do
|
35
|
+
expect(subject).to receive(:http_connection_for).with(cookbook_source).and_return(http_connection)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'fetches the universe graph' do
|
39
|
+
expect(http_connection).to receive(:get).with('/universe').and_return(universe_response_encoded)
|
40
|
+
actual_universe = subject.universe_graph
|
41
|
+
expect(actual_universe).to have_key('apt')
|
42
|
+
expect(actual_universe['apt']).to eq(pruned_universe['apt'])
|
43
|
+
expect(subject.universe_graph).to eq(pruned_universe)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'generates location options for a cookbook from the given graph' do
|
47
|
+
expected_opts = {
|
48
|
+
chef_server: "https://chef.example.com/organizations/example",
|
49
|
+
http_client: http_connection,
|
50
|
+
version: "4.2.3"
|
51
|
+
}
|
52
|
+
expect(subject.source_options_for('ohai', '4.2.3')).to eq(expected_opts)
|
53
|
+
end
|
54
|
+
end
|
34
55
|
end
|