This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
89 lines (76 loc) · 2.67 KB
/
Rakefile
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
# -*- mode: ruby -*-
require 'rake'
require 'rake/clean'
require 'fileutils'
require 'chef/role'
directory 'cookbooks'
directory 'pkg'
directory 'boxes'
pkgname = ENV["CUISINEPKG"] || File.basename(Dir.pwd)
desc "Artifact cleaner"
def artclean(cpath)
# Clean git
Dir.glob("#{cpath}/**/.git").each{|gd| FileUtils.rm_rf gd}
# Clean Gemfile.lock
Dir.glob("#{cpath}/**/Gemfile.lock").each{|gd| FileUtils.rm_rf gd}
end
CLEAN.include("cookbooks", "Gemfile.lock", "tmp", "pkg", "iso", "boxes", "roles/*.json", \
"definitions/*/output-*", "definitions/*/packer_cache", ".bundle", ".vagrant")
boxlist = FileList.new
Dir.glob("definitions/*").each do |dfntn|
vm = dfntn.split("/")[1]
box = vm + ".box"
boxlist.add("boxes/#{box}")
desc "Build #{box} from #{dfntn}"
file "boxes/#{box}" => FileList["#{dfntn}/*"] do |t|
Dir.chdir dfntn do
sh "packer build #{vm}.json"
FileUtils.mv "#{vm}.box", "../../boxes/"
end
end
end
desc "Generate Vagrant boxes"
file "baseboxes" => [ "boxes"] + boxlist
desc "Populate cookbooks"
task :berkshelf do
sh "bundle check || bundle install"
FileUtils.rm_rf "cookbooks"
sh "bundle exec berks vendor cookbooks"
artclean "cookbooks"
end
desc "Prepare and pack chef bundle"
task :pack => ["berkshelf", "pkg", "roles_to_json"] do
sh "tar -czf pkg/#{pkgname}.tar.gz --exclude='clients/*.pem' cookbooks conf roles/*.json data_bags nodes clients"
end
desc "Prepare and pack chef bundle quickly"
task :qpack do
sh "tar -czf pkg/#{pkgname}.tar.gz --exclude='clients/*.pem' cookbooks conf roles/*.json data_bags nodes clients"
end
desc "Regenerate cookbooks"
task :regen do
sh "rm Berksfile.lock || echo 'No berkshelf lock found'"
Rake::Task["berkshelf"].execute
Rake::Task["pack"].execute
end
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :roles_to_json do
Dir.glob('roles/*.rb') do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(role))}
end
end
desc "Prepare dev env"
task :default => ["berkshelf", "pack"]
desc "Copy artifacts to local web server"
task :install do
instdest = ENV["DEST"] ? ENV["DEST"] : "/srv/www"
File.directory?("#{instdest}/chef/") || Dir.mkdir("#{instdest}/chef/")
File.directory?("#{instdest}/chef/nodes/") || Dir.mkdir("#{instdest}/chef/nodes/")
File.directory?("#{instdest}/chef/conf/") || Dir.mkdir("#{instdest}/chef/conf/")
FileUtils.cp_r Dir.glob("pkg/*") ,"#{instdest}/chef/"
FileUtils.cp_r Dir.glob("nodes/*") ,"#{instdest}/chef/nodes"
FileUtils.cp_r Dir.glob("conf/*") ,"#{instdest}/chef/conf"
end