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.
- checksums.yaml +4 -4
- data/.gitignore +36 -17
- data/.travis.yml +6 -4
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +2 -2
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +67 -24
- data/Rakefile +14 -0
- data/lib/vagrant-berkshelf.rb +17 -1
- data/lib/vagrant-berkshelf/action/base.rb +48 -0
- data/lib/vagrant-berkshelf/action/check.rb +44 -0
- data/lib/vagrant-berkshelf/action/clean.rb +29 -0
- data/lib/vagrant-berkshelf/action/install.rb +35 -0
- data/lib/vagrant-berkshelf/action/load.rb +59 -0
- data/lib/vagrant-berkshelf/action/share.rb +38 -0
- data/lib/vagrant-berkshelf/action/upload.rb +99 -0
- data/lib/vagrant-berkshelf/config.rb +87 -0
- data/lib/vagrant-berkshelf/env.rb +14 -0
- data/lib/vagrant-berkshelf/errors.rb +79 -0
- data/lib/vagrant-berkshelf/helpers.rb +180 -0
- data/lib/vagrant-berkshelf/plugin.rb +40 -0
- data/lib/vagrant-berkshelf/version.rb +5 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/unit/vagrant-berkshelf/config_spec.rb +119 -0
- data/vagrant-berkshelf.gemspec +26 -14
- metadata +35 -52
- data/Thorfile +0 -59
- data/integration/Berksfile +0 -3
- data/integration/Gemfile +0 -10
- data/integration/Vagrantfile +0 -19
- data/lib/berkshelf/vagrant.rb +0 -68
- data/lib/berkshelf/vagrant/action.rb +0 -64
- data/lib/berkshelf/vagrant/action/clean.rb +0 -27
- data/lib/berkshelf/vagrant/action/configure_chef.rb +0 -27
- data/lib/berkshelf/vagrant/action/install.rb +0 -69
- data/lib/berkshelf/vagrant/action/load_shelf.rb +0 -52
- data/lib/berkshelf/vagrant/action/upload.rb +0 -53
- data/lib/berkshelf/vagrant/berks_config.rb +0 -48
- data/lib/berkshelf/vagrant/chef_config.rb +0 -88
- data/lib/berkshelf/vagrant/config.rb +0 -113
- data/lib/berkshelf/vagrant/env.rb +0 -16
- data/lib/berkshelf/vagrant/env_helpers.rb +0 -160
- data/lib/berkshelf/vagrant/errors.rb +0 -71
- data/lib/berkshelf/vagrant/plugin.rb +0 -41
- data/lib/berkshelf/vagrant/version.rb +0 -5
- data/spec/unit/berkshelf/vagrant/config_spec.rb +0 -97
- data/spec/unit/berkshelf/vagrant/errors_spec.rb +0 -12
- data/spec/unit/berkshelf/vagrant_spec.rb +0 -31
data/integration/Berksfile
DELETED
data/integration/Gemfile
DELETED
data/integration/Vagrantfile
DELETED
@@ -1,19 +0,0 @@
|
|
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
|
data/lib/berkshelf/vagrant.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'vagrant'
|
3
|
-
rescue LoadError
|
4
|
-
raise 'The Vagrant Berkshelf plugin must be run within Vagrant.'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'fileutils'
|
8
|
-
require 'json'
|
9
|
-
require 'tmpdir'
|
10
|
-
|
11
|
-
require_relative 'vagrant/errors'
|
12
|
-
require_relative 'vagrant/version'
|
13
|
-
|
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
|
-
|
28
|
-
module Vagrant
|
29
|
-
require_relative 'vagrant/chef_config'
|
30
|
-
require_relative 'vagrant/berks_config'
|
31
|
-
require_relative 'vagrant/action'
|
32
|
-
require_relative 'vagrant/config'
|
33
|
-
require_relative 'vagrant/env'
|
34
|
-
require_relative 'vagrant/env_helpers'
|
35
|
-
|
36
|
-
TESTED_REQUIREMENTS = [">= 1.1", "< 1.5.0"]
|
37
|
-
|
38
|
-
class << self
|
39
|
-
# The path to where shelfs are created on the host machine to be mounted in
|
40
|
-
# Vagrant guests
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
def shelf_path
|
44
|
-
File.join(Berkshelf.berkshelf_path, 'vagrant')
|
45
|
-
end
|
46
|
-
|
47
|
-
# Generate a new shelf to be mounted in a Vagrant guest
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
# path to the generated shelf
|
51
|
-
def mkshelf(machine_name = nil)
|
52
|
-
unless File.exist?(shelf_path)
|
53
|
-
FileUtils.mkdir_p(shelf_path)
|
54
|
-
end
|
55
|
-
|
56
|
-
if machine_name.nil?
|
57
|
-
prefix_suffix = 'berkshelf-'
|
58
|
-
else
|
59
|
-
prefix_suffix = ['berkshelf-', "-#{machine_name}"]
|
60
|
-
end
|
61
|
-
|
62
|
-
Dir.mktmpdir(prefix_suffix, shelf_path)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
require_relative 'vagrant/plugin'
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
require_relative 'env'
|
5
|
-
require_relative 'env_helpers'
|
6
|
-
|
7
|
-
require_relative 'action/clean'
|
8
|
-
require_relative 'action/configure_chef'
|
9
|
-
require_relative 'action/install'
|
10
|
-
require_relative 'action/load_shelf'
|
11
|
-
require_relative 'action/upload'
|
12
|
-
|
13
|
-
class << self
|
14
|
-
# Return the Berkshelf install middleware stack. When placed in the action chain
|
15
|
-
# this stack will find retrieve and resolve the cookbook dependencies describe
|
16
|
-
# in your configured Berksfile.
|
17
|
-
#
|
18
|
-
# Cookbooks will install into a temporary directory, called a Shelf, and be mounted
|
19
|
-
# into the VM. This mounted path will be appended to the chef_solo.cookbooks_path value.
|
20
|
-
#
|
21
|
-
# @return [::Vagrant::Action::Builder]
|
22
|
-
def install
|
23
|
-
@install ||= ::Vagrant::Action::Builder.new.tap do |b|
|
24
|
-
b.use Berkshelf::Vagrant::Action::Install
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Return the Berkshelf upload middleware stack. When placed in the action chain
|
29
|
-
# this stack will upload cookbooks to a Chef Server if the Chef-Client provisioner
|
30
|
-
# is used. The Chef Server where the cookbooks will be uploaded to is the same Chef
|
31
|
-
# Server used in the Chef-Client provisioner.
|
32
|
-
#
|
33
|
-
# Nothing will be done if the Chef-Solo provisioner is used.
|
34
|
-
#
|
35
|
-
# @return [::Vagrant::Action::Builder]
|
36
|
-
def upload
|
37
|
-
@upload ||= ::Vagrant::Action::Builder.new.tap do |b|
|
38
|
-
b.use Berkshelf::Vagrant::Action::Upload
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return the Berkshelf clean middleware stack. When placed in the action chain
|
43
|
-
# this stack will clean up any temporary directories or files created by the other
|
44
|
-
# middleware stacks.
|
45
|
-
#
|
46
|
-
# @return [::Vagrant::Action::Builder]
|
47
|
-
def clean
|
48
|
-
@clean ||= ::Vagrant::Action::Builder.new.tap do |b|
|
49
|
-
b.use setup
|
50
|
-
b.use Berkshelf::Vagrant::Action::Clean
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def setup
|
55
|
-
@setup ||= ::Vagrant::Action::Builder.new.tap do |b|
|
56
|
-
b.use ::Vagrant::Action::Builtin::EnvSet, berkshelf: Berkshelf::Vagrant::Env.new
|
57
|
-
b.use Berkshelf::Vagrant::Action::LoadShelf
|
58
|
-
b.use Berkshelf::Vagrant::Action::ConfigureChef
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
class Clean
|
5
|
-
include Berkshelf::Vagrant::EnvHelpers
|
6
|
-
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
if env[:berkshelf].shelf && File.exist?(env[:berkshelf].shelf)
|
13
|
-
env[:berkshelf].ui.info "Cleaning Vagrant's berkshelf"
|
14
|
-
|
15
|
-
FileUtils.remove_dir(env[:berkshelf].shelf, force: true)
|
16
|
-
FileUtils.rm_f(cache_file(env))
|
17
|
-
env[:berkshelf].shelf = nil
|
18
|
-
end
|
19
|
-
|
20
|
-
@app.call(env)
|
21
|
-
rescue Berkshelf::BerkshelfError => e
|
22
|
-
raise Berkshelf::VagrantWrapperError.new(e)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
class ConfigureChef
|
5
|
-
include Berkshelf::Vagrant::EnvHelpers
|
6
|
-
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
unless berkshelf_enabled?(env)
|
13
|
-
return @app.call(env)
|
14
|
-
end
|
15
|
-
|
16
|
-
if chef_solo?(env) && shelf = env[:berkshelf].shelf
|
17
|
-
provisioners(:chef_solo, env).each do |provisioner|
|
18
|
-
provisioner.config.cookbooks_path = provisioner.config.send(:prepare_folders_config, shelf)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
@app.call(env)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
class Install
|
5
|
-
include Berkshelf::Vagrant::EnvHelpers
|
6
|
-
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
if provision_disabled?(env)
|
13
|
-
env[:berkshelf].ui.info "Skipping Berkshelf with --no-provision"
|
14
|
-
|
15
|
-
return @app.call(env)
|
16
|
-
end
|
17
|
-
|
18
|
-
unless berkshelf_enabled?(env)
|
19
|
-
if File.exist?(berksfile_path(env))
|
20
|
-
warn_disabled_but_berksfile_exists(env)
|
21
|
-
end
|
22
|
-
|
23
|
-
return @app.call(env)
|
24
|
-
end
|
25
|
-
|
26
|
-
if chef_solo?(env)
|
27
|
-
vendor(env)
|
28
|
-
end
|
29
|
-
|
30
|
-
@app.call(env)
|
31
|
-
rescue => ex
|
32
|
-
raise Berkshelf::VagrantWrapperError.new(ex)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def vendor(env)
|
38
|
-
check_vagrant_version(env)
|
39
|
-
env[:berkshelf].ui.info "Updating Vagrant's berkshelf: '#{env[:berkshelf].shelf}'"
|
40
|
-
FileUtils.rm_rf(env[:berkshelf].shelf)
|
41
|
-
|
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
|
-
end
|
49
|
-
|
50
|
-
def warn_disabled_but_berksfile_exists(env)
|
51
|
-
env[:berkshelf].ui.warn "Berkshelf plugin is disabled but a Berksfile was found at" +
|
52
|
-
" your configured path: #{berksfile_path(env)}"
|
53
|
-
env[:berkshelf].ui.warn "Enable the Berkshelf plugin by setting 'config.berkshelf.enabled = true'" +
|
54
|
-
" in your vagrant config"
|
55
|
-
end
|
56
|
-
|
57
|
-
def check_vagrant_version(env)
|
58
|
-
unless vagrant_version_satisfies?(">= 1.5")
|
59
|
-
raise UnsupportedVagrantVersion.new(">= 1.5")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def vagrant_version_satisfies?(requirements)
|
64
|
-
Gem::Requirement.new(requirements).satisfied_by? Gem::Version.new(::Vagrant::VERSION)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module Vagrant
|
3
|
-
module Action
|
4
|
-
class LoadShelf
|
5
|
-
include Berkshelf::Vagrant::EnvHelpers
|
6
|
-
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
unless berkshelf_enabled?(env)
|
13
|
-
return @app.call(env)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Make sure that Berkshelf itself uses distinct directories for each vagrant run.
|
17
|
-
ENV['BERKSHELF_PATH'] ||= File.join(Berkshelf.berkshelf_path, env[:machine].name.to_s)
|
18
|
-
|
19
|
-
shelf = load_shelf(env)
|
20
|
-
|
21
|
-
if shelf.nil?
|
22
|
-
shelf = cache_shelf(Berkshelf::Vagrant.mkshelf(env[:machine].name), env)
|
23
|
-
end
|
24
|
-
|
25
|
-
env[:berkshelf].shelf = shelf
|
26
|
-
|
27
|
-
@app.call(env)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param [String] path
|
31
|
-
#
|
32
|
-
# @return [String]
|
33
|
-
def cache_shelf(path, env)
|
34
|
-
FileUtils.mkdir_p(File.dirname(path))
|
35
|
-
|
36
|
-
File.open((cache_file(env)), 'w+') do |f|
|
37
|
-
f.write(path)
|
38
|
-
end
|
39
|
-
|
40
|
-
path
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [String, nil]
|
44
|
-
def load_shelf(env)
|
45
|
-
return nil unless File.exist?(cache_file(env))
|
46
|
-
|
47
|
-
File.read(cache_file(env)).chomp
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
module Berkshelf
|
4
|
-
module Vagrant
|
5
|
-
module Action
|
6
|
-
class Upload
|
7
|
-
include Berkshelf::Vagrant::EnvHelpers
|
8
|
-
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
if provision_disabled?(env)
|
15
|
-
return @app.call(env)
|
16
|
-
end
|
17
|
-
|
18
|
-
unless berkshelf_enabled?(env)
|
19
|
-
return @app.call(env)
|
20
|
-
end
|
21
|
-
|
22
|
-
if chef_client?(env)
|
23
|
-
upload(env)
|
24
|
-
end
|
25
|
-
|
26
|
-
@app.call(env)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def upload(env)
|
32
|
-
provisioners(:chef_client, env).each do |provisioner|
|
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
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,48 +0,0 @@
|
|
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
|
-
# Instantiate and return or just return the currently instantiated Berkshelf
|
23
|
-
# configuration
|
24
|
-
#
|
25
|
-
# @return [Config]
|
26
|
-
def instance
|
27
|
-
@instance ||= if File.exists?(path) && File.readable?(path)
|
28
|
-
new(JSON.parse(File.read(path)))
|
29
|
-
else
|
30
|
-
new
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(attributes = {})
|
36
|
-
attributes.merge!(chef: ChefConfig.instance, ssl: ::Vagrant::Util::HashWithIndifferentAccess.new(verify: false))
|
37
|
-
super(attributes)
|
38
|
-
end
|
39
|
-
|
40
|
-
def chef
|
41
|
-
self[:chef]
|
42
|
-
end
|
43
|
-
|
44
|
-
def ssl
|
45
|
-
self[:ssl]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|