forked from chef-boneyard/cookbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
117 lines (102 loc) · 2.96 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
COMPANY_NAME = "Opscode, Inc."
NEW_COOKBOOK_LICENSE = :apachev2
desc "Test the cookbooks for syntax errors"
task :test do
puts "** Testing your cookbooks for syntax errors"
Dir[ File.join(File.dirname(__FILE__), "**", "*.rb") ].each do |recipe|
print "Testing recipe #{recipe}: "
sh %{ruby -c #{recipe}} do |ok, res|
if ! ok
raise "Syntax error in #{recipe}"
end
end
end
end
desc "Create a new cookbook (with COOKBOOK=name)"
task :new_cookbook do
create_cookbook(File.join(TOPDIR, "cookbooks"))
create_readme(File.join(TOPDIR, "cookbooks"))
end
def create_cookbook(dir)
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
puts "** Creating cookbook #{ENV["COOKBOOK"]}"
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "recipes")}"
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"))
open(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"), "w") do |file|
file.puts <<-EOH
#
# Cookbook Name:: #{ENV["COOKBOOK"]}
# Recipe:: default
#
# Copyright #{Time.now.year}, #{COMPANY_NAME}
#
EOH
case NEW_COOKBOOK_LICENSE
when :apachev2
file.puts <<-EOH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
EOH
when :none
file.puts <<-EOH
# All rights reserved - Do Not Redistribute
#
EOH
end
end
end
end
def create_readme(dir)
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
puts "** Creating README for cookbook: #{ENV["COOKBOOK"]}"
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "README.rdoc"))
open(File.join(dir, ENV["COOKBOOK"], "README.rdoc"), "w") do |file|
file.puts <<-EOH
= DESCRIPTION:
= REQUIREMENTS:
== Platform:
== Cookbooks:
= ATTRIBUTES:
= USAGE:
= LICENSE and AUTHOR:
EOH
end
end
end
task :default => [ :test ]
desc "Build a bootstrap.tar.gz"
task :build_bootstrap do
bootstrap_files = Rake::FileList.new
%w(apache2 runit couchdb stompserver chef passenger ruby packages).each do |cookbook|
bootstrap_files.include "#{cookbook}/**/*"
end
tmp_dir = "tmp"
cookbooks_dir = File.join(tmp_dir, "cookbooks")
rm_rf tmp_dir
mkdir_p cookbooks_dir
bootstrap_files.each do |fn|
f = File.join(cookbooks_dir, fn)
fdir = File.dirname(f)
mkdir_p(fdir) if !File.exist?(fdir)
if File.directory?(fn)
mkdir_p(f)
else
rm_f f
safe_ln(fn, f)
end
end
chdir(tmp_dir) do
sh %{tar zcvf bootstrap.tar.gz cookbooks}
end
end