berkshelf-vagrant 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/berkshelf/vagrant/action.rb +51 -49
- data/lib/berkshelf/vagrant/action/clean.rb +20 -18
- data/lib/berkshelf/vagrant/action/configure_chef.rb +16 -14
- data/lib/berkshelf/vagrant/action/install.rb +27 -25
- data/lib/berkshelf/vagrant/action/load_shelf.rb +33 -31
- data/lib/berkshelf/vagrant/action/set_ui.rb +12 -10
- data/lib/berkshelf/vagrant/action/upload.rb +31 -29
- data/lib/berkshelf/vagrant/env.rb +18 -16
- data/lib/berkshelf/vagrant/env_helpers.rb +41 -39
- data/lib/berkshelf/vagrant/plugin.rb +26 -24
- data/lib/berkshelf/vagrant/version.rb +1 -1
- metadata +2 -2
@@ -1,59 +1,61 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
autoload :Clean, 'berkshelf/vagrant/action/clean'
|
5
|
+
autoload :ConfigureChef, 'berkshelf/vagrant/action/configure_chef'
|
6
|
+
autoload :Install, 'berkshelf/vagrant/action/install'
|
7
|
+
autoload :LoadShelf, 'berkshelf/vagrant/action/load_shelf'
|
8
|
+
autoload :SetUI, 'berkshelf/vagrant/action/set_ui'
|
9
|
+
autoload :Upload, 'berkshelf/vagrant/action/upload'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
class << self
|
12
|
+
# Return the Berkshelf install middleware stack. When placed in the action chain
|
13
|
+
# this stack will find retrieve and resolve the cookbook dependencies describe
|
14
|
+
# in your configured Berksfile.
|
15
|
+
#
|
16
|
+
# Cookbooks will installed into a temporary directory, called a Shelf, and mounted
|
17
|
+
# into the VM. This mounted path will be appended to the chef_solo.cookbooks_path value.
|
18
|
+
#
|
19
|
+
# @return [::Vagrant::Action::Builder]
|
20
|
+
def install
|
21
|
+
@install ||= ::Vagrant::Action::Builder.new.tap do |b|
|
22
|
+
b.use Berkshelf::Vagrant::Action::Install
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
# Return the Berkshelf upload middleware stack. When placed in the action chain
|
27
|
+
# this stack will upload cookbooks to a Chef Server if the Chef-Client provisioner
|
28
|
+
# is used. The Chef Server where the cookbooks will be uploaded to is the same Chef
|
29
|
+
# Server used in the Chef-Client provisioner.
|
30
|
+
#
|
31
|
+
# Nothing will be done if the Chef-Solo provisioner is used.
|
32
|
+
#
|
33
|
+
# @return [::Vagrant::Action::Builder]
|
34
|
+
def upload
|
35
|
+
@upload ||= ::Vagrant::Action::Builder.new.tap do |b|
|
36
|
+
b.use Berkshelf::Vagrant::Action::Upload
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
# Return the Berkshelf clean middleware stack. When placed in the action chain
|
41
|
+
# this stack will clean up any temporary directories or files created by the other
|
42
|
+
# middleware stacks.
|
43
|
+
#
|
44
|
+
# @return [::Vagrant::Action::Builder]
|
45
|
+
def clean
|
46
|
+
@clean ||= ::Vagrant::Action::Builder.new.tap do |b|
|
47
|
+
b.use setup
|
48
|
+
b.use Berkshelf::Vagrant::Action::Clean
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def setup
|
53
|
+
@setup ||= ::Vagrant::Action::Builder.new.tap do |b|
|
54
|
+
b.use ::Vagrant::Action::Builtin::EnvSet, berkshelf: Berkshelf::Vagrant::Env.new
|
55
|
+
b.use Berkshelf::Vagrant::Action::SetUI
|
56
|
+
b.use Berkshelf::Vagrant::Action::LoadShelf
|
57
|
+
b.use Berkshelf::Vagrant::Action::ConfigureChef
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
+
class Clean
|
6
|
+
include Berkshelf::Vagrant::EnvHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def call(env)
|
13
|
+
if env[:berkshelf].shelf && File.exist?(env[:berkshelf].shelf)
|
14
|
+
env[:berkshelf].ui.info "Cleaning Vagrant's berkshelf"
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
FileUtils.remove_dir(env[:berkshelf].shelf, force: true)
|
17
|
+
FileUtils.rm_f(cache_file)
|
18
|
+
env[:berkshelf].shelf = nil
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
@app.call(env)
|
22
|
+
rescue Berkshelf::BerkshelfError => e
|
23
|
+
raise Berkshelf::VagrantWrapperError.new(e)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
+
class ConfigureChef
|
6
|
+
include Berkshelf::Vagrant::EnvHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def call(env)
|
13
|
+
if chef_solo?(env) && env[:berkshelf].shelf
|
14
|
+
provisioners(:chef_solo, env).each do |provisioner|
|
15
|
+
provisioner.config.cookbooks_path = provisioner.config.send(:prepare_folders_config, env[:berkshelf].shelf)
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
+
@app.call(env)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,34 +1,36 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
+
class Install
|
6
|
+
include Berkshelf::Vagrant::EnvHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
env[:berkshelf].berksfile = Berkshelf::Berksfile.from_file(env[:global_config].berkshelf.berksfile_path)
|
13
|
-
|
14
|
-
if chef_solo?(env)
|
15
|
-
install(env)
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
raise VagrantWrapperError.new(e)
|
21
|
-
end
|
12
|
+
def call(env)
|
13
|
+
env[:berkshelf].berksfile = Berkshelf::Berksfile.from_file(env[:global_config].berkshelf.berksfile_path)
|
22
14
|
|
23
|
-
|
15
|
+
if chef_solo?(env)
|
16
|
+
install(env)
|
17
|
+
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
path: env[:berkshelf].shelf
|
29
|
-
}.merge(env[:global_config].berkshelf.to_hash).symbolize_keys!
|
30
|
-
env[:berkshelf].berksfile.install(opts)
|
19
|
+
@app.call(env)
|
20
|
+
rescue Berkshelf::BerkshelfError => e
|
21
|
+
raise Berkshelf::VagrantWrapperError.new(e)
|
31
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def install(env)
|
27
|
+
env[:berkshelf].ui.info "Updating Vagrant's berkshelf: '#{env[:berkshelf].shelf}'"
|
28
|
+
opts = {
|
29
|
+
path: env[:berkshelf].shelf
|
30
|
+
}.merge(env[:global_config].berkshelf.to_hash).symbolize_keys!
|
31
|
+
env[:berkshelf].berksfile.install(opts)
|
32
|
+
end
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,43 +1,45 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
shelf = load_shelf
|
13
|
-
|
14
|
-
if shelf.nil?
|
15
|
-
shelf = cache_shelf(Berkshelf::Vagrant.mkshelf)
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
+
class LoadShelf
|
6
|
+
include Berkshelf::Vagrant::EnvHelpers
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
16
10
|
end
|
17
11
|
|
18
|
-
env
|
12
|
+
def call(env)
|
13
|
+
shelf = load_shelf
|
19
14
|
|
20
|
-
|
21
|
-
|
15
|
+
if shelf.nil?
|
16
|
+
shelf = cache_shelf(Berkshelf::Vagrant.mkshelf)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
#
|
25
|
-
# @return [String]
|
26
|
-
def cache_shelf(path)
|
27
|
-
FileUtils.mkdir_p(File.dirname(path))
|
19
|
+
env[:berkshelf].shelf = shelf
|
28
20
|
|
29
|
-
|
30
|
-
f.write(path)
|
21
|
+
@app.call(env)
|
31
22
|
end
|
32
23
|
|
33
|
-
path
|
34
|
-
|
24
|
+
# @param [String] path
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def cache_shelf(path)
|
28
|
+
FileUtils.mkdir_p(File.dirname(path))
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
File.open(cache_file, 'w+') do |f|
|
31
|
+
f.write(path)
|
32
|
+
end
|
39
33
|
|
40
|
-
|
34
|
+
path
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String, nil]
|
38
|
+
def load_shelf
|
39
|
+
return nil unless File.exist?(cache_file)
|
40
|
+
|
41
|
+
File.read(cache_file).chomp
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def call(env)
|
11
|
+
Berkshelf.ui = env[:berkshelf].ui
|
12
|
+
@app.call(env)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,38 +1,40 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
module Action
|
4
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
5
|
+
class Upload
|
6
|
+
include Berkshelf::Vagrant::EnvHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
if chef_client?(env)
|
13
|
-
upload(env)
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
14
10
|
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def call(env)
|
13
|
+
if chef_client?(env)
|
14
|
+
upload(env)
|
15
|
+
end
|
20
16
|
|
21
|
-
|
17
|
+
@app.call(env)
|
18
|
+
rescue Berkshelf::BerkshelfError => e
|
19
|
+
raise Berkshelf::VagrantWrapperError.new(e)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
def upload(env)
|
25
|
+
provisioners(:chef_client, env).each do |provisioner|
|
26
|
+
env[:berkshelf].ui.info "Uploading cookbooks to '#{provisioner.config.chef_server_url}'"
|
27
|
+
env[:berkshelf].berksfile.upload(
|
28
|
+
server_url: provisioner.config.chef_server_url,
|
29
|
+
client_name: env[:berkshelf].config.chef.node_name,
|
30
|
+
client_key: env[:berkshelf].config.chef.client_key,
|
31
|
+
ssl: {
|
32
|
+
verify: env[:berkshelf].config.ssl.verify
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
34
36
|
end
|
35
|
-
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
4
|
+
#
|
5
|
+
# Environment data to build up and persist through the middleware chain
|
6
|
+
class Env
|
7
|
+
# @return [Vagrant::UI::Colored]
|
8
|
+
attr_accessor :ui
|
9
|
+
# @return [Berkshelf::Berksfile]
|
10
|
+
attr_accessor :berksfile
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :shelf
|
13
|
+
# @return [Berkshelf::Config]
|
14
|
+
attr_accessor :config
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def initialize
|
17
|
+
@ui = ::Vagrant::UI::Colored.new('Berkshelf')
|
18
|
+
@config = Berkshelf::Config.instance
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -1,46 +1,48 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
|
3
|
-
|
4
|
-
# A module of common helper functions that can be mixed into Berkshelf::Vagrant actions
|
5
|
-
module EnvHelpers
|
6
|
-
# A file to persist berkshelf-vagrant specific information in between
|
7
|
-
# Vagrant runs.
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
8
4
|
#
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
# A module of common helper functions that can be mixed into Berkshelf::Vagrant actions
|
6
|
+
module EnvHelpers
|
7
|
+
# A file to persist berkshelf-vagrant specific information in between
|
8
|
+
# Vagrant runs.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
def cache_file
|
12
|
+
File.join('.vagrant', 'berkshelf')
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
# Filter all of the provisioners of the given vagrant environment with the given name
|
16
|
+
#
|
17
|
+
# @param [Symbol] name
|
18
|
+
# name of provisioner to filter
|
19
|
+
# @param [Vagrant::Environment, Hash] env
|
20
|
+
# environment to inspect
|
21
|
+
#
|
22
|
+
# @return [Array]
|
23
|
+
def provisioners(name, env)
|
24
|
+
config_global = env.respond_to?(:config_global) ? env.config_global : env[:global_config]
|
25
|
+
|
26
|
+
config_global.vm.provisioners.select { |prov| prov.name == name }
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
# Determine if the given vagrant environment contains a chef_solo provisioner
|
30
|
+
#
|
31
|
+
# @param [Vagrant::Environment] env
|
32
|
+
#
|
33
|
+
# @return [Boolean]
|
34
|
+
def chef_solo?(env)
|
35
|
+
provisioners(:chef_solo, env).any?
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# Determine if the given vagrant environment contains a chef_client provisioner
|
39
|
+
#
|
40
|
+
# @param [Vagrant::Environment] env
|
41
|
+
#
|
42
|
+
# @return [Boolean]
|
43
|
+
def chef_client?(env)
|
44
|
+
provisioners(:chef_client, env).any?
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
hook
|
7
|
-
|
8
|
-
|
1
|
+
module Berkshelf
|
2
|
+
module Vagrant
|
3
|
+
# @author Jamie Winsor <reset@riotgames.com>
|
4
|
+
class Plugin < ::Vagrant.plugin("2")
|
5
|
+
class << self
|
6
|
+
def provision(hook)
|
7
|
+
hook.after(::Vagrant::Action::Builtin::Provision, Berkshelf::Vagrant::Action.upload)
|
8
|
+
hook.after(::Vagrant::Action::Builtin::Provision, Berkshelf::Vagrant::Action.install)
|
9
|
+
hook.before(::Vagrant::Action::Builtin::ConfigValidate, Berkshelf::Vagrant::Action.setup)
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
name "berkshelf"
|
14
|
+
description <<-DESC
|
15
|
+
Automatically make available cookbooks to virtual machines provisioned by Chef Solo
|
16
|
+
or Chef Client using Berkshelf.
|
17
|
+
DESC
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
action_hook(:berkshelf_provision, :machine_action_up, &method(:provision))
|
20
|
+
action_hook(:berkshelf_provision, :machine_action_provision, &method(:provision))
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
action_hook(:berkshelf_cleanup, :machine_action_destroy) do |hook|
|
23
|
+
# @todo this should be appended to the middleware stack instead of hooked in after the
|
24
|
+
# Virtualbox specific destroy step but there is a bug in Vagrant (1.1.0) which
|
25
|
+
# causes appended middleware to run multiple times.
|
26
|
+
hook.after(VagrantPlugins::ProviderVirtualBox::Action::DestroyUnusedNetworkInterfaces, Berkshelf::Vagrant::Action.clean)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
config(:berkshelf) do
|
30
|
+
Berkshelf::Vagrant::Config
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berkshelf-vagrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
240
|
version: '0'
|
241
241
|
segments:
|
242
242
|
- 0
|
243
|
-
hash: -
|
243
|
+
hash: -1000128588332199351
|
244
244
|
requirements: []
|
245
245
|
rubyforge_project:
|
246
246
|
rubygems_version: 1.8.24
|