vagrant-berkshelf 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +36 -17
  3. data/.travis.yml +6 -4
  4. data/CONTRIBUTING.md +4 -4
  5. data/Gemfile +2 -2
  6. data/{LICENSE.txt → LICENSE} +1 -1
  7. data/README.md +67 -24
  8. data/Rakefile +14 -0
  9. data/lib/vagrant-berkshelf.rb +17 -1
  10. data/lib/vagrant-berkshelf/action/base.rb +48 -0
  11. data/lib/vagrant-berkshelf/action/check.rb +44 -0
  12. data/lib/vagrant-berkshelf/action/clean.rb +29 -0
  13. data/lib/vagrant-berkshelf/action/install.rb +35 -0
  14. data/lib/vagrant-berkshelf/action/load.rb +59 -0
  15. data/lib/vagrant-berkshelf/action/share.rb +38 -0
  16. data/lib/vagrant-berkshelf/action/upload.rb +99 -0
  17. data/lib/vagrant-berkshelf/config.rb +87 -0
  18. data/lib/vagrant-berkshelf/env.rb +14 -0
  19. data/lib/vagrant-berkshelf/errors.rb +79 -0
  20. data/lib/vagrant-berkshelf/helpers.rb +180 -0
  21. data/lib/vagrant-berkshelf/plugin.rb +40 -0
  22. data/lib/vagrant-berkshelf/version.rb +5 -0
  23. data/spec/spec_helper.rb +1 -4
  24. data/spec/unit/vagrant-berkshelf/config_spec.rb +119 -0
  25. data/vagrant-berkshelf.gemspec +26 -14
  26. metadata +35 -52
  27. data/Thorfile +0 -59
  28. data/integration/Berksfile +0 -3
  29. data/integration/Gemfile +0 -10
  30. data/integration/Vagrantfile +0 -19
  31. data/lib/berkshelf/vagrant.rb +0 -68
  32. data/lib/berkshelf/vagrant/action.rb +0 -64
  33. data/lib/berkshelf/vagrant/action/clean.rb +0 -27
  34. data/lib/berkshelf/vagrant/action/configure_chef.rb +0 -27
  35. data/lib/berkshelf/vagrant/action/install.rb +0 -69
  36. data/lib/berkshelf/vagrant/action/load_shelf.rb +0 -52
  37. data/lib/berkshelf/vagrant/action/upload.rb +0 -53
  38. data/lib/berkshelf/vagrant/berks_config.rb +0 -48
  39. data/lib/berkshelf/vagrant/chef_config.rb +0 -88
  40. data/lib/berkshelf/vagrant/config.rb +0 -113
  41. data/lib/berkshelf/vagrant/env.rb +0 -16
  42. data/lib/berkshelf/vagrant/env_helpers.rb +0 -160
  43. data/lib/berkshelf/vagrant/errors.rb +0 -71
  44. data/lib/berkshelf/vagrant/plugin.rb +0 -41
  45. data/lib/berkshelf/vagrant/version.rb +0 -5
  46. data/spec/unit/berkshelf/vagrant/config_spec.rb +0 -97
  47. data/spec/unit/berkshelf/vagrant/errors_spec.rb +0 -12
  48. data/spec/unit/berkshelf/vagrant_spec.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6756cdfdfc203a867d17dbca91420bb5f360b36c
4
- data.tar.gz: 9da918a274b2556339f341e39d41c2d803c397d9
3
+ metadata.gz: 3f21f3e8d10fc7c1d2205c55b0ae8bca1221777a
4
+ data.tar.gz: fcd4acefc3f607775f97873bc04206b9bf2fcb08
5
5
  SHA512:
6
- metadata.gz: 5376cfd45dd23245082bdcbf6088ab4625f8aa4090ce89c1b49471d4a3934c4ca9111db2b80688371771e796aba50b8ab00ae6d0e7d74006504874abca3955d9
7
- data.tar.gz: 9eed85ed2561b146977d0d4b037281f6d34919e896bdf5fe1d2254ca75836ed6ab727a5c69202c9040ecc88f987a7d677a9b5c60d01eac50d446a357dc9563e9
6
+ metadata.gz: b4308dafc20d438f3c2a1524ed5076258c4b93e7f2291ca63c696fd116ec9aa7d81630c8a19bcda17d1a48fac25c87bcfa28caf6e343bfc66379a803dea72d61
7
+ data.tar.gz: fe57bc6dc166bf013d2eff69316d3ac0490ae79b6fafc3666052bc5cdadc07b434c0a91b13df7f7dbaf6c70a36bc1f697394b1488a0309258577eac4b7187a3e
data/.gitignore CHANGED
@@ -1,20 +1,39 @@
1
+ ### Ruby ###
1
2
  *.gem
2
3
  *.rbc
3
- .bundle
4
- .config
5
- .yardoc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /bin/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
6
31
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .rspec
19
- .vagrant
20
- integration/Berksfile.lock
32
+ .ruby-version
33
+ .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ ### Vagrant ###
39
+ .vagrant/
data/.travis.yml CHANGED
@@ -1,14 +1,16 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 2.0.0
4
- - 2.1.0
5
+ - 2.1
6
+
5
7
  notifications:
6
8
  irc:
7
9
  channels:
8
10
  - "irc.freenode.org#berkshelf"
9
11
  skip_join: true
10
12
  use_notice: true
13
+
11
14
  bundler_args: --without doc guard --jobs 7
12
- before_install:
13
- - sudo apt-get install -qq libgecode-dev
14
- script: 'bundle exec thor spec:ci'
15
+
16
+ script: bundle exec rake
data/CONTRIBUTING.md CHANGED
@@ -23,7 +23,7 @@ Install the latest version of [Bundler](http://gembundler.com)
23
23
 
24
24
  Clone the project
25
25
 
26
- $ git clone git://github.com/berkshelf/vagrant-berkshelf.git
26
+ $ git clone https://github.com/berkshelf/vagrant-berkshelf.git
27
27
 
28
28
  and run:
29
29
 
@@ -32,11 +32,11 @@ and run:
32
32
 
33
33
  Bundler will install all gems and their dependencies required for testing and developing.
34
34
 
35
- ### Running unit (RSpec) tests
35
+ ### Running tests
36
36
 
37
- One-time run with Thor
37
+ One-time run with Rake
38
38
 
39
- $ bundle exec thor spec
39
+ $ bundle exec rake spec
40
40
 
41
41
  Or you can setup a quick feedback loop with Guard
42
42
 
data/Gemfile CHANGED
@@ -3,11 +3,11 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.6.3'
6
+ gem 'vagrant', github: 'mitchellh/vagrant'
7
7
  end
8
8
 
9
9
  group :plugins do
10
- gem "vagrant-berkshelf", path: "."
10
+ gem 'vagrant-berkshelf', path: '.'
11
11
  end
12
12
 
13
13
  group :guard do
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2013 Riot Games
1
+ Copyright (c) 2012-2014 Riot Games
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,42 +1,85 @@
1
- # vagrant-berkshelf
1
+ Vagrant Berkshelf Plugin
2
+ ========================
3
+ [![Gem Version](http://img.shields.io/gem/v/vagrant-berkshelf.svg)][gem]
4
+ [![Build Status](http://img.shields.io/travis/berkshelf/vagrant-berkshelf.svg)][travis]
2
5
 
3
- [![Gem Version](https://badge.fury.io/rb/vagrant-berkshelf.png)](http://badge.fury.io/rb/vagrant-berkshelf)
4
- [![Build Status](https://travis-ci.org/berkshelf/vagrant-berkshelf.png?branch=master)](https://travis-ci.org/berkshelf/vagrant-berkshelf)
6
+ [gem]: https://rubygems.org/gems/vagrant-berkshelf
7
+ [travis]: http://travis-ci.org/berkshelf/vagrant-berkshelf
5
8
 
6
- A Vagrant plugin to add Berkshelf integration to the Chef provisioners
9
+ Vagrant Berkshelf is a Vagrant plugin that adds Berkshelf integration to the
10
+ Chef provisioners. Vagrant Berkshelf will automatically download and install
11
+ cookbooks onto the Vagrant Virtual Machine.
7
12
 
8
- ## Installation
9
13
 
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
+ Installation
15
+ ------------
16
+ 1. Install the latest version of [Vagrant](http://www.vagrantup.com/downloads.html)
17
+ 2. Install the latest version of [ChefDK](http://getchef.com/downloads/chef-dk)
18
+ 3. Install the Vagrant Berkshelf plugin:
13
19
 
14
- $ vagrant plugin install vagrant-berkshelf
20
+ $ vagrant plugin install vagrant-berkshelf
15
21
 
16
- ## Usage
17
22
 
18
- Once the Vagrant Berkshelf plugin is installed it can be enabled in your Vagrantfile
23
+ Usage
24
+ -----
25
+ If the Vagrant Berkshelf plugin is installed, it will intelligent detect when a
26
+ Berksfile is present in the same working directory as the Vagrantfile.
19
27
 
20
- Vagrant.configure("2") do |config|
21
- ...
22
- config.berkshelf.enabled = true
23
- ...
24
- end
28
+ Here is an example Vagrantfile configuration section for Vagrant Berkshelf:
25
29
 
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!
30
+ ```ruby
31
+ Vagrant.configure("2") do |config|
32
+ # The path to the Berksfile to use. The default value is "Berksfile" if one
33
+ # exists, or nil if it does not.
34
+ config.berkshelf.berksfile_path = "custom.Berksfile"
27
35
 
28
- > The Vagrant Berkshelf plugin does not support multi-machine Vagrantfiles.
36
+ # Enable Berkshelf. If a Berksfile exists or a berksfile_path is given, this
37
+ # value is automatically set to true. If not, the value is false
38
+ config.berkshelf.enabled = true
29
39
 
30
- ## Getting Help
40
+ # A list of Berkshelf groups to only install and sync to the Vagrant Virtual
41
+ # Machine. The default value is an empty array.
42
+ config.berkshelf.only = ["group_a", "group_b"]
31
43
 
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
44
+ # A list of Berkshelf groups to not install and sync to the Vagrant Virtual
45
+ # Machine. The default value is an empty array.
46
+ config.berkshelf.except = ["group_c", "group_d"]
34
47
 
35
- # Authors
48
+ # A list of extra values to pass to the `berks` executable. The default value
49
+ # is an empty array.
50
+ config.berkshelf.args = ["--format json"]
51
+ end
52
+ ```
36
53
 
37
- - Jamie Winsor (<jamie@vialstudios.com>)
38
- - Michael Ivey (<michael.ivey@riotgames.com>)
39
54
 
55
+ Contributing
56
+ ------------
40
57
  Thank you to all of our [Contributors](https://github.com/berkshelf/vagrant-berkshelf/graphs/contributors), testers, and users.
41
58
 
59
+ - Please report issues [on the GitHub issue tracker](https://github.com/berkshelf/berkshelf/issues)
60
+ - Hangout with us in #chef or #berkshelf on freenode
61
+
42
62
  If you'd like to contribute, please see our [contribution guidelines](https://github.com/berkshelf/vagrant-berkshelf/blob/master/CONTRIBUTING.md) first.
63
+
64
+
65
+ License & Authors
66
+ -----------------
67
+ - Jamie Winsor (jamie@vialstudios.com)
68
+ - Michael Ivey (michael.ivey@riotgames.com)
69
+ - Seth Vargo (sethvargo@gmail.com)
70
+
71
+ ```text
72
+ Copyright (c) 2012-2014 Riot Games
73
+
74
+ Licensed under the Apache License, Version 2.0 (the "License");
75
+ you may not use this file except in compliance with the License.
76
+ You may obtain a copy of the License at
77
+
78
+ http://www.apache.org/licenses/LICENSE-2.0
79
+
80
+ Unless required by applicable law or agreed to in writing, software
81
+ distributed under the License is distributed on an "AS IS" BASIS,
82
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83
+ See the License for the specific language governing permissions and
84
+ limitations under the License.
85
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = [].tap do |a|
6
+ a.push('--color')
7
+ a.push('--format progress')
8
+ end.join(' ')
9
+ end
10
+
11
+ desc 'Run all tests'
12
+ task :test => [:spec]
13
+
14
+ task :default => [:test]
@@ -1 +1,17 @@
1
- require 'berkshelf/vagrant'
1
+ require 'vagrant'
2
+
3
+ require_relative 'vagrant-berkshelf/config'
4
+ require_relative 'vagrant-berkshelf/plugin'
5
+ require_relative 'vagrant-berkshelf/version'
6
+
7
+ module VagrantPlugins
8
+ module Berkshelf
9
+ def self.berkshelf_path
10
+ ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
11
+ end
12
+
13
+ def self.shelves_path
14
+ File.join(berkshelf_path, 'vagrant-berkshelf', 'shelves')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ require 'vagrant/action'
2
+
3
+ require_relative '../helpers'
4
+
5
+ module VagrantPlugins
6
+ module Berkshelf
7
+ module Action
8
+ class Base
9
+ # Cleanup any shared folders before destroying the VM.
10
+ def self.clean
11
+ Vagrant::Action::Builder.new.tap do |b|
12
+ b.use setup
13
+ b.use Action::Clean
14
+ end
15
+ end
16
+
17
+ # Provision the VM, calling setup, install, and upload.
18
+ def self.provision
19
+ Vagrant::Action::Builder.new.tap do |b|
20
+ b.use Action::Install
21
+ b.use Action::Upload
22
+ end
23
+ end
24
+
25
+ # Setup all the required middlemare, including checking for the presence
26
+ # of Berkshelf, checking for the proper version of Berkshelf, and
27
+ # loading the datafile from disk.
28
+ def self.setup
29
+ Vagrant::Action::Builder.new.tap do |b|
30
+ b.use Action::Check
31
+ b.use Vagrant::Action::Builtin::EnvSet, berkshelf: Env.new
32
+ b.use Action::Load
33
+ b.use Action::Share
34
+ end
35
+ end
36
+
37
+ include VagrantPlugins::Berkshelf::Helpers
38
+
39
+ def initialize(app, env)
40
+ @app = app
41
+
42
+ klass = self.class.name.downcase.split('::').last
43
+ @logger = Log4r::Logger.new("vagrant::berkshelf::#{klass}")
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'base'
2
+
3
+ module VagrantPlugins
4
+ module Berkshelf
5
+ module Action
6
+ class Check < Base
7
+ BERKS_REQUIREMENT = "~> 3.2"
8
+
9
+ def call(env)
10
+ check_berks_bin!(env)
11
+ berkshelf_version_check!(env)
12
+
13
+ @app.call(env)
14
+ end
15
+
16
+ # Check that the Berkshelf `berks` bin is in the PATH.
17
+ # @raise [BerkshelfNotFound]
18
+ def check_berks_bin!(env)
19
+ if berks_bin.nil?
20
+ raise BerkshelfNotFound
21
+ end
22
+ end
23
+
24
+ # Check that the installed version of Berkshelf is valid for this
25
+ # version of Vagrant Berkshelf.
26
+ # @raise [InvalidBerkshelfVersionError]
27
+ def berkshelf_version_check!(env)
28
+ result = berks("--version", "--format", "json")
29
+
30
+ begin
31
+ json = JSON.parse(result.stdout, symbolize_names: true)
32
+ version = Gem::Version.new(json[:version])
33
+
34
+ unless Gem::Requirement.new(BERKS_REQUIREMENT).satisfied_by?(version)
35
+ raise InvalidBerkshelfVersionError.new(berks_bin, BERKS_REQUIREMENT, version)
36
+ end
37
+ rescue JSON::ParserError
38
+ raise InvalidBerkshelfVersionError.new(berks_bin, BERKS_REQUIREMENT, version)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'base'
2
+
3
+ module VagrantPlugins
4
+ module Berkshelf
5
+ module Action
6
+ class Clean < Base
7
+ def call(env)
8
+ if !berkshelf_enabled?(env)
9
+ @logger.info "Berkshelf disabled, skipping"
10
+ return @app.call(env)
11
+ end
12
+
13
+ env[:machine].ui.info "Running cleanup tasks for 'berkshelf'..."
14
+
15
+ if env[:berkshelf].shelf
16
+ if File.exist?(env[:berkshelf].shelf)
17
+ FileUtils.rm_rf(env[:berkshelf].shelf)
18
+ env[:berkshelf].shelf = nil
19
+ else
20
+ @logger.warn "The Berkshelf shelf did not exist for cleanup!"
21
+ end
22
+ end
23
+
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'base'
2
+
3
+ module VagrantPlugins
4
+ module Berkshelf
5
+ module Action
6
+ class Install < Base
7
+ def call(env)
8
+ if !berkshelf_enabled?(env)
9
+ @logger.info "Berkshelf disabled, skipping"
10
+ return @app.call(env)
11
+ end
12
+
13
+ if !provision_enabled?(env)
14
+ @logger.info "Provisioning disabled, skipping"
15
+ return @app.call(env)
16
+ end
17
+
18
+ vendor(env)
19
+ @app.call(env)
20
+ end
21
+
22
+ # Vendor the cookbooks in the Berkshelf shelf.
23
+ def vendor(env)
24
+ shelf = env[:berkshelf].shelf
25
+ env[:machine].ui.info "Updating Vagrant's Berkshelf..."
26
+
27
+ options = env[:machine].config.berkshelf.to_hash
28
+
29
+ result = berks('vendor', shelf, options)
30
+ env[:machine].ui.output(result.stdout)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end