berkshelf 6.3.4 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +10 -0
  4. data/.travis.yml +6 -8
  5. data/CHANGELOG.md +7 -19
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +68 -103
  8. data/Thorfile +2 -2
  9. data/berkshelf.gemspec +6 -8
  10. data/features/commands/info.feature +50 -8
  11. data/features/commands/shelf/show.feature +10 -40
  12. data/features/commands/upload.feature +73 -0
  13. data/features/commands/vendor.feature +43 -0
  14. data/features/json_formatter.feature +1 -1
  15. data/features/step_definitions/chef_server_steps.rb +2 -2
  16. data/features/step_definitions/filesystem_steps.rb +16 -0
  17. data/features/support/env.rb +11 -10
  18. data/lib/berkshelf.rb +15 -20
  19. data/lib/berkshelf/berksfile.rb +57 -47
  20. data/lib/berkshelf/cached_cookbook.rb +120 -19
  21. data/lib/berkshelf/chef_config_compat.rb +50 -0
  22. data/lib/berkshelf/chef_repo_universe.rb +2 -2
  23. data/lib/berkshelf/cli.rb +3 -42
  24. data/lib/berkshelf/community_rest.rb +40 -61
  25. data/lib/berkshelf/config.rb +92 -118
  26. data/lib/berkshelf/cookbook_store.rb +3 -2
  27. data/lib/berkshelf/core_ext/file.rb +1 -1
  28. data/lib/berkshelf/dependency.rb +1 -10
  29. data/lib/berkshelf/downloader.rb +19 -7
  30. data/lib/berkshelf/errors.rb +3 -0
  31. data/lib/berkshelf/location.rb +1 -1
  32. data/lib/berkshelf/locations/base.rb +1 -1
  33. data/lib/berkshelf/lockfile.rb +17 -13
  34. data/lib/berkshelf/logger.rb +62 -1
  35. data/lib/berkshelf/packager.rb +1 -1
  36. data/lib/berkshelf/resolver.rb +1 -1
  37. data/lib/berkshelf/ridley_compat.rb +22 -3
  38. data/lib/berkshelf/uploader.rb +76 -48
  39. data/lib/berkshelf/version.rb +1 -1
  40. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  41. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  42. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  43. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  44. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  45. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  46. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/support/chef_api.rb +4 -4
  49. data/spec/support/chef_server.rb +1 -1
  50. data/spec/support/matchers/file_system_matchers.rb +1 -3
  51. data/spec/support/path_helpers.rb +1 -1
  52. data/spec/unit/berkshelf/berksfile_spec.rb +3 -24
  53. data/spec/unit/berkshelf/cached_cookbook_spec.rb +13 -15
  54. data/spec/unit/berkshelf/community_rest_spec.rb +3 -12
  55. data/spec/unit/berkshelf/config_spec.rb +4 -4
  56. data/spec/unit/berkshelf/downloader_spec.rb +6 -11
  57. data/spec/unit/berkshelf/lockfile_spec.rb +10 -7
  58. data/spec/unit/berkshelf/source_spec.rb +1 -1
  59. data/spec/unit/berkshelf/ssl_policies_spec.rb +2 -5
  60. data/spec/unit/berkshelf/uploader_spec.rb +60 -10
  61. data/spec/unit/berkshelf/visualizer_spec.rb +2 -2
  62. metadata +49 -102
  63. data/features/commands/cookbook.feature +0 -35
  64. data/features/commands/init.feature +0 -27
  65. data/features/config.feature +0 -111
  66. data/lib/berkshelf/base_generator.rb +0 -42
  67. data/lib/berkshelf/cookbook_generator.rb +0 -133
  68. data/lib/berkshelf/init_generator.rb +0 -195
  69. data/lib/berkshelf/streaming_file_adapter.rb +0 -22
  70. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -108
  71. data/spec/unit/berkshelf/init_generator_spec.rb +0 -265
@@ -19,10 +19,7 @@
19
19
  """
20
20
  Name: fake
21
21
  Version: 1.0.0
22
- Description: A fabulous new cookbook
23
- Author: YOUR_COMPANY_NAME
24
- Email: YOUR_EMAIL
25
- License: none
22
+ License: All rights reserved
26
23
  """
27
24
 
28
25
  Scenario: When the parameter is a transitive dependency
@@ -50,10 +47,7 @@
50
47
  """
51
48
  Name: dep
52
49
  Version: 1.0.0
53
- Description: A fabulous new cookbook
54
- Author: YOUR_COMPANY_NAME
55
- Email: YOUR_EMAIL
56
- License: none
50
+ License: All rights reserved
57
51
  """
58
52
 
59
53
  Scenario: When the cookbook is not in the Berksfile
@@ -97,3 +91,51 @@
97
91
  Cookbook 'fake' (1.0.0) not found in the cookbook store!
98
92
  """
99
93
  And the exit status should be "CookbookNotFound"
94
+
95
+ Scenario: When the cookbook is a vendored cookbook
96
+ Given the cookbook store has the cookbooks:
97
+ | fake | 1.0.0 |
98
+ And I have a Berksfile pointing at the local Berkshelf API with:
99
+ """
100
+ cookbook 'fake', '1.0.0'
101
+ """
102
+ And I write to "Berksfile.lock" with:
103
+ """
104
+ DEPENDENCIES
105
+ fake (= 1.0.0)
106
+
107
+ GRAPH
108
+ fake (1.0.0)
109
+ """
110
+ And the cookbook store cookbook "fake" "1.0.0" is vendored without a metadata.rb
111
+ When I successfully run `berks info fake`
112
+ Then the output should contain:
113
+ """
114
+ Name: fake
115
+ Version: 1.0.0
116
+ License: All rights reserved
117
+ """
118
+
119
+ Scenario: When the cookbook is a vendored cookbook
120
+ Given the cookbook store has the cookbooks:
121
+ | fake | 1.0.0 |
122
+ And I have a Berksfile pointing at the local Berkshelf API with:
123
+ """
124
+ cookbook 'fake', '1.0.0'
125
+ """
126
+ And I write to "Berksfile.lock" with:
127
+ """
128
+ DEPENDENCIES
129
+ fake (= 1.0.0)
130
+
131
+ GRAPH
132
+ fake (1.0.0)
133
+ """
134
+ And the cookbook store cookbook "fake" "1.0.0" is vendored with a metadata.rb
135
+ When I successfully run `berks info fake`
136
+ Then the output should contain:
137
+ """
138
+ Name: fake
139
+ Version: 1.0.0
140
+ License: All rights reserved
141
+ """
@@ -17,10 +17,7 @@ Feature: berks shelf show
17
17
  Displaying all versions of 'fake' in the Berkshelf shelf:
18
18
  Name: fake
19
19
  Version: 1.0.0
20
- Description: A fabulous new cookbook
21
- Author: YOUR_COMPANY_NAME
22
- Email: YOUR_EMAIL
23
- License: none
20
+ License: All rights reserved
24
21
  """
25
22
  And the output should not contain:
26
23
  """
@@ -37,10 +34,7 @@ Feature: berks shelf show
37
34
  Displaying 'fake' (1.0.0) in the Berkshelf shelf:
38
35
  Name: fake
39
36
  Version: 1.0.0
40
- Description: A fabulous new cookbook
41
- Author: YOUR_COMPANY_NAME
42
- Email: YOUR_EMAIL
43
- License: none
37
+ License: All rights reserved
44
38
  """
45
39
  And the output should not contain:
46
40
  """
@@ -70,31 +64,19 @@ Feature: berks shelf show
70
64
  Displaying all versions of 'fake' in the Berkshelf shelf:
71
65
  Name: fake
72
66
  Version: 1.0.0
73
- Description: A fabulous new cookbook
74
- Author: YOUR_COMPANY_NAME
75
- Email: YOUR_EMAIL
76
- License: none
67
+ License: All rights reserved
77
68
 
78
69
  Name: fake
79
70
  Version: 1.1.0
80
- Description: A fabulous new cookbook
81
- Author: YOUR_COMPANY_NAME
82
- Email: YOUR_EMAIL
83
- License: none
71
+ License: All rights reserved
84
72
 
85
73
  Name: fake
86
74
  Version: 1.2.0
87
- Description: A fabulous new cookbook
88
- Author: YOUR_COMPANY_NAME
89
- Email: YOUR_EMAIL
90
- License: none
75
+ License: All rights reserved
91
76
 
92
77
  Name: fake
93
78
  Version: 2.0.0
94
- Description: A fabulous new cookbook
95
- Author: YOUR_COMPANY_NAME
96
- Email: YOUR_EMAIL
97
- License: none
79
+ License: All rights reserved
98
80
  """
99
81
 
100
82
  Scenario: With multiple cookbook versions installed and the --version flag
@@ -109,35 +91,23 @@ Feature: berks shelf show
109
91
  Displaying 'fake' (1.0.0) in the Berkshelf shelf:
110
92
  Name: fake
111
93
  Version: 1.0.0
112
- Description: A fabulous new cookbook
113
- Author: YOUR_COMPANY_NAME
114
- Email: YOUR_EMAIL
115
- License: none
94
+ License: All rights reserved
116
95
  """
117
96
  And the output should not contain:
118
97
  """
119
98
  Name: fake
120
99
  Version: 1.1.0
121
- Description: A fabulous new cookbook
122
- Author: YOUR_COMPANY_NAME
123
- Email: YOUR_EMAIL
124
- License: none
100
+ License: All rights reserved
125
101
  """
126
102
  And the output should not contain:
127
103
  """
128
104
  Name: fake
129
105
  Version: 1.2.0
130
- Description: A fabulous new cookbook
131
- Author: YOUR_COMPANY_NAME
132
- Email: YOUR_EMAIL
133
- License: none
106
+ License: All rights reserved
134
107
  """
135
108
  And the output should not contain:
136
109
  """
137
110
  Name: fake
138
111
  Version: 2.0.0
139
- Description: A fabulous new cookbook
140
- Author: YOUR_COMPANY_NAME
141
- Email: YOUR_EMAIL
142
- License: none
112
+ License: All rights reserved
143
113
  """
@@ -27,6 +27,79 @@ Feature: berks upload
27
27
  | fake | 1.0.0 |
28
28
  | ekaf | 2.0.0 |
29
29
 
30
+ Scenario: a cookbook without metadata.json
31
+ Given a cookbook named "fake"
32
+ And I have a Berksfile pointing at the local Berkshelf API with:
33
+ """
34
+ metadata
35
+ """
36
+ And I write to "metadata.rb" with:
37
+ """
38
+ name 'bacon'
39
+ version '1.0.0'
40
+ """
41
+ When I successfully run `berks install`
42
+ And I successfully run `berks upload`
43
+ Then the Chef Server should have the cookbooks:
44
+ | bacon | 1.0.0 |
45
+ And a file named "metadata.json" should not exist
46
+
47
+ Scenario: a cookbook with metadata.json
48
+ Given a cookbook named "fake"
49
+ And I have a Berksfile pointing at the local Berkshelf API with:
50
+ """
51
+ metadata
52
+ """
53
+ And I write to "metadata.rb" with:
54
+ """
55
+ name 'bacon'
56
+ version '1.0.0'
57
+ """
58
+ And I write to "metadata.json" with:
59
+ """
60
+ {
61
+ "name": "bacon",
62
+ "description": "",
63
+ "long_description": "",
64
+ "maintainer": "",
65
+ "maintainer_email": "",
66
+ "license": "All rights reserved",
67
+ "platforms": {
68
+
69
+ },
70
+ "dependencies": {
71
+
72
+ },
73
+ "providing": {
74
+
75
+ },
76
+ "attributes": {
77
+
78
+ },
79
+ "recipes": {
80
+
81
+ },
82
+ "version": "1.0.0",
83
+ "source_url": "",
84
+ "issues_url": "",
85
+ "privacy": false,
86
+ "chef_versions": [
87
+
88
+ ],
89
+ "ohai_versions": [
90
+
91
+ ],
92
+ "gems": [
93
+
94
+ ]
95
+ }
96
+ """
97
+ When I successfully run `berks install`
98
+ And I successfully run `berks upload`
99
+ Then the Chef Server should have the cookbooks:
100
+ | bacon | 1.0.0 |
101
+ And a file named "metadata.json" should exist
102
+
30
103
  Scenario: a cookbook with a path location
31
104
  Given a cookbook named "fake"
32
105
  And I have a Berksfile pointing at the local Berkshelf API with:
@@ -107,3 +107,46 @@ Feature: Vendoring cookbooks to a directory
107
107
  When I successfully run `berks vendor path/to/cukebooks`
108
108
  Then the directory "path/to/cukebooks/fake" should contain version "1.0.0" of the "fake" cookbook
109
109
 
110
+ Scenario: vendoring a cookbook with chefignores
111
+ Given a cookbook named "bacon"
112
+ And the cookbook "bacon" has the file "metadata.rb" with:
113
+ """
114
+ name 'bacon'
115
+ version '1.0.0'
116
+ """
117
+ And I have a Berksfile pointing at the local Berkshelf API with:
118
+ """
119
+ cookbook 'bacon', path: './bacon'
120
+ """
121
+ And the cookbook "bacon" has the file "chefignore" with:
122
+ """
123
+ *.turd
124
+ """
125
+ And the cookbook "bacon" has the file "foo.turd" with:
126
+ """
127
+ poop
128
+ """
129
+ And the cookbook "bacon" has the file "recipes/foo.turd" with:
130
+ """
131
+ poop
132
+ """
133
+ When I successfully run `berks vendor vendor`
134
+ Then the directory "vendor/bacon" should contain version "1.0.0" of the "bacon" cookbook
135
+ And a file named "vendor/bacon/foo.turd" should not exist
136
+ And a file named "vendor/bacon/recipes/foo.turd" should not exist
137
+
138
+ Scenario: metadata.json / metadata.rb handling when vendoring a cookbook
139
+ Given a cookbook named "bacon"
140
+ And the cookbook "bacon" has the file "metadata.rb" with:
141
+ """
142
+ name 'bacon'
143
+ version '1.0.0'
144
+ """
145
+ And I have a Berksfile pointing at the local Berkshelf API with:
146
+ """
147
+ cookbook 'bacon', path: './bacon'
148
+ """
149
+ When I successfully run `berks vendor vendor`
150
+ Then the directory "vendor/bacon" should contain version "1.0.0" of the "bacon" cookbook
151
+ And a file named "vendor/bacon/metadata.json" should exist
152
+ And a file named "vendor/bacon/metadata.rb" should exist
@@ -110,7 +110,7 @@ Feature: --format json
110
110
  {
111
111
  "name": "example_cookbook",
112
112
  "version": "0.5.0",
113
- "uploaded_to": "http://localhost:26310/"
113
+ "uploaded_to": "http://localhost:26310"
114
114
  }
115
115
  ],
116
116
  "errors": [],
@@ -9,8 +9,8 @@ Given /^the Chef Server has cookbooks:$/ do |cookbooks|
9
9
  metadata = []
10
10
  metadata << "name '#{name}'"
11
11
  metadata << "version '#{version}'"
12
- dependencies.to_s.split(",").map { |d| d.split(" ", 2) }.each do |(name, constraint)|
13
- metadata << "depends '#{name}', '#{constraint}'"
12
+ dependencies.to_s.split(",").map { |d| d.split(" ", 2) }.each do |(dep_name, constraint)|
13
+ metadata << "depends '#{dep_name}', '#{constraint}'"
14
14
  end
15
15
 
16
16
  chef_cookbook(name, { "metadata.rb" => metadata.join("\n") })
@@ -36,6 +36,22 @@ Given /^the cookbook store contains a cookbook "(.*?)" "(.*?)" with dependencies
36
36
  generate_cookbook(cookbook_store.storage_path, name, version, dependencies: dependencies.raw)
37
37
  end
38
38
 
39
+ Given(/^the cookbook store cookbook "(.*?)" "(.*?)" is vendored without a metadata.rb$/) do |name, version|
40
+ cookbook_path = File.join(cookbook_store.storage_path, "#{name}-#{version}")
41
+ cookbook = Berkshelf::CachedCookbook.from_path(cookbook_path)
42
+ cookbook.compile_metadata()
43
+ metadata_file = File.join(cookbook_path, "metadata.rb")
44
+ File.unlink(metadata_file) if File.file?(metadata_file)
45
+ end
46
+
47
+ Given(/^the cookbook store cookbook "(.*?)" "(.*?)" is vendored with a metadata.rb$/) do |name, version|
48
+ cookbook_path = File.join(cookbook_store.storage_path, "#{name}-#{version}")
49
+ cookbook = Berkshelf::CachedCookbook.from_path(cookbook_path)
50
+ cookbook.compile_metadata()
51
+ metadata_file = File.join(cookbook_path, "metadata.rb")
52
+ raise "internal error, fixture cookbook should have a metadata.rb" unless File.file?(metadata_file)
53
+ end
54
+
39
55
  Given(/^the cookbook store is empty$/) do
40
56
  Berkshelf::CookbookStore.instance.clean!
41
57
  end
@@ -42,16 +42,17 @@ Before do
42
42
  reload_configs
43
43
  Berkshelf::CachedCookbook.instance_variable_set(:@loaded_cookbooks, nil)
44
44
 
45
- endpoints = [
46
- {
47
- type: "chef_server",
48
- options: {
49
- url: "http://localhost:#{CHEF_SERVER_PORT}",
50
- client_name: "reset",
51
- client_key: File.expand_path("spec/config/berkshelf.pem"),
52
- },
53
- },
54
- ]
45
+ # This appears to be dead code
46
+ #endpoints = [
47
+ # {
48
+ # type: "chef_server",
49
+ # options: {
50
+ # url: "http://localhost:#{CHEF_SERVER_PORT}",
51
+ # client_name: "reset",
52
+ # client_key: File.expand_path("spec/config/berkshelf.pem"),
53
+ # },
54
+ # },
55
+ #]
55
56
 
56
57
  Berkshelf::RSpec::ChefServer.start(port: CHEF_SERVER_PORT)
57
58
 
@@ -1,3 +1,4 @@
1
+
1
2
  # XXX: work around logger spam from hashie
2
3
  # https://github.com/intridea/hashie/issues/394
3
4
  begin
@@ -8,23 +9,21 @@ rescue LoadError
8
9
  # intentionally left blank
9
10
  end
10
11
 
11
- require "buff/extensions"
12
12
  require "cleanroom"
13
13
  require "digest/md5"
14
14
  require "forwardable"
15
15
  require "json"
16
16
  require "pathname"
17
- require "ridley"
18
17
  require "semverse"
19
18
  require "solve"
20
19
  require "thor"
21
20
  require "uri"
22
- require "celluloid"
23
21
 
24
22
  JSON.create_id = nil
25
23
 
26
24
  require_relative "berkshelf/core_ext"
27
25
  require_relative "berkshelf/thor_ext"
26
+ require "berkshelf/chef_config_compat"
28
27
 
29
28
  module Berkshelf
30
29
  Encoding.default_external = Encoding::UTF_8
@@ -68,7 +67,7 @@ module Berkshelf
68
67
  include Mixin::Logging
69
68
 
70
69
  attr_writer :berkshelf_path
71
- attr_accessor :ui
70
+ attr_writer :ui
72
71
 
73
72
  # @return [Pathname]
74
73
  def root
@@ -105,9 +104,9 @@ module Berkshelf
105
104
 
106
105
  # The Chef configuration file.
107
106
  #
108
- # @return [Ridley::Chef::Config]
107
+ # @return [Berkshelf::ChefConfigCompat]
109
108
  def chef_config
110
- @chef_config ||= Ridley::Chef::Config.new(ENV["BERKSHELF_CHEF_CONFIG"])
109
+ @chef_config ||= Berkshelf::ChefConfigCompat.new(ENV["BERKSHELF_CHEF_CONFIG"])
111
110
  end
112
111
 
113
112
  # @param [Ridley::Chef::Config]
@@ -151,29 +150,29 @@ module Berkshelf
151
150
  end
152
151
  ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store
153
152
 
154
- ridley_options = options.slice(:ssl)
153
+ ridley_options = {}
154
+ ridley_options[:ssl] = options[:ssl] if options.key?(:ssl)
155
155
  ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url
156
156
  ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name
157
157
  ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key
158
158
  ridley_options[:ssl] = ssl_options
159
159
 
160
- unless ridley_options[:server_url].present?
160
+ if !ridley_options[:server_url] || ridley_options[:server_url] =~ /^\s*$/
161
161
  raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.server_url"
162
162
  end
163
163
 
164
- unless ridley_options[:client_name].present?
164
+ if !ridley_options[:client_name] || ridley_options[:client_name] =~ /^\s*$/
165
165
  raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.node_name"
166
166
  end
167
167
 
168
- unless ridley_options[:client_key].present?
168
+ if !ridley_options[:client_key] || ridley_options[:client_key] =~ /^\s*$/
169
169
  raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key"
170
170
  end
171
171
 
172
- # @todo Something scary going on here - getting an instance of Kitchen::Logger from test-kitchen
173
- # https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
174
- Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
175
- Ridley.open(ridley_options, &block)
176
- rescue Ridley::Errors::RidleyError => ex
172
+ RidleyCompat.new_client(ridley_options, &block)
173
+ rescue ChefConnectionError, BerkshelfError
174
+ raise
175
+ rescue => ex
177
176
  log.exception(ex)
178
177
  raise ChefConnectionError, ex # todo implement
179
178
  end
@@ -220,17 +219,15 @@ module Berkshelf
220
219
  end
221
220
 
222
221
  require_relative "berkshelf/lockfile"
223
- require_relative "berkshelf/base_generator"
224
222
  require_relative "berkshelf/berksfile"
225
223
  require_relative "berkshelf/cached_cookbook"
226
224
  require_relative "berkshelf/cli"
225
+ require_relative "berkshelf/chef_config_compat"
227
226
  require_relative "berkshelf/community_rest"
228
- require_relative "berkshelf/cookbook_generator"
229
227
  require_relative "berkshelf/cookbook_store"
230
228
  require_relative "berkshelf/config"
231
229
  require_relative "berkshelf/dependency"
232
230
  require_relative "berkshelf/downloader"
233
- require_relative "berkshelf/init_generator"
234
231
  require_relative "berkshelf/installer"
235
232
  require_relative "berkshelf/logger"
236
233
  require_relative "berkshelf/resolver"
@@ -239,6 +236,4 @@ require_relative "berkshelf/source_uri"
239
236
  require_relative "berkshelf/validator"
240
237
  require_relative "berkshelf/ssl_policies"
241
238
 
242
- Ridley.logger = Berkshelf.logger
243
239
  Berkshelf.logger.level = Logger::WARN
244
- Celluloid.logger.level = Logger::ERROR