berkshelf 3.0.0.beta3 → 3.0.0.beta4
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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +12 -2
- data/CONTRIBUTING.md +53 -53
- data/Gemfile +1 -1
- data/Guardfile +12 -6
- data/PLUGINS.md +2 -2
- data/README.md +7 -11
- data/berkshelf.gemspec +1 -1
- data/features/commands/apply.feature +15 -4
- data/features/commands/cookbook.feature +1 -1
- data/features/commands/install.feature +85 -15
- data/features/commands/list.feature +35 -2
- data/features/commands/outdated.feature +3 -3
- data/features/commands/package.feature +1 -0
- data/features/commands/show.feature +3 -3
- data/features/commands/update.feature +1 -0
- data/features/commands/upload.feature +28 -4
- data/features/json_formatter.feature +2 -0
- data/features/lockfile.feature +1 -0
- data/features/support/env.rb +8 -4
- data/generator_files/Gemfile.erb +9 -0
- data/generator_files/README.md.erb +15 -33
- data/generator_files/Vagrantfile.erb +6 -3
- data/lib/berkshelf.rb +32 -2
- data/lib/berkshelf/berksfile.rb +59 -83
- data/lib/berkshelf/cli.rb +15 -67
- data/lib/berkshelf/community_rest.rb +18 -2
- data/lib/berkshelf/dependency.rb +6 -4
- data/lib/berkshelf/downloader.rb +3 -0
- data/lib/berkshelf/errors.rb +15 -0
- data/lib/berkshelf/formatters.rb +1 -0
- data/lib/berkshelf/formatters/human_readable.rb +27 -4
- data/lib/berkshelf/formatters/json.rb +21 -5
- data/lib/berkshelf/git.rb +4 -0
- data/lib/berkshelf/installer.rb +3 -1
- data/lib/berkshelf/locations/git_location.rb +22 -10
- data/lib/berkshelf/locations/github_location.rb +3 -7
- data/lib/berkshelf/locations/path_location.rb +0 -19
- data/lib/berkshelf/lockfile.rb +66 -4
- data/lib/berkshelf/mixin/logging.rb +1 -1
- data/lib/berkshelf/version.rb +1 -1
- data/spec/spec_helper.rb +8 -4
- data/spec/support/git.rb +9 -9
- data/spec/support/mercurial.rb +9 -9
- data/spec/unit/berkshelf/api_client_spec.rb +1 -1
- data/spec/unit/berkshelf/berksfile_spec.rb +36 -59
- data/spec/unit/berkshelf/cli_spec.rb +16 -0
- data/spec/unit/berkshelf/config_spec.rb +1 -1
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +4 -6
- data/spec/unit/berkshelf/locations/git_location_spec.rb +1 -1
- data/spec/unit/berkshelf/lockfile_spec.rb +81 -2
- data/spec/unit/berkshelf/resolver/graph_spec.rb +1 -1
- data/spec/unit/berkshelf/ui_spec.rb +4 -4
- metadata +7 -7
- data/features/commands/configure.feature +0 -89
@@ -3,11 +3,14 @@ Feature: berks list
|
|
3
3
|
Given the cookbook store has the cookbooks:
|
4
4
|
| fake1 | 1.0.0 |
|
5
5
|
| fake2 | 1.0.1 |
|
6
|
-
|
6
|
+
And I have a Berksfile pointing at the local Berkshelf API with:
|
7
7
|
"""
|
8
8
|
cookbook 'fake1', '1.0.0'
|
9
9
|
cookbook 'fake2', '1.0.1'
|
10
10
|
"""
|
11
|
+
And the Lockfile has:
|
12
|
+
| fake1 | 1.0.0 |
|
13
|
+
| fake2 | 1.0.1 |
|
11
14
|
When I successfully run `berks list`
|
12
15
|
Then the output should contain:
|
13
16
|
"""
|
@@ -17,7 +20,37 @@ Feature: berks list
|
|
17
20
|
"""
|
18
21
|
|
19
22
|
|
20
|
-
Scenario: Running the list command
|
23
|
+
Scenario: Running the list command when the dependencies aren't downloaded
|
24
|
+
And I have a Berksfile pointing at the local Berkshelf API with:
|
25
|
+
"""
|
26
|
+
cookbook 'fake', '1.0.0'
|
27
|
+
"""
|
28
|
+
And the Lockfile has:
|
29
|
+
| fake | 1.0.0 |
|
30
|
+
When I run `berks list`
|
31
|
+
Then the output should contain:
|
32
|
+
"""
|
33
|
+
Could not find cookbook 'fake (1.0.0)'.
|
34
|
+
"""
|
35
|
+
And the exit status should be "CookbookNotFound"
|
36
|
+
|
37
|
+
|
38
|
+
Scenario: Running the list command when the lockfile isn't present
|
39
|
+
Given the cookbook store has the cookbooks:
|
40
|
+
| fake | 1.0.0 |
|
41
|
+
And I have a Berksfile pointing at the local Berkshelf API with:
|
42
|
+
"""
|
43
|
+
cookbook 'fake', '1.0.0'
|
44
|
+
"""
|
45
|
+
When I run `berks list`
|
46
|
+
Then the output should contain:
|
47
|
+
"""
|
48
|
+
Could not find cookbook 'fake (= 1.0.0)'.
|
49
|
+
"""
|
50
|
+
And the exit status should be "CookbookNotFound"
|
51
|
+
|
52
|
+
|
53
|
+
Scenario: Running the list command with no dependencies defined
|
21
54
|
Given I have a Berksfile pointing at the local Berkshelf API
|
22
55
|
When I successfully run `berks list`
|
23
56
|
Then the output should contain:
|
@@ -70,9 +70,9 @@ Feature: berks outdated
|
|
70
70
|
When I run `berks outdated`
|
71
71
|
Then the output should contain:
|
72
72
|
"""
|
73
|
-
Could not find cookbook 'bacon (
|
73
|
+
Could not find cookbook 'bacon (= 1.0.0)'. Try running `berks install` to download and install the missing dependencies.
|
74
74
|
"""
|
75
|
-
And the exit status should be "
|
75
|
+
And the exit status should be "CookbookNotFound"
|
76
76
|
|
77
77
|
|
78
78
|
Scenario: When the cookbook is not installed
|
@@ -85,6 +85,6 @@ Feature: berks outdated
|
|
85
85
|
When I run `berks outdated`
|
86
86
|
Then the output should contain:
|
87
87
|
"""
|
88
|
-
Could not find cookbook 'bacon (
|
88
|
+
Could not find cookbook 'bacon (1.0.0)'. Try running `berks install` to download and install the missing dependencies.
|
89
89
|
"""
|
90
90
|
And the exit status should be "CookbookNotFound"
|
@@ -38,9 +38,9 @@ Feature: berks show
|
|
38
38
|
When I run `berks show fake`
|
39
39
|
Then the output should contain:
|
40
40
|
"""
|
41
|
-
Could not find cookbook 'fake (
|
41
|
+
Could not find cookbook 'fake (= 1.0.0)'. Try running `berks install` to download and install the missing dependencies.
|
42
42
|
"""
|
43
|
-
And the exit status should be "
|
43
|
+
And the exit status should be "CookbookNotFound"
|
44
44
|
|
45
45
|
|
46
46
|
Scenario: When the cookbook is not installed
|
@@ -54,6 +54,6 @@ Feature: berks show
|
|
54
54
|
When I run `berks show fake`
|
55
55
|
Then the output should contain:
|
56
56
|
"""
|
57
|
-
Could not find cookbook 'fake (
|
57
|
+
Could not find cookbook 'fake (1.0.0)'. Try running `berks install` to download and install the missing dependencies.
|
58
58
|
"""
|
59
59
|
And the exit status should be "CookbookNotFound"
|
@@ -168,11 +168,11 @@ Feature: berks upload
|
|
168
168
|
When I successfully run `berks upload`
|
169
169
|
Then the output should contain:
|
170
170
|
"""
|
171
|
-
Skipping fake (1.0.0) (
|
171
|
+
Skipping fake (1.0.0) (frozen)
|
172
172
|
"""
|
173
173
|
And the output should contain:
|
174
174
|
"""
|
175
|
-
Skipped uploading some cookbooks because they already
|
175
|
+
Skipped uploading some cookbooks because they already exist on the remote server and are frozen. Re-run with the `--force` flag to force overwrite these cookbooks:
|
176
176
|
|
177
177
|
* fake (1.0.0)
|
178
178
|
"""
|
@@ -190,8 +190,32 @@ Feature: berks upload
|
|
190
190
|
When I successfully run `berks upload`
|
191
191
|
Then the output should contain:
|
192
192
|
"""
|
193
|
-
Skipping fake (0.0.0) (
|
194
|
-
Skipped uploading some cookbooks because they already
|
193
|
+
Skipping fake (0.0.0) (frozen)
|
194
|
+
Skipped uploading some cookbooks because they already exist on the remote server and are frozen. Re-run with the `--force` flag to force overwrite these cookbooks:
|
195
195
|
|
196
196
|
* fake (0.0.0)
|
197
197
|
"""
|
198
|
+
Scenario: When the syntax check is skipped
|
199
|
+
Given a cookbook named "fake"
|
200
|
+
And the cookbook "fake" has the file "recipes/default.rb" with:
|
201
|
+
"""
|
202
|
+
Totally not valid Ruby syntax
|
203
|
+
"""
|
204
|
+
And the cookbook "fake" has the file "templates/default/file.erb" with:
|
205
|
+
"""
|
206
|
+
<% for %>
|
207
|
+
"""
|
208
|
+
And the cookbook "fake" has the file "recipes/template.rb" with:
|
209
|
+
"""
|
210
|
+
template "/tmp/wadus" do
|
211
|
+
source "file.erb"
|
212
|
+
end
|
213
|
+
"""
|
214
|
+
And the cookbook "fake" has the file "Berksfile" with:
|
215
|
+
"""
|
216
|
+
metadata
|
217
|
+
"""
|
218
|
+
And I cd to "fake"
|
219
|
+
When I successfully run `berks upload --skip-syntax-check`
|
220
|
+
Then the Chef Server should have the cookbooks:
|
221
|
+
| fake | 0.0.0 |
|
data/features/lockfile.feature
CHANGED
data/features/support/env.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'spork'
|
2
2
|
|
3
|
+
def windows?
|
4
|
+
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
5
|
+
end
|
6
|
+
|
3
7
|
Spork.prefork do
|
4
8
|
require 'aruba/cucumber'
|
5
9
|
require 'aruba/in_process'
|
6
10
|
require 'aruba/spawn_process'
|
7
11
|
require 'cucumber/rspec/doubles'
|
8
|
-
require 'berkshelf/api/rspec'
|
9
|
-
require 'berkshelf/api/cucumber'
|
12
|
+
require 'berkshelf/api/rspec' unless windows?
|
13
|
+
require 'berkshelf/api/cucumber' unless windows?
|
10
14
|
|
11
15
|
Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
|
12
16
|
|
@@ -18,7 +22,7 @@ Spork.prefork do
|
|
18
22
|
|
19
23
|
at_exit do
|
20
24
|
Berkshelf::RSpec::ChefServer.stop
|
21
|
-
Berkshelf::API::RSpec::Server.stop
|
25
|
+
Berkshelf::API::RSpec::Server.stop unless windows?
|
22
26
|
end
|
23
27
|
|
24
28
|
Before do
|
@@ -50,7 +54,7 @@ Spork.prefork do
|
|
50
54
|
]
|
51
55
|
|
52
56
|
Berkshelf::RSpec::ChefServer.start(port: CHEF_SERVER_PORT)
|
53
|
-
Berkshelf::API::RSpec::Server.start(port: BERKS_API_PORT, endpoints: endpoints)
|
57
|
+
Berkshelf::API::RSpec::Server.start(port: BERKS_API_PORT, endpoints: endpoints) unless windows?
|
54
58
|
|
55
59
|
@aruba_io_wait_seconds = Cucumber::JRUBY ? 7 : 5
|
56
60
|
@aruba_timeout_seconds = Cucumber::JRUBY ? 35 : 15
|
data/generator_files/Gemfile.erb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'berkshelf'
|
4
|
+
|
5
|
+
# Uncomment these lines (and the ones in the generated Vagrantfile) if you want
|
6
|
+
# to live on the Edge:
|
7
|
+
#
|
8
|
+
# gem "berkshelf", github: "RiotGames/berkshelf"
|
9
|
+
# gem "vagrant", github: "mitchellh/vagrant", tag: "v1.3.5"
|
10
|
+
# gem "vagrant-berkshelf", github: "RiotGames/vagrant-berkshelf"
|
11
|
+
# gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus", tag: "v1.1.2"
|
12
|
+
|
4
13
|
<% if options[:foodcritic] -%>
|
5
14
|
gem 'thor-foodcritic'
|
6
15
|
<% end -%>
|
@@ -1,24 +1,13 @@
|
|
1
|
-
<%= name
|
2
|
-
<%= '='*"#{name} cookbook".length %>
|
3
|
-
TODO: Enter the cookbook description here.
|
1
|
+
# <%= name %>-cookbook
|
4
2
|
|
5
|
-
|
6
|
-
This cookbook makes your favorite breakfast sandwich.
|
3
|
+
TODO: Enter the cookbook description here.
|
7
4
|
|
8
|
-
|
9
|
-
------------
|
10
|
-
TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
|
5
|
+
## Supported Platforms
|
11
6
|
|
12
|
-
|
13
|
-
#### packages
|
14
|
-
- `toaster` - <%= name %> needs toaster to brown your bagel.
|
7
|
+
TODO: List your supported platforms.
|
15
8
|
|
16
|
-
Attributes
|
17
|
-
----------
|
18
|
-
TODO: List you cookbook attributes here.
|
9
|
+
## Attributes
|
19
10
|
|
20
|
-
e.g.
|
21
|
-
#### <%= name %>::default
|
22
11
|
<table>
|
23
12
|
<tr>
|
24
13
|
<th>Key</th>
|
@@ -34,36 +23,29 @@ e.g.
|
|
34
23
|
</tr>
|
35
24
|
</table>
|
36
25
|
|
37
|
-
Usage
|
38
|
-
|
39
|
-
|
40
|
-
TODO: Write usage instructions for each cookbook.
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### <%= name %>::default
|
41
29
|
|
42
|
-
|
43
|
-
Just include `<%= name %>` in your node's `run_list`:
|
30
|
+
Include `<%= name %>` in your node's `run_list`:
|
44
31
|
|
45
32
|
```json
|
46
33
|
{
|
47
|
-
"name":"my_node",
|
48
34
|
"run_list": [
|
49
|
-
"recipe[<%= name
|
35
|
+
"recipe[<%= name %>::default]"
|
50
36
|
]
|
51
37
|
}
|
52
38
|
```
|
53
39
|
|
54
|
-
Contributing
|
55
|
-
------------
|
56
|
-
TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
|
57
|
-
|
58
|
-
e.g.
|
40
|
+
## Contributing
|
59
41
|
|
60
42
|
1. Fork the repository on Github
|
61
|
-
2. Create a named feature branch (
|
43
|
+
2. Create a named feature branch (i.e. `add-new-recipe`)
|
62
44
|
3. Write you change
|
63
45
|
4. Write tests for your change (if applicable)
|
64
46
|
5. Run the tests, ensuring they all pass
|
65
|
-
6. Submit a Pull Request
|
47
|
+
6. Submit a Pull Request
|
48
|
+
|
49
|
+
## License and Authors
|
66
50
|
|
67
|
-
License and Authors
|
68
|
-
-------------------
|
69
51
|
Author:: <%= maintainer %> (<<%= maintainer_email %>>)
|
@@ -1,6 +1,12 @@
|
|
1
1
|
# -*- mode: ruby -*-
|
2
2
|
# vi: set ft=ruby :
|
3
3
|
|
4
|
+
# Uncomment these lines (and the ones in the generated Gemfile) if you want
|
5
|
+
# to live on the Edge:
|
6
|
+
#
|
7
|
+
# Vagrant.require_plugin "vagrant-berkshelf"
|
8
|
+
# Vagrant.require_plugin "vagrant-omnibus"
|
9
|
+
|
4
10
|
Vagrant.configure("2") do |config|
|
5
11
|
# All Vagrant configuration is done here. The most common configuration
|
6
12
|
# options are documented and commented below. For a complete reference,
|
@@ -73,9 +79,6 @@ Vagrant.configure("2") do |config|
|
|
73
79
|
# View the documentation for the provider you're using for more
|
74
80
|
# information on available options.
|
75
81
|
|
76
|
-
config.ssh.max_tries = 40
|
77
|
-
config.ssh.timeout = 120
|
78
|
-
|
79
82
|
# The path to the Berksfile to use with Vagrant Berkshelf
|
80
83
|
# config.berkshelf.berksfile_path = "./Berksfile"
|
81
84
|
|
data/lib/berkshelf.rb
CHANGED
@@ -18,6 +18,7 @@ require_relative 'berkshelf/core_ext'
|
|
18
18
|
require_relative 'berkshelf/thor_ext'
|
19
19
|
|
20
20
|
module Berkshelf
|
21
|
+
require_relative 'berkshelf/version'
|
21
22
|
require_relative 'berkshelf/errors'
|
22
23
|
require_relative 'berkshelf/mixin'
|
23
24
|
|
@@ -113,6 +114,36 @@ module Berkshelf
|
|
113
114
|
@formatter ||= Formatters::HumanReadable.new
|
114
115
|
end
|
115
116
|
|
117
|
+
# @raise [Berkshelf::ChefConnectionError]
|
118
|
+
def ridley_connection(options = {}, &block)
|
119
|
+
ridley_options = options.slice(:ssl)
|
120
|
+
|
121
|
+
ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url
|
122
|
+
ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name
|
123
|
+
ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key
|
124
|
+
ridley_options[:ssl] = { verify: (options[:ssl_verify].nil?) ? Berkshelf.config.ssl.verify : options[:ssl_verify]}
|
125
|
+
|
126
|
+
unless ridley_options[:server_url].present?
|
127
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.server_url'
|
128
|
+
end
|
129
|
+
|
130
|
+
unless ridley_options[:client_name].present?
|
131
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.node_name'
|
132
|
+
end
|
133
|
+
|
134
|
+
unless ridley_options[:client_key].present?
|
135
|
+
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.client_key'
|
136
|
+
end
|
137
|
+
|
138
|
+
# @todo Something scary going on here - getting an instance of Kitchen::Logger from test-kitchen
|
139
|
+
# https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
|
140
|
+
Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
|
141
|
+
Ridley.open(ridley_options, &block)
|
142
|
+
rescue Ridley::Errors::RidleyError => ex
|
143
|
+
log_exception(ex)
|
144
|
+
raise ChefConnectionError, ex # todo implement
|
145
|
+
end
|
146
|
+
|
116
147
|
# Specify the format for output
|
117
148
|
#
|
118
149
|
# @param [#to_sym] format_id
|
@@ -138,6 +169,7 @@ module Berkshelf
|
|
138
169
|
end
|
139
170
|
end
|
140
171
|
|
172
|
+
require_relative 'berkshelf/lockfile'
|
141
173
|
require_relative 'berkshelf/api_client'
|
142
174
|
require_relative 'berkshelf/base_generator'
|
143
175
|
require_relative 'berkshelf/berksfile'
|
@@ -155,13 +187,11 @@ require_relative 'berkshelf/mercurial'
|
|
155
187
|
require_relative 'berkshelf/init_generator'
|
156
188
|
require_relative 'berkshelf/installer'
|
157
189
|
require_relative 'berkshelf/location'
|
158
|
-
require_relative 'berkshelf/lockfile'
|
159
190
|
require_relative 'berkshelf/logger'
|
160
191
|
require_relative 'berkshelf/resolver'
|
161
192
|
require_relative 'berkshelf/source'
|
162
193
|
require_relative 'berkshelf/source_uri'
|
163
194
|
require_relative 'berkshelf/ui'
|
164
|
-
require_relative 'berkshelf/version'
|
165
195
|
|
166
196
|
Ridley.logger = Berkshelf.logger = Logger.new(STDOUT)
|
167
197
|
Berkshelf.logger.level = Logger::WARN
|
data/lib/berkshelf/berksfile.rb
CHANGED
@@ -42,19 +42,15 @@ module Berkshelf
|
|
42
42
|
# The path on disk to the file representing this instance of Berksfile
|
43
43
|
attr_reader :filepath
|
44
44
|
|
45
|
-
# @return [Array<Berkshelf::CachedCookbook>]
|
46
|
-
attr_reader :cached_cookbooks
|
47
|
-
|
48
45
|
# @param [String] path
|
49
46
|
# path on disk to the file containing the contents of this Berksfile
|
50
47
|
def initialize(path)
|
51
48
|
@filepath = path
|
52
49
|
@dependencies = Hash.new
|
53
|
-
@cached_cookbooks = nil
|
54
50
|
@sources = Array.new
|
55
51
|
end
|
56
52
|
|
57
|
-
# Add a cookbook dependency to the Berksfile to be retrieved and have
|
53
|
+
# Add a cookbook dependency to the Berksfile to be retrieved and have its dependencies recursively retrieved
|
58
54
|
# and resolved.
|
59
55
|
#
|
60
56
|
# @example a cookbook dependency that will be retrieved from one of the default locations
|
@@ -162,14 +158,14 @@ module Berkshelf
|
|
162
158
|
Berkshelf.formatter.deprecation "Your Berksfile contains a site location pointing to the Opscode Community " +
|
163
159
|
"Site (site :opscode). Site locations have been replaced by the source location. Change this to: " +
|
164
160
|
"'source \"http://api.berkshelf.com\" to remove this warning. For more information visit " +
|
165
|
-
"https://github.com/
|
161
|
+
"https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
|
166
162
|
source(DEFAULT_API_URL)
|
167
163
|
return
|
168
164
|
end
|
169
165
|
|
170
166
|
raise Berkshelf::DeprecatedError.new "Your Berksfile contains a site location. Site locations have been " +
|
171
167
|
" replaced by the source location. Please remove your site location and try again. For more information " +
|
172
|
-
" visit https://github.com/
|
168
|
+
" visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
|
173
169
|
end
|
174
170
|
|
175
171
|
# @todo remove in Berkshelf 4.0
|
@@ -178,7 +174,7 @@ module Berkshelf
|
|
178
174
|
def chef_api(*args)
|
179
175
|
raise Berkshelf::DeprecatedError.new "Your Berksfile contains a chef_api location. Chef API locations have " +
|
180
176
|
" been replaced by the source location. Please remove your site location and try again. For more " +
|
181
|
-
" information visit https://github.com/
|
177
|
+
" information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
|
182
178
|
end
|
183
179
|
|
184
180
|
# Add a dependency of the given name and constraint to the array of dependencies.
|
@@ -276,6 +272,12 @@ module Berkshelf
|
|
276
272
|
@dependencies[name]
|
277
273
|
end
|
278
274
|
|
275
|
+
# Find a dependency, raising an exception if it is not found.
|
276
|
+
# @see {find}
|
277
|
+
def find!(name)
|
278
|
+
find(name) || raise(DependencyNotFound.new(name))
|
279
|
+
end
|
280
|
+
|
279
281
|
# @return [Hash]
|
280
282
|
# a hash containing group names as keys and an array of Berkshelf::Dependencies
|
281
283
|
# that are a member of that group as values
|
@@ -376,29 +378,41 @@ module Berkshelf
|
|
376
378
|
# @raise [CookbookNotFound]
|
377
379
|
# if there is a lockfile with a cookbook, but the cookbook is not downloaded
|
378
380
|
#
|
379
|
-
# @param [
|
381
|
+
# @param [Dependency] name
|
380
382
|
# the name of the cookbook to find
|
381
383
|
#
|
382
384
|
# @return [CachedCookbook]
|
383
385
|
# the CachedCookbook that corresponds to the given name parameter
|
384
|
-
def retrieve_locked(
|
385
|
-
|
386
|
+
def retrieve_locked(dependency)
|
387
|
+
locked = lockfile.find(dependency.name)
|
386
388
|
|
387
|
-
locked = lockfile.find(name)
|
388
389
|
unless locked
|
389
|
-
raise
|
390
|
+
raise CookbookNotFound, "Could not find cookbook '#{dependency.to_s}'."\
|
390
391
|
" Try running `berks install` to download and install the missing"\
|
391
392
|
" dependencies."
|
392
393
|
end
|
393
394
|
|
394
|
-
|
395
|
-
|
396
|
-
raise CookbookNotFound, "Could not find cookbook '#{name} (= #{locked.locked_version})'."\
|
395
|
+
unless locked.downloaded?
|
396
|
+
raise CookbookNotFound, "Could not find cookbook '#{locked.to_s}'."\
|
397
397
|
" Try running `berks install` to download and install the missing"\
|
398
398
|
" dependencies."
|
399
399
|
end
|
400
400
|
|
401
|
-
|
401
|
+
@dependencies[dependency.name] = locked
|
402
|
+
locked.cached_cookbook
|
403
|
+
end
|
404
|
+
|
405
|
+
# The cached cookbooks installed by this Berksfile.
|
406
|
+
#
|
407
|
+
# @raise [Berkshelf::LockfileNotFound]
|
408
|
+
# if there is no lockfile
|
409
|
+
# @raise [Berkshelf::CookbookNotFound]
|
410
|
+
# if a listed source could not be found
|
411
|
+
#
|
412
|
+
# @return [Hash<Berkshelf::Dependency, Berkshelf::CachedCookbook>]
|
413
|
+
# the list of dependencies as keys and the cached cookbook as the value
|
414
|
+
def list
|
415
|
+
Hash[*dependencies.sort.collect { |dependency| [dependency, retrieve_locked(dependency)] }.flatten]
|
402
416
|
end
|
403
417
|
|
404
418
|
# List of all the cookbooks which have a newer version found at a source that satisfies
|
@@ -426,7 +440,7 @@ module Berkshelf
|
|
426
440
|
|
427
441
|
outdated = {}
|
428
442
|
dependencies(options).each do |dependency|
|
429
|
-
locked = retrieve_locked(dependency
|
443
|
+
locked = retrieve_locked(dependency)
|
430
444
|
outdated[dependency.name] = {}
|
431
445
|
|
432
446
|
sources.each do |source|
|
@@ -488,6 +502,7 @@ module Berkshelf
|
|
488
502
|
halt_on_frozen: false,
|
489
503
|
skip_dependencies: false,
|
490
504
|
cookbooks: [],
|
505
|
+
validate: true
|
491
506
|
}.merge(options)
|
492
507
|
|
493
508
|
validate_cookbook_names!(options)
|
@@ -497,34 +512,6 @@ module Berkshelf
|
|
497
512
|
do_upload(cached_cookbooks, options)
|
498
513
|
end
|
499
514
|
|
500
|
-
# Resolve this Berksfile and apply the locks found in the generated Berksfile.lock to the
|
501
|
-
# target Chef environment
|
502
|
-
#
|
503
|
-
# @param [String] environment_name
|
504
|
-
#
|
505
|
-
# @option options [Hash] :ssl_verify (true)
|
506
|
-
# Disable/Enable SSL verification during uploads
|
507
|
-
#
|
508
|
-
# @raise [EnvironmentNotFound]
|
509
|
-
# if the target environment was not found
|
510
|
-
# @raise [ChefConnectionError]
|
511
|
-
# if you are locking cookbooks with an invalid or not-specified client configuration
|
512
|
-
def apply(environment_name, options = {})
|
513
|
-
ridley_connection(options) do |conn|
|
514
|
-
unless environment = conn.environment.find(environment_name)
|
515
|
-
raise EnvironmentNotFound.new(environment_name)
|
516
|
-
end
|
517
|
-
|
518
|
-
install
|
519
|
-
|
520
|
-
environment.cookbook_versions = {}.tap do |cookbook_versions|
|
521
|
-
lockfile.dependencies.each { |dependency| cookbook_versions[dependency.name] = dependency.locked_version }
|
522
|
-
end
|
523
|
-
|
524
|
-
environment.save
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
515
|
# Package the given cookbook for distribution outside of berkshelf. If the
|
529
516
|
# name attribute is not given, all cookbooks in the Berksfile will be
|
530
517
|
# packaged.
|
@@ -627,18 +614,33 @@ module Berkshelf
|
|
627
614
|
src = cookbook.path.to_s.gsub('\\', '/')
|
628
615
|
files = Dir.glob(File.join(src, '*'))
|
629
616
|
|
630
|
-
|
631
|
-
|
617
|
+
chefignore = Ridley::Chef::Chefignore.new(cookbook.path.to_s) rescue nil
|
618
|
+
chefignore.apply!(files) if chefignore
|
619
|
+
|
620
|
+
unless cookbook.compiled_metadata?
|
621
|
+
cookbook.compile_metadata(cookbook_destination)
|
632
622
|
end
|
633
623
|
|
634
|
-
|
624
|
+
# Don't vendor the raw metadata (metadata.rb). The raw metadata is unecessary for the
|
625
|
+
# client, and this is required until compiled metadata (metadata.json) takes precedence over
|
626
|
+
# raw metadata in the Chef-Client.
|
627
|
+
#
|
628
|
+
# We can change back to including the raw metadata in the future after this has been fixed or
|
629
|
+
# just remove these comments. There is no circumstance that I can currently think of where
|
630
|
+
# raw metadata should ever be read by the client.
|
631
|
+
#
|
632
|
+
# - Jamie
|
633
|
+
#
|
634
|
+
# See the following tickets for more information:
|
635
|
+
# * https://tickets.opscode.com/browse/CHEF-4811
|
636
|
+
# * https://tickets.opscode.com/browse/CHEF-4810
|
637
|
+
files.reject! { |file| File.basename(file) == "metadata.rb" }
|
635
638
|
|
636
|
-
|
637
|
-
Dir["#{cookbook_destination}/**/*"].each do |path|
|
638
|
-
FileUtils.rm_rf(path) if chefignore.ignored?(path)
|
639
|
-
end if chefignore
|
639
|
+
FileUtils.cp_r(files, cookbook_destination)
|
640
640
|
end
|
641
641
|
|
642
|
+
FileUtils.cp(lockfile.filepath, File.join(scratch, Lockfile::DEFAULT_FILENAME))
|
643
|
+
|
642
644
|
FileUtils.mv(scratch, destination)
|
643
645
|
destination
|
644
646
|
end
|
@@ -651,7 +653,7 @@ module Berkshelf
|
|
651
653
|
# the lockfile corresponding to this berksfile, or a new Lockfile if one does
|
652
654
|
# not exist
|
653
655
|
def lockfile
|
654
|
-
@lockfile ||=
|
656
|
+
@lockfile ||= Lockfile.from_berksfile(self)
|
655
657
|
end
|
656
658
|
|
657
659
|
private
|
@@ -659,7 +661,7 @@ module Berkshelf
|
|
659
661
|
def do_upload(cookbooks, options = {})
|
660
662
|
@skipped = []
|
661
663
|
|
662
|
-
ridley_connection(options) do |conn|
|
664
|
+
Berkshelf.ridley_connection(options) do |conn|
|
663
665
|
cookbooks.each do |cookbook|
|
664
666
|
Berkshelf.formatter.upload(cookbook, conn)
|
665
667
|
validate_files!(cookbook)
|
@@ -669,6 +671,7 @@ module Berkshelf
|
|
669
671
|
force: options[:force],
|
670
672
|
freeze: options[:freeze],
|
671
673
|
name: cookbook.cookbook_name,
|
674
|
+
validate: options[:validate]
|
672
675
|
})
|
673
676
|
rescue Ridley::Errors::FrozenCookbook => ex
|
674
677
|
if options[:halt_on_frozen]
|
@@ -683,7 +686,7 @@ module Berkshelf
|
|
683
686
|
|
684
687
|
unless @skipped.empty?
|
685
688
|
Berkshelf.formatter.msg "Skipped uploading some cookbooks because they" <<
|
686
|
-
" already
|
689
|
+
" already exist on the remote server and are frozen. Re-run with the `--force`" <<
|
687
690
|
" flag to force overwrite these cookbooks:" <<
|
688
691
|
"\n\n" <<
|
689
692
|
" * " << @skipped.map { |c| "#{c.cookbook_name} (#{c.version})" }.join("\n * ")
|
@@ -713,33 +716,6 @@ module Berkshelf
|
|
713
716
|
cookbooks
|
714
717
|
end
|
715
718
|
|
716
|
-
# @raise [Berkshelf::ChefConnectionError]
|
717
|
-
def ridley_connection(options = {}, &block)
|
718
|
-
ridley_options = options.slice(:ssl)
|
719
|
-
|
720
|
-
ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url
|
721
|
-
ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name
|
722
|
-
ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key
|
723
|
-
ridley_options[:ssl] = { verify: (options[:ssl_verify].nil?) ? Berkshelf.config.ssl.verify : options[:ssl_verify]}
|
724
|
-
|
725
|
-
unless ridley_options[:server_url].present?
|
726
|
-
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.server_url'
|
727
|
-
end
|
728
|
-
|
729
|
-
unless ridley_options[:client_name].present?
|
730
|
-
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.node_name'
|
731
|
-
end
|
732
|
-
|
733
|
-
unless ridley_options[:client_key].present?
|
734
|
-
raise ChefConnectionError, 'Missing required attribute in your Berkshelf configuration: chef.client_key'
|
735
|
-
end
|
736
|
-
|
737
|
-
Ridley.open(ridley_options, &block)
|
738
|
-
rescue Ridley::Errors::RidleyError => ex
|
739
|
-
log_exception(ex)
|
740
|
-
raise ChefConnectionError, ex # todo implement
|
741
|
-
end
|
742
|
-
|
743
719
|
# Determine if any cookbooks were specified that aren't in our shelf.
|
744
720
|
#
|
745
721
|
# @option options [Array<String>] :cookbooks
|