forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifacts.rake
213 lines (191 loc) · 7.24 KB
/
artifacts.rake
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def staging
"build/staging"
end
namespace "artifact" do
require "logstash/environment"
def package_files
[
"LICENSE",
"CHANGELOG",
"CONTRIBUTORS",
"{bin,lib,spec,locales}/{,**/*}",
"patterns/**/*",
"vendor/??*/**/*",
File.join(LogStash::Environment.gem_home.gsub(Dir.pwd + "/", ""), "{gems,specifications}/**/*"),
"Rakefile",
"rakelib/*",
]
end
def exclude_globs
return @exclude_globs if @exclude_globs
@exclude_globs = []
#gitignore = File.join(File.dirname(__FILE__), "..", ".gitignore")
#if File.exists?(gitignore)
#@exclude_globs += File.read(gitignore).split("\n")
#end
@exclude_globs << "spec/reports/**/*"
@exclude_globs << "**/*.gem"
@exclude_globs << "**/test/files/slow-xpath.xml"
return @exclude_globs
end
def excludes
return @excludes if @excludes
@excludes = exclude_globs.collect { |g| Rake::FileList[g] }.flatten
end
def exclude?(path)
excludes.any? { |ex| path == ex || (File.directory?(ex) && path =~ /^#{ex}\//) }
end
def files
return @files if @files
@files = package_files.collect do |glob|
Rake::FileList[glob].reject { |path| exclude?(path) }
end.flatten.uniq
end
desc "Build a tar.gz of logstash with all dependencies"
task "tar" => ["bootstrap", "plugin:install-defaults"] do
require "zlib"
require "archive/tar/minitar"
require "logstash/version"
tarpath = "build/logstash-#{LOGSTASH_VERSION}.tar.gz"
tarfile = File.new(tarpath, "wb")
gz = Zlib::GzipWriter.new(tarfile, Zlib::BEST_COMPRESSION)
tar = Archive::Tar::Minitar::Output.new(gz)
files.each do |path|
stat = File.lstat(path)
path_in_tar = "logstash-#{LOGSTASH_VERSION}/#{path}"
opts = {
:size => stat.size,
:mode => stat.mode,
:mtime => stat.mtime
}
if stat.directory?
tar.tar.mkdir(path_in_tar, opts)
else
tar.tar.add_file_simple(path_in_tar, opts) do |io|
File.open(path) do |fd|
chunk = nil
size = 0
size += io.write(chunk) while chunk = fd.read(16384)
if stat.size != size
raise "Failure to write the entire file (#{path}) to the tarball. Expected to write #{stat.size} bytes; actually write #{size}"
end
end
end
end
end
tar.close
gz.close
puts "Complete: #{tarpath}"
end
def package(platform, version)
Rake::Task["dependency:fpm"].invoke
Rake::Task["dependency:stud"].invoke
require "stud/temporary"
require "fpm/errors" # TODO(sissel): fix this in fpm
require "fpm/package/dir"
require "fpm/package/gem" # TODO(sissel): fix this in fpm; rpm needs it.
dir = FPM::Package::Dir.new
files.each do |path|
next if File.directory?(path)
dir.input("#{path}=/opt/logstash/#{path}")
end
basedir = File.join(File.dirname(__FILE__), "..")
File.join(basedir, "pkg", "logrotate.conf").tap do |path|
dir.input("#{path}=/etc/logrotate.d/logstash")
end
# Create an empty /var/log/logstash/ directory in the package
# This is a bit obtuse, I suppose, but it is necessary until
# we find a better way to do this with fpm.
Stud::Temporary.directory do |empty|
dir.input("#{empty}/=/var/log/logstash")
dir.input("#{empty}/=/var/lib/logstash")
dir.input("#{empty}/=/etc/logstash/conf.d")
end
case platform
when "redhat", "centos"
File.join(basedir, "pkg", "logrotate.conf").tap do |path|
dir.input("#{path}=/etc/logrotate.d/logstash")
end
File.join(basedir, "pkg", "logstash.default").tap do |path|
dir.input("#{path}=/etc/sysconfig/logstash")
end
File.join(basedir, "pkg", "logstash.sysv").tap do |path|
dir.input("#{path}=/etc/init.d/logstash")
end
require "fpm/package/rpm"
out = dir.convert(FPM::Package::RPM)
out.license = "ASL 2.0" # Red Hat calls 'Apache Software License' == ASL
out.attributes[:rpm_use_file_permissions] = true
out.attributes[:rpm_user] = "root"
out.attributes[:rpm_group] = "root"
out.config_files << "etc/sysconfig/logstash"
out.config_files << "etc/logrotate.d/logstash"
out.config_files << "/etc/init.d/logstash"
when "debian", "ubuntu"
File.join(basedir, "pkg", "logstash.default").tap do |path|
dir.input("#{path}=/etc/default/logstash")
end
File.join(basedir, "pkg", "logstash.sysv").tap do |path|
dir.input("#{path}=/etc/init.d/logstash")
end
require "fpm/package/deb"
out = dir.convert(FPM::Package::Deb)
out.license = "Apache 2.0"
out.attributes[:deb_user] = "root"
out.attributes[:deb_group] = "root"
out.attributes[:deb_suggests] = "java7-runtime-headless"
out.config_files << "/etc/default/logstash"
out.config_files << "/etc/logrotate.d/logstash"
out.config_files << "/etc/init.d/logstash"
end
# Packaging install/removal scripts
["before", "after"].each do |stage|
["install", "remove"].each do |action|
script = "#{stage}-#{action}" # like, "before-install"
script_sym = script.gsub("-", "_").to_sym
script_path = File.join(File.dirname(__FILE__), "..", "pkg", platform, "#{script}.sh")
next unless File.exists?(script_path)
out.scripts[script_sym] = File.read(script_path)
end
end
# TODO(sissel): Invoke Pleaserun to generate the init scripts/whatever
out.name = "logstash"
out.version = LOGSTASH_VERSION
out.architecture = "all"
# TODO(sissel): Include the git commit hash?
out.iteration = "1" # what revision?
out.url = "http://www.elasticsearch.org/overview/logstash/"
out.description = "An extensible logging pipeline"
out.vendor = "Elasticsearch"
out.dependencies << "logrotate"
# We don't specify a dependency on Java because:
# - On Red Hat, Oracle and Red Hat both label their java packages in
# incompatible ways. Further, there is no way to guarantee a qualified
# version is available to install.
# - On Debian and Ubuntu, there is no Oracle package and specifying a
# correct version of OpenJDK is impossible because there is no guarantee that
# is impossible for the same reasons as the Red Hat section above.
# References:
# - http://www.elasticsearch.org/blog/java-1-7u55-safe-use-elasticsearch-lucene/
# - deb: https://github.com/elasticsearch/logstash/pull/1008
# - rpm: https://github.com/elasticsearch/logstash/pull/1290
# - rpm: https://github.com/elasticsearch/logstash/issues/1673
# - rpm: https://logstash.jira.com/browse/LOGSTASH-1020
out.attributes[:force?] = true # overwrite the rpm/deb/etc being created
begin
path = File.join(basedir, "build", out.to_s)
x = out.output(path)
puts "Completed: #{path}"
ensure
out.cleanup
end
end # def package
desc "Build an RPM of logstash with all dependencies"
task "rpm" => ["bootstrap", "plugin:install-defaults"] do
package("centos", "5")
end
desc "Build an RPM of logstash with all dependencies"
task "deb" => ["bootstrap", "plugin:install-defaults"] do
package("ubuntu", "12.04")
end
end