vagrant-berkshelf 2.0.1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0d9bbf9d6d41659443ed835c10c67361b44eb4e
4
- data.tar.gz: 8094ab33d81a900ef1c856af121be08c46f5fb7e
3
+ metadata.gz: 62de20b48013f967082c65d1aedb9f29292e694c
4
+ data.tar.gz: 1172289f2a081195c6fbf72d8311954a6c8b238c
5
5
  SHA512:
6
- metadata.gz: 967829c95d9d9415dab4d784634b5bd111a0e714340dd1b23356fb2787bce68865d956e897b187d4fc01a40014cfc733b08c10614797262c14ec7f3790d28713
7
- data.tar.gz: 0e98e2ee7973f75fdd2497b066a05b2f891b3b580b3ce70444e354f906ed6f87fcb9f0e2f3454a7a9545a4bf0719feae46c94c41c50438c3db68b4f6e209d02c
6
+ metadata.gz: edd6b97e93c2a74463c16b1bdca1fce19575f94506d8a690625f233ab5e4e5fb52e4b8c14f904db222ca2a24b14d515e13f15a3f66f66a0a72809cf731eb8b7a
7
+ data.tar.gz: 877fdae6ba5e16e5a3b6920af4759b88cd5288d42ecf65d6bf6ba1dae7a4e83fe9bae5fac6594216c8258669245ef740c99bb33557a34838dcf4d57ffeecd72b
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rspec
19
+ .vagrant
20
+ integration/Berksfile.lock
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 3.0.0
2
+
3
+ * Enhancements
4
+ * Now leverages the Berkshelf version installed by ChefDK
5
+ * Installation process of plugin should be many, many times faster
6
+
7
+ * Bug Fixes
8
+ * Fix many installation issues for Windows users
9
+ * Fix warning output of berkshelf path when berkshelf is disabled but a Berksfile is present
10
+ * Ensure default values for configuration are properly set
11
+
1
12
  # 2.0.1
2
13
 
3
14
  * Bug Fixes
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.5.2'
6
+ gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.6.3'
7
7
  end
8
8
 
9
9
  group :plugins do
data/README.md CHANGED
@@ -2,15 +2,14 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/vagrant-berkshelf.png)](http://badge.fury.io/rb/vagrant-berkshelf)
4
4
  [![Build Status](https://travis-ci.org/berkshelf/vagrant-berkshelf.png?branch=master)](https://travis-ci.org/berkshelf/vagrant-berkshelf)
5
- [![Dependency Status](https://gemnasium.com/berkshelf/vagrant-berkshelf.png)](https://gemnasium.com/berkshelf/vagrant-berkshelf)
6
5
 
7
6
  A Vagrant plugin to add Berkshelf integration to the Chef provisioners
8
7
 
9
8
  ## Installation
10
9
 
11
- Install Vagrant '>= 1.5.2' from the [Vagrant downloads page](http://www.vagrantup.com/downloads.html)
12
-
13
- Install the Vagrant Berkshelf plugin
10
+ 1. Install [Vagrant](http://www.vagrantup.com/downloads.html) ">= 1.5.2"
11
+ 2. Install [ChefDK](http://getchef.com/downloads/chef-dk) ">= 0.2.0"
12
+ 3. Install the Vagrant Berkshelf plugin
14
13
 
15
14
  $ vagrant plugin install vagrant-berkshelf
16
15
 
@@ -26,6 +25,13 @@ Once the Vagrant Berkshelf plugin is installed it can be enabled in your Vagrant
26
25
 
27
26
  The plugin will look in your current working directory for your `Berksfile` by default. Just ensure that your Berksfile exists and when you run `vagrant up`, `vagrant provision`, or `vagrant destroy` the Berkshelf integration will automatically kick in!
28
27
 
28
+ > The Vagrant Berkshelf plugin does not support multi-machine Vagrantfiles.
29
+
30
+ ## Getting Help
31
+
32
+ * If you have an issue: report it on the [issue tracker](https://github.com/berkshelf/berkshelf/issues)
33
+ * If you have a question: visit the #chef or #berkshelf channel on irc.freenode.net
34
+
29
35
  # Authors
30
36
 
31
37
  - Jamie Winsor (<jamie@vialstudios.com>)
@@ -0,0 +1,3 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+ cookbook "apt"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-berkshelf", path: "../"
9
+ gem "vagrant-omnibus"
10
+ end
@@ -0,0 +1,19 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ Vagrant.require_version ">= 1.5.0"
4
+
5
+ Vagrant.configure("2") do |config|
6
+ config.vm.hostname = "vagrant-builder-int"
7
+ config.vm.box = "opscode-ubuntu-14.04"
8
+ config.vm.box_url = "https://vagrantcloud.com/chef/ubuntu-14.04/version/1/provider/virtualbox.box"
9
+
10
+ config.vm.network :private_network, type: "dhcp"
11
+
12
+ config.omnibus.chef_version = :latest
13
+
14
+ config.vm.provision :chef_client do |chef|
15
+ chef.chef_server_url = "https://api.opscode.com/organizations/undeadlabs"
16
+ chef.validation_key_path = File.expand_path("~/.chef/undeadlabs-validator.pem")
17
+ chef.run_list = ["apt::default"]
18
+ end
19
+ end
@@ -23,50 +23,46 @@ module Berkshelf
23
23
  return @app.call(env)
24
24
  end
25
25
 
26
- opts = env[:machine].config.berkshelf.to_hash.symbolize_keys
27
- opts.delete(:except) if opts[:except].empty?
28
- opts.delete(:only) if opts[:only].empty?
29
- env[:berkshelf].berksfile = Berkshelf::Berksfile.from_file(berksfile_path(env), opts)
30
-
31
26
  if chef_solo?(env)
32
- install(env)
27
+ vendor(env)
33
28
  end
34
29
 
35
30
  @app.call(env)
36
- rescue Berkshelf::BerkshelfError => e
37
- raise Berkshelf::VagrantWrapperError.new(e)
31
+ rescue => ex
32
+ raise Berkshelf::VagrantWrapperError.new(ex)
38
33
  end
39
34
 
40
35
  private
41
36
 
42
- def install(env)
37
+ def vendor(env)
43
38
  check_vagrant_version(env)
44
39
  env[:berkshelf].ui.info "Updating Vagrant's berkshelf: '#{env[:berkshelf].shelf}'"
45
40
  FileUtils.rm_rf(env[:berkshelf].shelf)
46
41
 
47
- env[:berkshelf].berksfile.vendor(env[:berkshelf].shelf)
42
+ opts = env[:machine].config.berkshelf.to_hash
43
+ berks_opts = { berksfile: opts[:berksfile_path] }
44
+ berks_opts[:except] = opts[:except] if opts.has_key?(:except) && !opts[:except].empty?
45
+ berks_opts[:only] = opts[:only] if opts.has_key?(:only) && !opts[:only].empty?
46
+
47
+ env[:berkshelf].ui.info berks("vendor", env[:berkshelf].shelf, berks_opts)
48
48
  end
49
49
 
50
50
  def warn_disabled_but_berksfile_exists(env)
51
51
  env[:berkshelf].ui.warn "Berkshelf plugin is disabled but a Berksfile was found at" +
52
- " your configured path: #{env[:global_config].berkshelf.berksfile_path}"
52
+ " your configured path: #{berksfile_path(env)}"
53
53
  env[:berkshelf].ui.warn "Enable the Berkshelf plugin by setting 'config.berkshelf.enabled = true'" +
54
54
  " in your vagrant config"
55
55
  end
56
56
 
57
57
  def check_vagrant_version(env)
58
58
  unless vagrant_version_satisfies?(">= 1.5")
59
- raise Berkshelf::VagrantWrapperError.new(RuntimeError.new("vagrant-berkshelf requires Vagrant 1.5 or later."))
59
+ raise UnsupportedVagrantVersion.new(">= 1.5")
60
60
  end
61
61
  end
62
62
 
63
63
  def vagrant_version_satisfies?(requirements)
64
64
  Gem::Requirement.new(requirements).satisfied_by? Gem::Version.new(::Vagrant::VERSION)
65
65
  end
66
-
67
- def berksfile_path(env)
68
- env[:machine].env.vagrantfile.config.berkshelf.berksfile_path
69
- end
70
66
  end
71
67
  end
72
68
  end
@@ -1,3 +1,5 @@
1
+ require 'tempfile'
2
+
1
3
  module Berkshelf
2
4
  module Vagrant
3
5
  module Action
@@ -22,25 +24,27 @@ module Berkshelf
22
24
  end
23
25
 
24
26
  @app.call(env)
25
- rescue Berkshelf::BerkshelfError => e
26
- raise Berkshelf::VagrantWrapperError.new(e)
27
27
  end
28
28
 
29
29
  private
30
30
 
31
31
  def upload(env)
32
32
  provisioners(:chef_client, env).each do |provisioner|
33
- env[:berkshelf].ui.info "Uploading cookbooks to '#{provisioner.config.chef_server_url}'"
34
- env[:berkshelf].berksfile.upload(
35
- server_url: provisioner.config.chef_server_url,
36
- client_name: env[:berkshelf].config.chef.node_name,
37
- client_key: env[:berkshelf].config.chef.client_key,
38
- ssl: {
39
- verify: env[:berkshelf].config.ssl.verify
40
- },
41
- force: true,
42
- freeze: false
43
- )
33
+ begin
34
+ # Temporarily generate a berkshelf configuration to pass to the CLI since not all versions
35
+ # of the CLI allow overriding all options needed for upload.
36
+ tmp_config = Tempfile.new("berks-config")
37
+ config = BerksConfig.instance.dup
38
+ config[:chef][:chef_server_url] = provisioner.config.chef_server_url
39
+ tmp_config.write(config.to_json)
40
+ tmp_config.flush
41
+
42
+ env[:berkshelf].ui.info "Uploading cookbooks to '#{provisioner.config.chef_server_url}'"
43
+ berks("upload", config: tmp_config.path, berksfile: berksfile_path(env), force: true,
44
+ freeze: false)
45
+ ensure
46
+ tmp_config.close! unless tmp_config.nil?
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -8,7 +8,6 @@ module Berkshelf
8
8
  require_relative 'action/configure_chef'
9
9
  require_relative 'action/install'
10
10
  require_relative 'action/load_shelf'
11
- require_relative 'action/set_ui'
12
11
  require_relative 'action/upload'
13
12
 
14
13
  class << self
@@ -55,7 +54,6 @@ module Berkshelf
55
54
  def setup
56
55
  @setup ||= ::Vagrant::Action::Builder.new.tap do |b|
57
56
  b.use ::Vagrant::Action::Builtin::EnvSet, berkshelf: Berkshelf::Vagrant::Env.new
58
- b.use Berkshelf::Vagrant::Action::SetUI
59
57
  b.use Berkshelf::Vagrant::Action::LoadShelf
60
58
  b.use Berkshelf::Vagrant::Action::ConfigureChef
61
59
  end
@@ -0,0 +1,57 @@
1
+ require 'vagrant/util/hash_with_indifferent_access'
2
+
3
+ module Berkshelf::Vagrant
4
+ class BerksConfig < ::Vagrant::Util::HashWithIndifferentAccess
5
+ class << self
6
+ # @return [String]
7
+ def store_location
8
+ File.join(Berkshelf.berkshelf_path, 'config.json')
9
+ end
10
+
11
+ # @return [String]
12
+ def local_location
13
+ ENV['BERKSHELF_CONFIG'] || File.join('.', '.berkshelf', 'config.json')
14
+ end
15
+
16
+ # @return [String]
17
+ def path
18
+ path = File.exists?(local_location) ? local_location : store_location
19
+ File.expand_path(path)
20
+ end
21
+
22
+ # @return [String, nil]
23
+ # the contents of the file
24
+ def file
25
+ File.read(path) if File.exists?(path)
26
+ end
27
+
28
+ def from_json(path)
29
+ JSON.parse(File.read(path))
30
+ end
31
+
32
+ # Instantiate and return or just return the currently instantiated Berkshelf
33
+ # configuration
34
+ #
35
+ # @return [Config]
36
+ def instance
37
+ @instance ||= if file
38
+ from_json file
39
+ else
40
+ new
41
+ end
42
+ end
43
+ end
44
+
45
+ def initialize
46
+ super(chef: ChefConfig.instance, ssl: ::Vagrant::Util::HashWithIndifferentAccess.new(verify: false))
47
+ end
48
+
49
+ def chef
50
+ self[:chef]
51
+ end
52
+
53
+ def ssl
54
+ self[:ssl]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,88 @@
1
+ require 'vagrant/util/hash_with_indifferent_access'
2
+ require 'pathname'
3
+
4
+ module Berkshelf::Vagrant
5
+ class ChefConfig < ::Vagrant::Util::HashWithIndifferentAccess
6
+ class << self
7
+ # Return the most sensible path to the Chef configuration file. This can
8
+ # be configured by setting a value for the 'CHEF_CONFIG' environment
9
+ # variable.
10
+ #
11
+ # @return [String, nil]
12
+ def location
13
+ possibles = []
14
+
15
+ possibles << ENV['CHEF_CONFIG'] if ENV['CHEF_CONFIG']
16
+ possibles << File.join(ENV['KNIFE_HOME'], 'knife.rb') if ENV['KNIFE_HOME']
17
+ possibles << File.join(Dir.pwd, 'knife.rb')
18
+
19
+ # Ascending search for .chef directory siblings
20
+ Pathname.new(Dir.pwd).ascend do |file|
21
+ sibling_chef = File.join(file, '.chef')
22
+ possibles << File.join(sibling_chef, 'knife.rb')
23
+ end
24
+
25
+ possibles << File.join(ENV['HOME'], '.chef', 'knife.rb') if ENV['HOME']
26
+ possibles.compact!
27
+
28
+ location = possibles.find { |loc| File.exists?(File.expand_path(loc)) }
29
+
30
+ File.expand_path(location) unless location.nil?
31
+ end
32
+
33
+ def instance
34
+ @instance ||= from_file(location)
35
+ end
36
+
37
+ def from_file(file = nil)
38
+ file = file.nil? ? location : file
39
+ if !file.nil? && File.exist?(file) && File.readable?(file)
40
+ contents = File.read(file)
41
+ return parse(contents, file)
42
+ end
43
+
44
+ new
45
+ end
46
+
47
+ def parse(contents, path = nil)
48
+ new(contents, path)
49
+ end
50
+ end
51
+
52
+ def initialize(contents = "", path = "")
53
+ instance_eval(contents, path)
54
+ end
55
+
56
+ def chef_server_url(value = nil)
57
+ set_or_return(:chef_server_url, value)
58
+ end
59
+
60
+ def client_key(value = nil)
61
+ set_or_return(:client_key, value)
62
+ end
63
+
64
+ def node_name(value = nil)
65
+ set_or_return(:node_name, value)
66
+ end
67
+
68
+ def method_missing(m, *args, &block)
69
+ Proxy.new
70
+ end
71
+
72
+ private
73
+
74
+ def set_or_return(key, value)
75
+ if value.nil?
76
+ return self[key]
77
+ else
78
+ self[key] = value
79
+ end
80
+ end
81
+
82
+ class Proxy
83
+ def method_missing(m, *args, &block)
84
+ self
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,5 @@
1
+ require 'vagrant/util/hash_with_indifferent_access'
2
+
1
3
  module Berkshelf
2
4
  module Vagrant
3
5
  class Config < ::Vagrant.plugin("2", :config)
@@ -32,12 +34,17 @@ module Berkshelf
32
34
  def initialize
33
35
  super
34
36
 
35
- @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
37
+ @berksfile_path = UNSET_VALUE
36
38
  @except = Array.new
37
39
  @only = Array.new
38
- @node_name = Berkshelf::Config.instance.chef.node_name
39
- @client_key = Berkshelf::Config.instance.chef.client_key
40
- @enabled = File.exist?(@berksfile_path)
40
+ @node_name = BerksConfig.instance.chef[:node_name]
41
+ @client_key = BerksConfig.instance.chef[:client_key]
42
+ @enabled = UNSET_VALUE
43
+ end
44
+
45
+ def finalize!
46
+ @berksfile_path = File.join(Dir.pwd, "Berksfile") if @berksfile_path == UNSET_VALUE
47
+ @enabled = File.exist?(@berksfile_path) if @enabled == UNSET_VALUE
41
48
  end
42
49
 
43
50
  # @param [String] value
@@ -50,12 +57,18 @@ module Berkshelf
50
57
  @client_key = value
51
58
  end
52
59
 
53
- alias_method :to_hash, :instance_variables_hash
60
+ def to_hash
61
+ ::Vagrant::Util::HashWithIndifferentAccess.new(instance_variables_hash)
62
+ end
54
63
 
55
64
  def validate(machine)
56
- @berksfile_path = File.expand_path(@berksfile_path, machine.env.root_path.to_s)
57
- @client_key = File.expand_path(@client_key, machine.env.root_path.to_s)
58
65
  errors = Array.new
66
+ unless @berksfile_path.nil?
67
+ @berksfile_path = File.expand_path(@berksfile_path, machine.env.root_path.to_s)
68
+ end
69
+ unless @client_key.nil?
70
+ @client_key = File.expand_path(@client_key, machine.env.root_path.to_s)
71
+ end
59
72
 
60
73
  unless [TrueClass, FalseClass].include?(enabled.class)
61
74
  errors << "A value for berkshelf.enabled can be true or false."
@@ -76,16 +89,18 @@ module Berkshelf
76
89
 
77
90
  if global_provisioners(machine).any? { |prov| prov.name == :chef_client }
78
91
  if machine.config.berkshelf.node_name.nil?
79
- errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
92
+ errors << "A configuration must be set node_name when using the chef_client provisioner." +
93
+ " Edit your berkshelf configuration and add a value for chef.node_name."
80
94
  end
81
95
 
82
96
  if machine.config.berkshelf.client_key.nil?
83
- errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
97
+ errors << "A configuration must be set for client_key when using the chef_client provisioner." +
98
+ " Edit your berkshelf configuration and add a value for chef.client_key."
84
99
  end
85
100
  end
86
101
  end
87
102
 
88
- { "berkshelf configuration" => errors }
103
+ {"berkshelf configuration" => errors}
89
104
  end
90
105
 
91
106
  private
@@ -4,17 +4,12 @@ module Berkshelf
4
4
  class Env
5
5
  # @return [Vagrant::UI::Colored]
6
6
  attr_accessor :ui
7
- # @return [Berkshelf::Berksfile]
8
- attr_accessor :berksfile
9
7
  # @return [String]
10
8
  attr_accessor :shelf
11
- # @return [Berkshelf::Config]
12
- attr_accessor :config
13
9
 
14
10
  def initialize
15
- @ui = ::Vagrant::UI::Colored.new
11
+ @ui = ::Vagrant::UI::Colored.new
16
12
  @ui.opts[:target] = 'Berkshelf'
17
- @config = Berkshelf::Config.instance
18
13
  end
19
14
  end
20
15
  end
@@ -1,7 +1,47 @@
1
+ require 'buff/shell_out'
2
+ require 'json'
3
+ require 'vagrant/util/which'
4
+
1
5
  module Berkshelf
2
6
  module Vagrant
3
7
  # A module of common helper functions that can be mixed into Berkshelf::Vagrant actions
4
8
  module EnvHelpers
9
+ BERKS_CONSTRAINT = ">= 3.0.0"
10
+
11
+ include Buff::ShellOut
12
+ include ::Vagrant::Util
13
+
14
+ # Execute a berkshelf command with the given arguments and flags.
15
+ #
16
+ # @overload berks(command, args)
17
+ # @param [String] berks CLI command to run
18
+ # @param [Object] any number of arguments to pass to CLI
19
+ # @overload berks(command, args, options)
20
+ # @param [String] berks CLI command to run
21
+ # @param [Object] any number of arguments to pass to CLI
22
+ # @param [Hash] options to convert to flags for the CLI
23
+ #
24
+ # @return [String]
25
+ # output of the command
26
+ #
27
+ # @raise [UnsupportedBerksVersion]
28
+ # version of Berks installed does not satisfy the application's constraint
29
+ # @raise [BerksNotFound]
30
+ # berks command is not found in the user's path
31
+ # @raise [BerksError]
32
+ # CLI command failed
33
+ def berks(command, *args)
34
+ if defined?(Bundler)
35
+ Bundler.with_clean_env { run_berks(command, *args) }
36
+ else
37
+ run_berks(command, *args)
38
+ end
39
+ end
40
+
41
+ def berksfile_path(env)
42
+ env[:machine].env.vagrantfile.config.berkshelf.berksfile_path
43
+ end
44
+
5
45
  # A file to persist vagrant-berkshelf specific information in between
6
46
  # Vagrant runs.
7
47
  #
@@ -57,6 +97,64 @@ module Berkshelf
57
97
  def provision_disabled?(env)
58
98
  env.has_key?(:provision_enabled) && !env[:provision_enabled]
59
99
  end
100
+
101
+ private
102
+
103
+ def berks_version_check!
104
+ if (exec = Which.which("berks")).nil?
105
+ raise BerksNotFound
106
+ end
107
+
108
+ unless (response = shell_out("#{exec} version -F json")).success?
109
+ raise "Couldn't determine Berks version: #{response.inspect}"
110
+ end
111
+
112
+ begin
113
+ version = Gem::Version.new(JSON.parse(response.stdout)["version"])
114
+ Gem::Requirement.new(BERKS_CONSTRAINT).satisfied_by?(version)
115
+ exec
116
+ rescue => ex
117
+ raise UnsupportedBerksVersion.new(exec, BERKS_CONSTRAINT, version)
118
+ end
119
+ end
120
+
121
+ def options_to_flags(opts)
122
+ opts.map do |key, value|
123
+ if value.is_a?(TrueClass)
124
+ "--#{key_to_flag(key)}"
125
+ next
126
+ end
127
+
128
+ if value.is_a?(FalseClass)
129
+ "--no-#{key_to_flag(key)}"
130
+ next
131
+ end
132
+
133
+ if value.is_a?(Array)
134
+ "--#{key_to_flag(key)}=#{value.join(" ")}"
135
+ next
136
+ end
137
+
138
+ "--#{key_to_flag(key)}=#{value}"
139
+ end.join(" ")
140
+ end
141
+
142
+ def run_berks(command, *args)
143
+ exec = berks_version_check!
144
+ options = args.last.is_a?(Hash) ? args.pop : Hash.new
145
+ arguments = args.join(" ")
146
+ flags = options_to_flags(options)
147
+
148
+ command = "#{exec} #{command} #{arguments} #{flags}"
149
+ unless (response = shell_out(command)).success?
150
+ raise BerksError.new("Berks command Failed: #{command}, reason: #{response.stderr}")
151
+ end
152
+ response.stdout
153
+ end
154
+
155
+ def key_to_flag(key)
156
+ "#{key.to_s.gsub("_", "-")}"
157
+ end
60
158
  end
61
159
  end
62
160
  end
@@ -28,4 +28,44 @@ module Berkshelf
28
28
  original.send(fun, *args, &block)
29
29
  end
30
30
  end
31
+
32
+ class BerksError < ::Vagrant::Errors::VagrantError
33
+ attr_reader :error_message
34
+
35
+ def initialize(message)
36
+ @error_message = message
37
+ super
38
+ end
39
+ end
40
+
41
+ class BerksNotFound < ::Vagrant::Errors::VagrantError
42
+ def error_message
43
+ "Berks not found. Download the ChefDK from http://downloads.getchef.com/chef-dk and add it to your $PATH."
44
+ end
45
+ end
46
+
47
+ class UnsupportedBerksVersion < ::Vagrant::Errors::VagrantError
48
+ def initialize(bin, constraint, version)
49
+ @bin = bin
50
+ @constraint = constraint
51
+ @version = version
52
+ super
53
+ end
54
+
55
+ def error_message
56
+ "Unsupported Berkshelf version at: #{@bin}. Requires #{@constraint} and got #{@version}." +
57
+ " Download the latest version of the ChefDK from http://downloads.getchef.com/chef-dk and add it to your $PATH."
58
+ end
59
+ end
60
+
61
+ class UnsupportedVagrantVersion < ::Vagrant::Errors::VagrantError
62
+ def initialize(constraint)
63
+ @constraint = constraint
64
+ super
65
+ end
66
+
67
+ def error_message
68
+ "vagrant-berkshelf requires Vagrant #{@constraint}."
69
+ end
70
+ end
31
71
  end
@@ -1,5 +1,5 @@
1
1
  module Berkshelf
2
2
  module Vagrant
3
- VERSION = "2.0.1"
3
+ VERSION = "3.0.0.rc1"
4
4
  end
5
5
  end
@@ -4,7 +4,6 @@ rescue LoadError
4
4
  raise 'The Vagrant Berkshelf plugin must be run within Vagrant.'
5
5
  end
6
6
 
7
- require 'berkshelf'
8
7
  require 'fileutils'
9
8
  require 'json'
10
9
  require 'tmpdir'
@@ -13,7 +12,22 @@ require_relative 'vagrant/errors'
13
12
  require_relative 'vagrant/version'
14
13
 
15
14
  module Berkshelf
15
+ class << self
16
+ # Returns the filepath to the location Berkshelf will use for
17
+ # storage; temp files will go here, Cookbooks will be downloaded
18
+ # to or uploaded from here. By default this is '~/.berkshelf' but
19
+ # can be overridden by specifying a value for the ENV variable
20
+ # 'BERKSHELF_PATH'.
21
+ #
22
+ # @return [String]
23
+ def berkshelf_path
24
+ ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
25
+ end
26
+ end
27
+
16
28
  module Vagrant
29
+ require_relative 'vagrant/chef_config'
30
+ require_relative 'vagrant/berks_config'
17
31
  require_relative 'vagrant/action'
18
32
  require_relative 'vagrant/config'
19
33
  require_relative 'vagrant/env'
@@ -35,7 +49,6 @@ module Berkshelf
35
49
  # @return [String]
36
50
  # path to the generated shelf
37
51
  def mkshelf(machine_name = nil)
38
-
39
52
  unless File.exist?(shelf_path)
40
53
  FileUtils.mkdir_p(shelf_path)
41
54
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Vagrant::Config do
4
4
  let(:unset_value) { described_class::UNSET_VALUE }
5
- let(:config) { described_class.new }
5
+ subject { described_class.new.tap {|s| s.finalize! } }
6
6
 
7
7
  it "sets a path to a Berksfile in the current working directory for berksfile_path" do
8
8
  subject.berksfile_path.should eql(File.join(Dir.pwd, "Berksfile"))
@@ -14,7 +14,7 @@ describe Berkshelf::Vagrant::Config do
14
14
  end
15
15
 
16
16
  it "it sets the value of enabled to true" do
17
- config.enabled.should be true
17
+ subject.enabled.should be true
18
18
  end
19
19
  end
20
20
 
@@ -24,7 +24,7 @@ describe Berkshelf::Vagrant::Config do
24
24
  end
25
25
 
26
26
  it "set the value of enabled to false" do
27
- config.enabled.should be false
27
+ subject.enabled.should be false
28
28
  end
29
29
  end
30
30
 
@@ -38,12 +38,12 @@ describe Berkshelf::Vagrant::Config do
38
38
  subject.except.should be_empty
39
39
  end
40
40
 
41
- it "sets the value of node_name to the value in the Berkshelf::Config.instance" do
42
- subject.node_name.should eql(Berkshelf::Config.instance.chef.node_name)
41
+ it "sets the value of node_name to the value in the Berkshelf::Vagrant::BerksConfig.instance" do
42
+ subject.node_name.should eql(Berkshelf::Vagrant::BerksConfig.instance.chef.node_name)
43
43
  end
44
44
 
45
- it "sets the value of client_key to the value in Berkshelf::Config.instance" do
46
- subject.client_key.should eql(Berkshelf::Config.instance.chef.client_key)
45
+ it "sets the value of client_key to the value in Berkshelf::Vagrant::BerksConfig.instance" do
46
+ subject.client_key.should eql(Berkshelf::Vagrant::BerksConfig.instance.chef.client_key)
47
47
  end
48
48
 
49
49
  describe "#validate" do
@@ -13,7 +13,6 @@ describe Berkshelf::Vagrant do
13
13
  end
14
14
 
15
15
  describe "::mkshelf" do
16
-
17
16
  it "returns a String" do
18
17
  subject.mkshelf().should be_a(String)
19
18
  end
@@ -27,7 +26,6 @@ describe Berkshelf::Vagrant do
27
26
  machine_name = 'fantastic_machine'
28
27
  subject.mkshelf(machine_name).should include(machine_name)
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
  spec.required_ruby_version = '>= 1.9.1'
21
21
 
22
- spec.add_dependency 'berkshelf', '~> 3.1'
23
- spec.add_dependency 'celluloid', '~> 0.16.0.pre' # must explicitly lock or a gem conflict with vagrant's
24
- spec.add_dependency 'celluloid-io', '~> 0.16.0.pre' # dependencies will arise during installation
22
+ spec.post_install_message = "In order to use the Vagrant-Berkshelf plugin, you must have ChefDK installed.\n" +
23
+ "To download the latest ChefDK visit http://getchef.com/downloads/chef-dk."
24
+
25
+ spec.add_dependency "buff-shell_out"
25
26
 
26
27
  spec.add_development_dependency 'spork', '~> 0.9'
27
28
  spec.add_development_dependency 'rspec', '~> 2.13'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -9,50 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-20 00:00:00.000000000 Z
12
+ date: 2014-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: berkshelf
15
+ name: buff-shell_out
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3.1'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '3.1'
28
- - !ruby/object:Gem::Dependency
29
- name: celluloid
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 0.16.0.pre
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
25
+ - - ">="
40
26
  - !ruby/object:Gem::Version
41
- version: 0.16.0.pre
42
- - !ruby/object:Gem::Dependency
43
- name: celluloid-io
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 0.16.0.pre
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 0.16.0.pre
27
+ version: '0'
56
28
  - !ruby/object:Gem::Dependency
57
29
  name: spork
58
30
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +84,18 @@ files:
112
84
  - LICENSE.txt
113
85
  - README.md
114
86
  - Thorfile
87
+ - integration/Berksfile
88
+ - integration/Gemfile
89
+ - integration/Vagrantfile
115
90
  - lib/berkshelf/vagrant.rb
116
91
  - lib/berkshelf/vagrant/action.rb
117
92
  - lib/berkshelf/vagrant/action/clean.rb
118
93
  - lib/berkshelf/vagrant/action/configure_chef.rb
119
94
  - lib/berkshelf/vagrant/action/install.rb
120
95
  - lib/berkshelf/vagrant/action/load_shelf.rb
121
- - lib/berkshelf/vagrant/action/set_ui.rb
122
96
  - lib/berkshelf/vagrant/action/upload.rb
97
+ - lib/berkshelf/vagrant/berks_config.rb
98
+ - lib/berkshelf/vagrant/chef_config.rb
123
99
  - lib/berkshelf/vagrant/config.rb
124
100
  - lib/berkshelf/vagrant/env.rb
125
101
  - lib/berkshelf/vagrant/env_helpers.rb
@@ -136,7 +112,9 @@ homepage: http://berkshelf.com
136
112
  licenses:
137
113
  - Apache 2.0
138
114
  metadata: {}
139
- post_install_message:
115
+ post_install_message: |-
116
+ In order to use the Vagrant-Berkshelf plugin, you must have ChefDK installed.
117
+ To download the latest ChefDK visit http://getchef.com/downloads/chef-dk.
140
118
  rdoc_options: []
141
119
  require_paths:
142
120
  - lib
@@ -147,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
125
  version: 1.9.1
148
126
  required_rubygems_version: !ruby/object:Gem::Requirement
149
127
  requirements:
150
- - - ">="
128
+ - - ">"
151
129
  - !ruby/object:Gem::Version
152
- version: '0'
130
+ version: 1.3.1
153
131
  requirements: []
154
132
  rubyforge_project:
155
133
  rubygems_version: 2.2.2
@@ -1,16 +0,0 @@
1
- module Berkshelf
2
- module Vagrant
3
- module Action
4
- class SetUI
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- Berkshelf.ui = env[:berkshelf].ui
11
- @app.call(env)
12
- end
13
- end
14
- end
15
- end
16
- end