forked from puppetlabs/puppetdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
198 lines (165 loc) · 6.12 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
require 'rake'
require 'erb'
require 'facter'
JAR_FILE = 'puppetdb.jar'
RAKE_ROOT = File.dirname(__FILE__)
# Load tasks and variables for packaging automation
begin
load File.join(RAKE_ROOT, 'ext', 'packaging', 'packaging.rake')
rescue LoadError
end
def ln_sf(src, dest)
if !File.exist?(dest)
sh "ln -sf #{src} #{dest}"
end
end
def cp_pr(src, dest, options={})
mandatory = {:preserve => true}
cp_r(src, dest, options.merge(mandatory))
end
def cp_p(src, dest, options={})
mandatory = {:preserve => true}
cp(src, dest, options.merge(mandatory))
end
# We want to use puppetdb's package:tar and its dependencies, because it
# contains all the special java snowflake magicks, so we have to clear the
# packaging repo's. We also want to use puppetdb's clean task, since it has so
# much more clean than the packaging repo knows about
['package:tar', 'clean'].each do |task|
Rake::Task[task].clear if Rake::Task.task_defined?(task)
end
# We establish variables used in the puppetdb tasks before hand
if defined?(Pkg) and defined?(Pkg::Config)
if @pe = Pkg::Config.build_pe
# If we're building PE, we need to set the project name to pe-puppetdb
Pkg::Config.project = "pe-puppetdb"
end
@version = Pkg::Config.version
else
begin
%x{which git >/dev/null 2>&1}
if $?.success?
@version = %x{git describe --always --dirty}
if $?.success?
@version.chomp!
end
end
rescue
@version = "0.0-dev-build"
end
if ENV['PE_BUILD'] and ENV['PE_BUILD'].downcase == 'true'
@pe = TRUE
end
end
ENV['PATH'] = "/opt/puppet/bin:" + ENV['PATH'] if @pe
@osfamily = (Facter.value(:osfamily) || "").downcase
# Specific minimum pinning for Puppet & Facter versions
@puppetminversion = "3.5.1"
@facterminversion = "1.7.0"
if @pe
@install_dir = "/opt/puppet/share/puppetdb"
@etc_dir = "/etc/puppetlabs/puppetdb"
@config_dir = "/etc/puppetlabs/puppetdb/conf.d"
@lib_dir = "/opt/puppet/share/puppetdb"
@libexec_dir = "/opt/puppet/libexec/puppetdb"
@name ="pe-puppetdb"
@sbin_dir = "/opt/puppet/sbin"
@pe_version = ENV['PE_VER'] || '3.0'
@java_bin = "/opt/puppet/bin/java"
else
@install_dir = case @osfamily
when /openbsd/
"/usr/local/share/puppetdb"
else
"/usr/share/puppetdb"
end
@etc_dir = "/etc/puppetdb"
@config_dir = "/etc/puppetdb/conf.d"
@lib_dir = "/var/lib/puppetdb"
@libexec_dir = case @osfamily
when /openbsd/
"/usr/local/libexec/puppetdb"
when /redhat/, /suse/, /darwin/, /bsd/
"/usr/libexec/puppetdb"
else
"/usr/lib/puppetdb"
end
@link = "/usr/share/puppetdb"
@name = "puppetdb"
@sbin_dir = "/usr/sbin"
end
@initscriptname = "/etc/init.d/#{@name}"
@log_dir = "/var/log/#{@name}"
# We only need the ruby major, minor versions
@ruby_version = (ENV['RUBY_VER'] || Facter.value(:rubyversion))[0..2]
unless ['1.8','1.9'].include?(@ruby_version)
STDERR.puts "Warning: Existing rake commands are untested on #{@ruby_version} currently supported rubies include 1.8 or 1.9"
end
PATH = ENV['PATH']
DESTDIR= ENV['DESTDIR'] || ''
PE_SITELIBDIR = "/opt/puppet/lib/ruby/site_ruby/1.9.1"
case @osfamily
when /debian/
@plibdir = @pe ? PE_SITELIBDIR : '/usr/lib/ruby/vendor_ruby'
when /redhat/
@plibdir = @pe ? PE_SITELIBDIR : ( @ruby_version == '1.8' ? %x(ruby -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]').chomp : %x(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorlibdir"]').chomp )
when /suse/
@plibdir = @pe ? PE_SITELIBDIR : (%x(ruby -rrbconfig -e "puts RbConfig::CONFIG['sitelibdir']").chomp)
when /openbsd/
@plibdir = @pe ? PE_SITELIBDIR : '/usr/local/lib/ruby/site_ruby/1.9.1'
when /archlinux/
@plibdir = @pe ? PE_SITELIBDIR : (%x(ruby -rrbconfig -e 'puts RbConfig::CONFIG["vendorlibdir"]').chomp)
end
@heap_dump_path = "#{@log_dir}/puppetdb-oom.hprof"
@default_java_args = "-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=#{@heap_dump_path} -Djava.security.egd=file:/dev/urandom"
# All variables have been set, so we can load the puppetdb tasks
Dir[ File.join(RAKE_ROOT, 'tasks','*.rake') ].sort.each { |t| load t }
task :default => [ :package ]
task :allclean => [ :clobber ]
desc "Remove build artifacts (other than clojure (lein) builds)"
task :clean do
rm_rf FileList["ext/files", "pkg", "*.tar.gz"]
end
desc "Get rid of build artifacts including clojure (lein) builds"
task :clobber => [ :clean ] do
rm_rf FileList["target/puppetdb*jar"]
end
task :version do
puts @version
end
file "ext/files/config.ini" => [ :template, JAR_FILE ] do
end
namespace :test do
desc "Run beaker based acceptance tests"
task :beaker, :test_files do |t, args|
args.with_defaults(:test_files => 'acceptance/tests/')
config = ENV["BEAKER_CONFIG"] || "vbox-el6-64mda"
options = ENV["BEAKER_OPTIONS"] || "postgres"
preserve_hosts = ENV["BEAKER_PRESERVE_HOSTS"] == "true" ? true : false
color = ENV["BEAKER_COLOR"] == "false" ? false : true
xml = ENV["BEAKER_XML"] == "true" ? true : false
type = ENV["BEAKER_TYPE"] || "git"
beaker = "beaker " +
"-c '#{RAKE_ROOT}/acceptance/config/#{config}.cfg' " +
"--type #{type} " +
"--debug " +
"--tests " + args[:test_files] + " " +
"--options-file 'acceptance/options/#{options}.rb' " +
"--root-keys"
beaker += " --preserve-hosts" if preserve_hosts
beaker += " --no-color" unless color
beaker += " --xml" if xml
sh beaker
end
end
# The first package build tasks in puppetdb were rake deb and rake srpm (due to
# a cyclical dependency bug, the namespaced aliases to these tasks never worked
# actually worked). The packaging repo doesn't provide rake deb/srpm (they're
# namespaced as package:deb/srpm) and its just as well so we don't conflict
# here when we try to emulate the original behavior here backwards
# compatibility. These two tasks will force a reload of the packaging repo and
# then use it to do the same thing the original tasks did.
desc 'Build deb package'
task :deb => [ 'package:implode', 'package:bootstrap', 'package:deb' ]
desc 'Build a Source rpm for puppetdb'
task :srpm => [ 'package:implode', 'package:bootstrap', 'package:srpm' ]