vagrant-cookbook-fetcher 0.0.6 → 0.0.7
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/README.md +5 -4
- data/lib/vagrant_cookbook_fetcher.rb +119 -90
- metadata +39 -40
data/README.md
CHANGED
@@ -5,7 +5,7 @@ A Vagrant plugin to automatically fetch cookbooks, roles, and such whenever you
|
|
5
5
|
|
6
6
|
## Behavior
|
7
7
|
|
8
|
-
Once you set a URL that provides a list of checkouts, this plugin will create two directory trees:
|
8
|
+
Once you set a URL in your Vagrantfile that provides a list of checkouts, this plugin will create two directory trees (checkouts and combined):
|
9
9
|
|
10
10
|
my-vagrant-project
|
11
11
|
|...Vagrantfile
|
@@ -16,6 +16,7 @@ Once you set a URL that provides a list of checkouts, this plugin will create tw
|
|
16
16
|
|...roles
|
17
17
|
|...nodes
|
18
18
|
|...data_bags
|
19
|
+
|...specs
|
19
20
|
|
20
21
|
The plugin will loop through the list of checkouts, perform a clone/checkout or pull/update to make sure the checkout exists in the 'checkouts' directory.
|
21
22
|
|
@@ -38,7 +39,7 @@ The fields are: VCS,repo address, directory name, branch, credentials
|
|
38
39
|
|
39
40
|
## Configuration
|
40
41
|
|
41
|
-
### config.
|
42
|
+
### config.cookbook_fetcher.url
|
42
43
|
|
43
44
|
Default: none.
|
44
45
|
|
@@ -46,11 +47,11 @@ URL that replies with a CSV file containing the list of checkouts.
|
|
46
47
|
|
47
48
|
If absent, no fetch occurs.
|
48
49
|
|
49
|
-
### config.
|
50
|
+
### config.cookbook_fetcher.disable
|
50
51
|
|
51
52
|
Default: false
|
52
53
|
|
53
|
-
If true, no checkout will be be run. This can be useful if you're provisioning frequently and making local changes to your recipes.
|
54
|
+
If true, no checkout will be be run. This can be useful if you're provisioning frequently and making local changes to your recipes; if you use git rebase, your build will break whenever you have a local change and an incoming change at the same time.
|
54
55
|
|
55
56
|
Even if the fetch is disabled, this plugin will still try to tell chef-solo about your cookbook, role, and data_bag paths, unless you override them.
|
56
57
|
|
@@ -1,51 +1,41 @@
|
|
1
|
+
module CookbookFetcher
|
1
2
|
|
2
|
-
# http://vagrantup.com/v1/docs/extending/configuration.html
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
Vagrant.config_keys.register(:cookbook_fetcher) { CookbookFetcherConfig }
|
8
|
-
|
9
|
-
|
10
|
-
# This is a Vagrant middleware plugin
|
11
|
-
# http://vagrantup.com/v1/docs/extending/middleware.html
|
12
|
-
|
13
|
-
class CookbookFetcher
|
14
|
-
def initialize(app, env)
|
15
|
-
@app = app
|
3
|
+
# http://vagrantup.com/v1/docs/extending/configuration.html
|
4
|
+
class Config < Vagrant::Config::Base
|
5
|
+
attr_accessor :url
|
6
|
+
attr_accessor :disable
|
16
7
|
end
|
8
|
+
Vagrant.config_keys.register(:cookbook_fetcher) { CookbookFetcher::Config }
|
17
9
|
|
18
|
-
|
10
|
+
# Utility method - reads the config, fetches the checkout list,
|
11
|
+
# does the checkout, and does the crosslinks. Expects cwd to be the root_path.
|
12
|
+
def perform_fetch (global_config, logger)
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
env[:ui].warn "No URL set for auto-checkout, skipping"
|
25
|
-
end
|
26
|
-
else
|
27
|
-
env[:ui].info "Auto-checkout disabled, skipping"
|
14
|
+
unless global_config.cookbook_fetcher then
|
15
|
+
logger.warn "No config.cookbook_fetcher section found in Vagrantfile - skipping checkouts"
|
16
|
+
return
|
28
17
|
end
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def fetch_checkouts (env)
|
36
|
-
url = env[:global_config].cookbook_fetcher.url
|
37
|
-
env[:ui].info "Fetching checkout list from #{url}"
|
19
|
+
url = global_config.cookbook_fetcher.url
|
20
|
+
unless url then
|
21
|
+
logger.warn "No config.cookbook_fetcher.url value found in Vagrantfile - skipping checkouts"
|
22
|
+
return
|
23
|
+
end
|
38
24
|
|
39
|
-
checkouts = fetch_checkout_list
|
40
|
-
perform_checkouts
|
41
|
-
update_links
|
25
|
+
checkouts = CookbookFetcher.fetch_checkout_list(url,logger)
|
26
|
+
CookbookFetcher.perform_checkouts(checkouts,logger)
|
27
|
+
CookbookFetcher.update_links(checkouts,logger)
|
42
28
|
end
|
29
|
+
module_function :perform_fetch
|
43
30
|
|
44
|
-
|
31
|
+
# Utility method, fetches checkout list, parses it,
|
32
|
+
# and writes cookbook order to a file in the current working directory.
|
33
|
+
def fetch_checkout_list (url, logger)
|
45
34
|
require 'open-uri'
|
46
|
-
|
35
|
+
|
47
36
|
checkouts = { :by_dir => {}, :cookbook_list => [] }
|
48
37
|
|
38
|
+
logger.info "Fetching checkout list from #{url}"
|
49
39
|
open(url, {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE }) do |resp|
|
50
40
|
resp.each do |line|
|
51
41
|
line.chomp!
|
@@ -70,22 +60,23 @@ class CookbookFetcher
|
|
70
60
|
File.open('.cookbook-order', 'w') do |f|
|
71
61
|
f.print(checkouts[:cookbook_list].join("\n"))
|
72
62
|
end
|
73
|
-
|
74
63
|
end
|
75
64
|
end
|
76
65
|
end
|
77
|
-
|
78
66
|
return checkouts
|
79
|
-
|
80
67
|
end
|
68
|
+
module_function :fetch_checkout_list
|
81
69
|
|
82
|
-
|
70
|
+
# Utility method. Based on a parsed checkout list,
|
71
|
+
# performs each of the checkouts, creating the checkouts/ directory in
|
72
|
+
# the current directory.
|
73
|
+
def perform_checkouts (checkouts,logger)
|
83
74
|
|
84
75
|
if !Dir.exists?("checkouts") then Dir.mkdir("checkouts") end
|
85
76
|
|
86
77
|
Dir.chdir("checkouts") do
|
87
78
|
checkouts[:by_dir].each do |dir, info|
|
88
|
-
|
79
|
+
logger.info "Updating checkout '#{dir}'"
|
89
80
|
if info[:vcs] == 'git' then
|
90
81
|
|
91
82
|
if Dir.exists?(info[:dir]) then
|
@@ -103,11 +94,11 @@ class CookbookFetcher
|
|
103
94
|
unless system cmd then raise "Could not find branch or commit #{info[:branch]}" end
|
104
95
|
cmd = "git checkout -b #{info[:branch]} origin/#{info[:branch]}"
|
105
96
|
unless system cmd then raise "Could not '#{cmd}'" end
|
106
|
-
|
97
|
+
# no branch
|
107
98
|
elsif local_branch.empty? then
|
108
99
|
cmd = "git checkout #{info[:branch]}"
|
109
100
|
unless system cmd then raise "Could not '#{cmd}'" end
|
110
|
-
|
101
|
+
# local branch already exists
|
111
102
|
else
|
112
103
|
cmd = "git checkout #{info[:branch]}"
|
113
104
|
unless system cmd then raise "Could not '#{cmd}'" end
|
@@ -132,7 +123,7 @@ class CookbookFetcher
|
|
132
123
|
cmd = "git checkout -B #{info[:branch]} origin/#{info[:branch]}"
|
133
124
|
unless system cmd then raise "Could not '#{cmd}'" end
|
134
125
|
end
|
135
|
-
|
126
|
+
#commit
|
136
127
|
else
|
137
128
|
cmd = "git checkout #{info[:branch]}"
|
138
129
|
unless system cmd then raise "Could not '#{cmd}'" end
|
@@ -145,10 +136,14 @@ class CookbookFetcher
|
|
145
136
|
end
|
146
137
|
end
|
147
138
|
end
|
139
|
+
module_function :perform_checkouts
|
148
140
|
|
149
|
-
|
150
|
-
|
151
|
-
|
141
|
+
# Utility method - given a parsed checkout list, and assuming the checkout have
|
142
|
+
# already been performed, creates the combined/ directory in the current directory,
|
143
|
+
# and symlinks in the roles, nodes, etc.
|
144
|
+
def update_links (checkouts,logger)
|
145
|
+
things_to_link = ["roles", "nodes", "handlers", "data_bags", "specs"]
|
146
|
+
logger.info "Updating links to #{things_to_link.join(', ')}"
|
152
147
|
|
153
148
|
if !Dir.exists?("combined") then Dir.mkdir("combined") end
|
154
149
|
Dir.chdir("combined") do
|
@@ -202,64 +197,98 @@ class CookbookFetcher
|
|
202
197
|
end
|
203
198
|
end
|
204
199
|
end
|
200
|
+
module_function :update_links
|
205
201
|
|
202
|
+
# This is a Vagrant middleware plugin, which implements fetching the cookbooks
|
203
|
+
# http://vagrantup.com/v1/docs/extending/middleware.html
|
204
|
+
class FetchHook
|
205
|
+
def initialize(app, env)
|
206
|
+
@app = app
|
207
|
+
end
|
206
208
|
|
207
|
-
|
209
|
+
def call(env)
|
210
|
+
if !env[:global_config].cookbook_fetcher.disable then
|
211
|
+
Dir.chdir(env[:root_path]) do
|
212
|
+
CookbookFetcher.perform_fetch(env[:global_config], env[:ui])
|
213
|
+
end
|
214
|
+
else
|
215
|
+
env[:ui].info "Auto-checkout disabled, skipping"
|
216
|
+
end
|
208
217
|
|
209
|
-
|
210
|
-
|
211
|
-
|
218
|
+
# Continue daisy chain
|
219
|
+
@app.call(env)
|
220
|
+
end
|
221
|
+
end
|
212
222
|
|
223
|
+
# Install fetcher hook
|
224
|
+
Vagrant.actions[:provision].insert(Vagrant::Action::General::Validate, CookbookFetcher::FetchHook)
|
225
|
+
# Note that :up includes :start ( see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin.rb )
|
226
|
+
Vagrant.actions[:start].insert(Vagrant::Action::General::Validate, CookbookFetcher::FetchHook)
|
213
227
|
|
214
|
-
# Injects auto-checkout-derived chef-solo config
|
215
|
-
class CookbookFetcherConfigureChef
|
216
|
-
def initialize(app, env)
|
217
|
-
@app = app
|
218
|
-
end
|
219
228
|
|
220
|
-
|
221
|
-
|
229
|
+
# Middleware to tweak chef config
|
230
|
+
# Injects auto-checkout-derived chef-solo config
|
231
|
+
class ConfigureChef
|
232
|
+
def initialize(app, env)
|
233
|
+
@app = app
|
234
|
+
end
|
235
|
+
|
236
|
+
def call(env)
|
237
|
+
# Do this even if fetch is disabled
|
222
238
|
|
223
|
-
|
224
|
-
|
225
|
-
provisioners_list = env[:vm].config.to_hash["keys"][:vm].provisioners
|
239
|
+
# there has got to be a better way
|
240
|
+
provisioners_list = env[:vm].config.to_hash["keys"][:vm].provisioners
|
226
241
|
|
227
|
-
|
228
|
-
|
229
|
-
|
242
|
+
chef_solo = provisioners_list.find { |p| p.shortcut === :chef_solo }
|
243
|
+
if !chef_solo.nil? then
|
244
|
+
solo_cfg = chef_solo.config
|
230
245
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
246
|
+
# TODO - need cwd block
|
247
|
+
Dir.chdir(env[:root_path]) do
|
248
|
+
if solo_cfg.roles_path.nil? then
|
249
|
+
solo_cfg.roles_path = "combined/roles"
|
250
|
+
else
|
251
|
+
env[:ui].warn "Auto-checkout is keeping your custom chef-solo role path"
|
252
|
+
end
|
236
253
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
254
|
+
if solo_cfg.data_bags_path.nil? then
|
255
|
+
solo_cfg.data_bags_path = "combined/data_bags"
|
256
|
+
else
|
257
|
+
env[:ui].warn "Auto-checkout is keeping your custom chef-solo data_bags path"
|
258
|
+
end
|
242
259
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
260
|
+
# Cookbooks has a default
|
261
|
+
if solo_cfg.cookbooks_path === ["cookbooks", [:vm, "cookbooks"]] then
|
262
|
+
# Read from filesystem
|
263
|
+
if !File.exists?(".cookbook-order") then
|
264
|
+
env[:ui].error "Auto-checkout could find not a .cookbook-order file. You need to run provision with autocheckout enabled at least once (or else specify your own cookbook path)"
|
265
|
+
end
|
249
266
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
267
|
+
cbs = []
|
268
|
+
IO.readlines(".cookbook-order").each { |line| cbs.push line.chomp }
|
269
|
+
solo_cfg.cookbooks_path = cbs
|
270
|
+
else
|
271
|
+
env[:ui].warn "Auto-checkout is keeping your custom chef-solo cookbook path"
|
272
|
+
end
|
273
|
+
end
|
255
274
|
end
|
256
275
|
|
276
|
+
# Continue daisy chain
|
277
|
+
@app.call(env)
|
257
278
|
end
|
279
|
+
end
|
280
|
+
|
281
|
+
Vagrant.actions[:provision].insert(Vagrant::Action::VM::Provision, CookbookFetcher::ConfigureChef)
|
282
|
+
Vagrant.actions[:start].insert(Vagrant::Action::VM::Provision, CookbookFetcher::ConfigureChef)
|
258
283
|
|
259
|
-
|
260
|
-
|
284
|
+
class CheckoutCommand < Vagrant::Command::Base
|
285
|
+
def execute
|
286
|
+
Dir.chdir(@env.root_path) do
|
287
|
+
CookbookFetcher.perform_fetch(@env.config.global, @env.ui)
|
288
|
+
end
|
289
|
+
end
|
261
290
|
end
|
262
|
-
|
291
|
+
Vagrant.commands.register(:checkout) { CookbookFetcher::CheckoutCommand }
|
263
292
|
|
264
|
-
|
265
|
-
|
293
|
+
|
294
|
+
end
|
metadata
CHANGED
@@ -1,68 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-cookbook-fetcher
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
version: 0.0.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Clinton Wolfe
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - <=
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - <=
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.7
|
30
|
+
description: Whenever you run start, up, or provision, this plugin will dynamically
|
31
|
+
fetch a list of checkouts from a URL; checkout each one; then create a combined
|
32
|
+
roles directory, with symlinks.
|
22
33
|
email: clinton@NOSPAM.omniti.com
|
23
34
|
executables: []
|
24
|
-
|
25
35
|
extensions: []
|
26
|
-
|
27
36
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
37
|
+
files:
|
30
38
|
- ChangeLog
|
31
39
|
- LICENSE
|
32
40
|
- README.md
|
33
41
|
- lib/vagrant_init.rb
|
34
42
|
- lib/vagrant_cookbook_fetcher.rb
|
35
|
-
has_rdoc: true
|
36
43
|
homepage: https://github.com/clintoncwolfe/vagrant-cookbook-fetcher
|
37
44
|
licenses: []
|
38
|
-
|
39
45
|
post_install_message:
|
40
46
|
rdoc_options: []
|
41
|
-
|
42
|
-
require_paths:
|
47
|
+
require_paths:
|
43
48
|
- lib
|
44
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
50
|
none: false
|
46
|
-
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
|
50
|
-
|
51
|
-
version: "0"
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
56
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
60
61
|
requirements: []
|
61
|
-
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.8.24
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
66
|
summary: Fetch your Chef cookbooks whenever you provision
|
67
67
|
test_files: []
|
68
|
-
|