-
Notifications
You must be signed in to change notification settings - Fork 19
/
ec2_package.rb
executable file
·38 lines (32 loc) · 1.2 KB
/
ec2_package.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
#Make a tarball of only the recipes called in dna.json
#Takes as an argument the path to a Vagrant VM's folder.
require 'rubygems'
require 'json'
Dir.chdir(ARGV[0]) do
#run vagrant to parse the `Vagrantfile` and write out `dna.json` and `.cookbooks_path.json`.
res = `vagrant`
if $?.exitstatus != 0
puts res
exit 1
end
CookbooksPath = [JSON.parse(open('.cookbooks_path.json').read)].flatten
recipe_names = JSON.parse(open('dna.json').read)["run_list"].map{|x|
x.gsub('recipe', '').gsub(/(\[|\])/, '').gsub(/::.*$/, '')
}.uniq
open('recipe_list', 'w'){|f|
f.puts recipe_names.map{|x|
paths = CookbooksPath.map{|cookbook_path|
"#{cookbook_path}/#{x}"
}
paths.reject!{|path| not File.exists?(path)}
raise "Multiple cookbooks '#{x}' exist within `chef.cookbooks_path`; I'm not sure which one to use" if paths.length > 1
raise "I can't find any cookbooks called '#{x}'" if paths.length == 0
paths[0]
}
}
#Have tar chop off all of the relative file business prefixes so we can just
#upload everything to the same cookbooks directory
`tar czf cookbooks.tgz --files-from recipe_list 2> /dev/null`
`rm recipe_list`
end