berkshelf 1.2.1 → 1.3.0.rc1
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.
- data/.gitignore +1 -0
- data/{.rbenv-version → .ruby-version} +0 -0
- data/.travis.yml +5 -5
- data/berkshelf.gemspec +3 -7
- data/features/help.feature +20 -0
- data/features/install_command.feature +2 -0
- data/features/list_command.feature +1 -0
- data/features/step_definitions/filesystem_steps.rb +7 -8
- data/features/step_definitions/utility_steps.rb +6 -0
- data/features/upload_command.feature +2 -0
- data/generator_files/Gemfile.erb +1 -1
- data/generator_files/Vagrantfile.erb +51 -45
- data/lib/berkshelf/cli.rb +18 -8
- data/lib/berkshelf/community_rest.rb +2 -2
- data/lib/berkshelf/git.rb +1 -1
- data/lib/berkshelf/locations/git_location.rb +1 -1
- data/lib/berkshelf/version.rb +1 -1
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_download/unpacks_the_archive.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_find/raises_a_CommunitySiteError_error_on_any_non_200_or_404_response.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_find/raises_a_CookbookNotFound_error_on_a_404_response_for_a_non-existent_cookbook.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_find/raises_a_CookbookNotFound_error_on_a_404_response_for_a_non-existent_version.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_find/returns_the_cookbook_and_version_information.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_latest_version/raises_a_CommunitySiteError_error_on_any_non_200_or_404_response.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_latest_version/raises_a_CookbookNotFound_error_on_a_404_response.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_latest_version/returns_the_version_number_of_the_latest_version_of_the_cookbook.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_satisfy/returns_the_version_number_of_the_best_solution.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_versions/raises_a_CommunitySiteError_error_on_any_non_200_or_404_response.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_versions/raises_a_CookbookNotFound_error_on_a_404_response.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_CommunityREST/_versions/returns_an_array_containing_an_item_for_each_version.json +1 -0
- data/spec/fixtures/cassettes/Berkshelf_Resolver/ClassMethods/_initialize/adds_the_dependencies_of_the_source_as_sources.yml +3829 -0
- data/spec/spec_helper.rb +10 -3
- data/spec/support/matchers/file_system_matchers.rb +4 -2
- data/spec/unit/berkshelf/community_rest_spec.rb +108 -67
- data/spec/unit/berkshelf/config_spec.rb +1 -1
- data/spec/unit/berkshelf/errors_spec.rb +1 -10
- data/spec/unit/berkshelf/init_generator_spec.rb +2 -3
- data/spec/unit/berkshelf/location_spec.rb +2 -0
- data/spec/unit/berkshelf/resolver_spec.rb +10 -40
- metadata +43 -60
- data/.rvmrc +0 -1
- data/lib/berkshelf/vagrant.rb +0 -74
- data/lib/berkshelf/vagrant/action/clean.rb +0 -26
- data/lib/berkshelf/vagrant/action/install.rb +0 -49
- data/lib/berkshelf/vagrant/action/set_ui.rb +0 -17
- data/lib/berkshelf/vagrant/action/upload.rb +0 -41
- data/lib/berkshelf/vagrant/action/validate.rb +0 -30
- data/lib/berkshelf/vagrant/config.rb +0 -53
- data/lib/berkshelf/vagrant/errors.rb +0 -31
- data/lib/berkshelf/vagrant/middleware.rb +0 -52
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.3-p327@berkshelf --create
|
data/lib/berkshelf/vagrant.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'vagrant'
|
2
|
-
require 'berkshelf'
|
3
|
-
require 'berkshelf/vagrant/errors'
|
4
|
-
|
5
|
-
module Berkshelf
|
6
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
7
|
-
# @author Andrew Garson <andrew.garson@gmail.com>
|
8
|
-
module Vagrant
|
9
|
-
module Action
|
10
|
-
autoload :Install, 'berkshelf/vagrant/action/install'
|
11
|
-
autoload :Upload, 'berkshelf/vagrant/action/upload'
|
12
|
-
autoload :Clean, 'berkshelf/vagrant/action/clean'
|
13
|
-
autoload :SetUI, 'berkshelf/vagrant/action/set_ui'
|
14
|
-
autoload :Validate, 'berkshelf/vagrant/action/validate'
|
15
|
-
end
|
16
|
-
|
17
|
-
autoload :Config, 'berkshelf/vagrant/config'
|
18
|
-
autoload :Middleware, 'berkshelf/vagrant/middleware'
|
19
|
-
|
20
|
-
class << self
|
21
|
-
# @param [Vagrant::Action::Environment] env
|
22
|
-
#
|
23
|
-
# @return [String, nil]
|
24
|
-
def shelf_for(env)
|
25
|
-
return nil if env[:vm].uuid.nil?
|
26
|
-
|
27
|
-
File.join(Berkshelf.berkshelf_path, "vagrant", env[:vm].uuid)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param [Symbol] shortcut
|
31
|
-
# @param [Vagrant::Config::Top] config
|
32
|
-
#
|
33
|
-
# @return [Array]
|
34
|
-
def provisioners(shortcut, config)
|
35
|
-
config.vm.provisioners.select { |prov| prov.shortcut == shortcut }
|
36
|
-
end
|
37
|
-
|
38
|
-
# Determine if the given instance of Vagrant::Config::Top contains a
|
39
|
-
# chef_solo provisioner
|
40
|
-
#
|
41
|
-
# @param [Vagrant::Config::Top] config
|
42
|
-
#
|
43
|
-
# @return [Boolean]
|
44
|
-
def chef_solo?(config)
|
45
|
-
!provisioners(:chef_solo, config).empty?
|
46
|
-
end
|
47
|
-
|
48
|
-
# Determine if the given instance of Vagrant::Config::Top contains a
|
49
|
-
# chef_client provisioner
|
50
|
-
#
|
51
|
-
# @param [Vagrant::Config::Top] config
|
52
|
-
#
|
53
|
-
# @return [Boolean]
|
54
|
-
def chef_client?(config)
|
55
|
-
!provisioners(:chef_client, config).empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
# Initialize the Berkshelf Vagrant middleware stack
|
59
|
-
def init!
|
60
|
-
::Vagrant.config_keys.register(:berkshelf) { Berkshelf::Vagrant::Config }
|
61
|
-
|
62
|
-
[ :provision, :start ].each do |action|
|
63
|
-
::Vagrant.actions[action].insert(::Vagrant::Action::General::Validate, Berkshelf::Vagrant::Action::Validate)
|
64
|
-
::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.install)
|
65
|
-
::Vagrant.actions[action].insert(::Vagrant::Action::VM::Provision, Berkshelf::Vagrant::Middleware.upload)
|
66
|
-
end
|
67
|
-
|
68
|
-
::Vagrant.actions[:destroy].insert(::Vagrant::Action::VM::ProvisionerCleanup, Berkshelf::Vagrant::Middleware.clean)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
Berkshelf::Vagrant.init!
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
-
class Clean
|
6
|
-
attr_reader :shelf
|
7
|
-
|
8
|
-
def initialize(app, env)
|
9
|
-
@app = app
|
10
|
-
@shelf = Berkshelf::Vagrant.shelf_for(env)
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
if Berkshelf::Vagrant.chef_solo?(env[:vm].config) && self.shelf
|
15
|
-
Berkshelf.formatter.msg "cleaning Vagrant's shelf"
|
16
|
-
FileUtils.remove_dir(self.shelf, fore: true)
|
17
|
-
end
|
18
|
-
|
19
|
-
@app.call(env)
|
20
|
-
rescue BerkshelfError => e
|
21
|
-
raise VagrantWrapperError.new(e)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
-
# @author Andrew Garson <andrew.garson@gmail.com>
|
6
|
-
class Install
|
7
|
-
attr_reader :shelf
|
8
|
-
attr_reader :berksfile
|
9
|
-
|
10
|
-
def initialize(app, env)
|
11
|
-
@app = app
|
12
|
-
@shelf = Berkshelf::Vagrant.shelf_for(env)
|
13
|
-
@berksfile = Berksfile.from_file(env[:vm].config.berkshelf.berksfile_path)
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
if Berkshelf::Vagrant.chef_solo?(env[:vm].config)
|
18
|
-
configure_cookbooks_path(env)
|
19
|
-
install(env)
|
20
|
-
end
|
21
|
-
|
22
|
-
@app.call(env)
|
23
|
-
rescue BerkshelfError => e
|
24
|
-
raise VagrantWrapperError.new(e)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def install(env)
|
30
|
-
Berkshelf.formatter.msg "installing cookbooks..."
|
31
|
-
opts = {
|
32
|
-
path: self.shelf
|
33
|
-
}.merge(env[:vm].config.berkshelf.to_hash).symbolize_keys!
|
34
|
-
berksfile.install(opts)
|
35
|
-
end
|
36
|
-
|
37
|
-
def configure_cookbooks_path(env)
|
38
|
-
Berkshelf::Vagrant.provisioners(:chef_solo, env[:vm].config).each do |provisioner|
|
39
|
-
unless provisioner.config.cookbooks_path.is_a?(Array)
|
40
|
-
provisioner.config.cookbooks_path = Array(provisioner.config.cookbooks_path)
|
41
|
-
end
|
42
|
-
|
43
|
-
provisioner.config.cookbooks_path.unshift(self.shelf)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
-
class SetUI
|
6
|
-
def initialize(app, env)
|
7
|
-
@app = app
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(env)
|
11
|
-
Berkshelf.ui = ::Vagrant::UI::Colored.new('Berkshelf')
|
12
|
-
@app.call(env)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
-
class Upload
|
6
|
-
attr_reader :berksfile
|
7
|
-
|
8
|
-
def initialize(app, env)
|
9
|
-
@app = app
|
10
|
-
@berksfile = Berksfile.from_file(env[:vm].config.berkshelf.berksfile_path)
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
if Berkshelf::Vagrant.chef_client?(env[:vm].config)
|
15
|
-
upload(env)
|
16
|
-
end
|
17
|
-
|
18
|
-
@app.call(env)
|
19
|
-
rescue BerkshelfError => e
|
20
|
-
raise VagrantWrapperError.new(e)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def upload(env)
|
26
|
-
Berkshelf::Vagrant.provisioners(:chef_client, env[:vm].config).each do |provisioner|
|
27
|
-
Berkshelf.formatter.msg "uploading cookbooks to '#{provisioner.config.chef_server_url}'"
|
28
|
-
berksfile.upload(
|
29
|
-
server_url: provisioner.config.chef_server_url,
|
30
|
-
client_name: Berkshelf::Config.instance.chef.node_name,
|
31
|
-
client_key: Berkshelf::Config.instance.chef.client_key,
|
32
|
-
ssl: {
|
33
|
-
verify: Berkshelf::Config.instance.ssl.verify
|
34
|
-
}
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
-
#
|
6
|
-
# As of Vagrant 1.0.5 it is not possible to validate configuration values of
|
7
|
-
# a configuraiton that was not explicitly described in a Vagrant::Config.run block.
|
8
|
-
#
|
9
|
-
# In our case we want some values set for our middleware stacks even if the user does
|
10
|
-
# not explicitly set values for settings in `config.berkshelf`.
|
11
|
-
class Validate
|
12
|
-
def initialize(app, env)
|
13
|
-
@app = app
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
recorder = ::Vagrant::Config::ErrorRecorder.new
|
18
|
-
env[:vm].config.berkshelf.validate(env[:vm].env, recorder)
|
19
|
-
|
20
|
-
unless recorder.errors.empty?
|
21
|
-
raise ::Vagrant::Errors::ConfigValidationFailed,
|
22
|
-
messages: ::Vagrant::Util::TemplateRenderer.render("config/validation_failed", errors: { berkshelf: recorder })
|
23
|
-
end
|
24
|
-
|
25
|
-
@app.call(env)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
4
|
-
# @author Andrew Garson <andrew.garson@gmail.com>
|
5
|
-
class Config < ::Vagrant::Config::Base
|
6
|
-
# @return [String]
|
7
|
-
# path to the Berksfile to use with Vagrant
|
8
|
-
attr_reader :berksfile_path
|
9
|
-
|
10
|
-
# @return [Array<Symbol>]
|
11
|
-
# only cookbooks in these groups will be installed and copied to
|
12
|
-
# Vagrant's shelf
|
13
|
-
attr_accessor :only
|
14
|
-
|
15
|
-
# @return [Array<Symbol>]
|
16
|
-
# cookbooks in all other groups except for these will be installed
|
17
|
-
# and copied to Vagrant's shelf
|
18
|
-
attr_accessor :except
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
|
22
|
-
@except = Array.new
|
23
|
-
@only = Array.new
|
24
|
-
end
|
25
|
-
|
26
|
-
# @param [String] value
|
27
|
-
def berksfile_path=(value)
|
28
|
-
@berksfile_path = File.expand_path(value)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @param [String] value
|
32
|
-
def client_key=(value)
|
33
|
-
@client_key = File.expand_path(value)
|
34
|
-
end
|
35
|
-
|
36
|
-
def validate(env, errors)
|
37
|
-
if !except.empty? && !only.empty?
|
38
|
-
errors.add("A value for berkshelf.empty and berkshelf.only cannot both be defined.")
|
39
|
-
end
|
40
|
-
|
41
|
-
if Berkshelf::Vagrant.chef_client?(env.config.global)
|
42
|
-
if Berkshelf::Config.instance.chef.node_name.nil?
|
43
|
-
errors.add("A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
|
44
|
-
end
|
45
|
-
|
46
|
-
if Berkshelf::Config.instance.chef.client_key.nil?
|
47
|
-
errors.add("A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'vagrant/errors'
|
2
|
-
|
3
|
-
module Berkshelf
|
4
|
-
# A wrapper for a BerkshelfError for Vagrant. All Berkshelf exceptions should be
|
5
|
-
# wrapped in this proxy object so they are properly handled when Vagrant encounters
|
6
|
-
# an exception.
|
7
|
-
#
|
8
|
-
# @example wrapping an error encountered within the Vagrant plugin
|
9
|
-
# rescue BerkshelfError => e
|
10
|
-
# VagrantWrapperError.new(e)
|
11
|
-
# end
|
12
|
-
class VagrantWrapperError < Vagrant::Errors::VagrantError
|
13
|
-
# @param [BerkshelfError]
|
14
|
-
attr_reader :original
|
15
|
-
|
16
|
-
# @param [BerkshelfError] original
|
17
|
-
def initialize(original)
|
18
|
-
@original = original
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
"#{original.class}: #{original.to_s}"
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def method_missing(fun, *args, &block)
|
28
|
-
original.send(fun, *args, &block)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
4
|
-
#
|
5
|
-
# Middleware stacks for use with Vagrant
|
6
|
-
module Middleware
|
7
|
-
class << self
|
8
|
-
# Return the Berkshelf install middleware stack. When placed in the action chain
|
9
|
-
# this stack will find retrieve and resolve the cookbook dependencies describe
|
10
|
-
# in your configured Berksfile.
|
11
|
-
#
|
12
|
-
# Cookbooks will installed into a temporary directory, called a Shelf, and mounted
|
13
|
-
# into the VM. This mounted path will be appended to the chef_solo.cookbooks_path value.
|
14
|
-
#
|
15
|
-
# @return [::Vagrant::Action::Builder]
|
16
|
-
def install
|
17
|
-
@install ||= ::Vagrant::Action::Builder.new do
|
18
|
-
use Berkshelf::Vagrant::Action::SetUI
|
19
|
-
use Berkshelf::Vagrant::Action::Install
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Return the Berkshelf upload middleware stack. When placed in the action chain
|
24
|
-
# this stack will upload cookbooks to a Chef Server if the Chef-Client provisioner
|
25
|
-
# is used. The Chef Server where the cookbooks will be uploaded to is the same Chef
|
26
|
-
# Server used in the Chef-Client provisioner.
|
27
|
-
#
|
28
|
-
# Nothing will be done if the Chef-Solo provisioner is used.
|
29
|
-
#
|
30
|
-
# @return [::Vagrant::Action::Builder]
|
31
|
-
def upload
|
32
|
-
@upload ||= ::Vagrant::Action::Builder.new do
|
33
|
-
use Berkshelf::Vagrant::Action::SetUI
|
34
|
-
use Berkshelf::Vagrant::Action::Upload
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Return the Berkshelf clean middleware stack. When placed in the action chain
|
39
|
-
# this stack will clean up any temporary directories or files created by the other
|
40
|
-
# middleware stacks.
|
41
|
-
#
|
42
|
-
# @return [::Vagrant::Action::Builder]
|
43
|
-
def clean
|
44
|
-
@clean ||= ::Vagrant::Action::Builder.new do
|
45
|
-
use Berkshelf::Vagrant::Action::SetUI
|
46
|
-
use Berkshelf::Vagrant::Action::Clean
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|