-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.rb
More file actions
executable file
·345 lines (307 loc) · 11 KB
/
setup.rb
File metadata and controls
executable file
·345 lines (307 loc) · 11 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/env ruby
require 'fileutils'
require 'optparse'
# Pro tip: You might have to run "sudo setup.rb ..."
# To save time and space, we build images for support libs for
# specific commits like v2.3.7 and 38957e2c0 (for v2.4.4 and later),
# instead of all commits. If you specify the wrong "support_commit"
# option, nothing will break, but you will end up rebuilding some
# support libraries because they changed.
#
# TODO: Look into default_commit's git history and automatically
# select the support commit to use.
basedir = Dir.pwd()
# 38957e2c0 is after the sha256sum patch
default_support_commit = "38957e2c0"
# 792922d6c is after the boost 1.60.0 patch
new_support_commit = "792922d6c"
default_commit = "v2.4.4"
options = {
:commit => default_commit,
:support_commit => default_support_commit,
# :yes, :no, or nil
:support => nil,
:builds => false,
# :yes, :no, or nil
:packages => nil,
# :dir, :pkgs, or nil
:copy => nil,
:distro => nil,
:dist => false,
:docs => false,
:test_packages => false,
}
parser = OptionParser.new { |opts|
opts.banner = "Usage: ./setup.rb [options]"
opts.on("-c", "--commit COMMIT", "The commit to build packages for (default #{default_commit})") { |c|
if c[0] == "v"
options[:commit] = c
elsif c =~ /^[a-f0-9]{9,}$/
options[:commit] = c[0...9]
else
raise "Commit must be \"v...\" or be hash of length 9"
end
}
opts.on("--[no-]support", "Build support (default off)") { |s|
options[:support] = s ? :yes : :no
}
opts.on("--[no-]packages", "Build packages (default off)") { |p|
options[:packages] = p ? :yes : :no
}
opts.on("--[no-]builds", "Build builds (default off)") { |b|
options[:builds] = b
}
opts.on("--distro DISTRO", "The distro to build packages for (default all)") { |d|
if d == "all"
options[:distro] = nil
else
options[:distro] = d
end
}
opts.on("--dist", "Builds dist .tgz source file") { |b|
options[:dist] = b
}
opts.on("--copy-dirs", "Copies packages directory to artifacts/") { |b|
if b
raise "--copy-dirs is incompatible with --copy-pkgs" if options[:copy] == :pkgs
options[:copy] = :dir
end
}
opts.on("--copy-pkgs", "Copies debs and rpms to artifacts/pkgs") { |b|
if b
raise "--copy-dirs is incompatible with --copy-pkgs" if options[:copy] == :dirs
options[:copy] = :pkgs
end
}
opts.on("--test-pkgs", "Tests copied debs and rpms") { |b|
options[:test_packages] = b
}
opts.on("--v23support", "Build support libs for v2.3.x") { |b|
options[:support_commit] = "v2.3.7"
}
opts.on("--v24support", "Build support libs for v2.4.0/v2.4.1") { |b|
# b2365be is the "Parallelize deb-build" commit in v2.4.x.
options[:support_commit] = "b2365bef6"
}
opts.on("--v242support", "Build support libs for v2.4.x, 1<x<=2") { |b|
# We might want to update this commit hash later.
options[:support_commit] = "ca0eb820d"
}
opts.on("--v243support", "Build support libs for v2.4.x, x>2") { |b|
# We might want to update this commit hash later.
options[:support_commit] = default_support_commit
}
opts.on("--v245support", "Build support libs for v2.4.x, x>4") { |b|
# We might want to update this commit hash later.
options[:support_commit] = new_support_commit
}
opts.on("--docs", "Build docs for master branch") { |b|
options[:docs] = b
}
}
parser.parse!
if options[:test_packages]
if options[:copy] == :dir
# I don't want to think about this right now, so we just require
# --copy-pkgs to be used.
raise "--test-pkgs is incompatible with --copy-dirs (out of sheer laziness)"
end
options[:copy] = :pkgs
end
if options[:copy] == :pkgs || options[:copy] == :dirs
if options[:packages] == :no
raise "--copy-#{options[:copy]} is incompatible with --no-packages"
end
options[:packages] = :yes
end
if options[:dist]
raise "--dist is incompatible with --no-support" if options[:support] == :no
options[:support] = :yes
end
if options[:builds]
raise "--builds is incompatible with --no-support" if options[:support] == :no
options[:support] = :yes
end
if options[:packages] == :yes
raise "--packages is incompatible with --no-support" if options[:support] == :no
options[:support] = :yes
end
commit = options[:commit]
support_commit = options[:support_commit]
package_args = "--build-arg commit=#{commit}"
checkout_args = "#{package_args} --build-arg support_commit=#{support_commit}"
build_args = "#{package_args}"
support_args = "--build-arg commit=#{support_commit}"
# distros is in order of priority.
distros = [
# latest production releases
"trixie",
"questing",
"plucky",
"noble",
"jammy",
"alma8",
"alma9",
"rocky8",
"rocky9",
# "centos8",
# past production releases
# "centos7",
# working but normally commented.
# "amazon2",
# "amazon2023",
# "archlinux",
# "alpine3_15",
# "alpine3_15i386",
# "alpine3_16",
# "alpine3_17",
# "alpine3_18",
# "alpine_edge",
# "alpine_edgei386",
# "centos6",
"bookworm",
"bullseye",
"oracular",
# "buster",
# "stretch",
# "jessie",
# "kinetic",
# "mantic",
# "lunar",
"focal",
"bionic",
"xenial",
# unimportant releases
"trusty",
# "trustyi386",
]
if options[:distro] != nil
if ["archlinux", "alpine3_15", "alpine3_15i386", "alpine3_16", "alpine3_17", "alpine3_18", "alpine_edge", "alpine_edgei386"].include?(options[:distro])
# We don't yet implement package builds for archlinux/alpine, we don't want the all-distros option to fail.
distros = [options[:distro]]
else
distros.delete_if { |d| options[:distro] != d }
end
end
if distros.empty?
raise "Invalid distro"
end
docker_build = "docker build --progress=plain"
# First build the base image
Dir.chdir("rdbcheckout") {
system "#{docker_build} -t samrhughes/rdbcheckout ." or raise "build rdbcheckout fail"
}
# Then do system builds
distros.each { |distro|
Dir.chdir("#{distro}") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-system -f System ." or raise "build rdb-#{distro}-system fail"
}
}
if options[:docs]
Dir.chdir("docs/docscheckout") {
system "#{docker_build} -t samrhughes/rdb-docs-docscheckout ." or raise "build rdb-docs-docscheckout fail"
}
Dir.chdir("docs/system") {
system "#{docker_build} -t samrhughes/rdb-docs-system ." or raise "build rdb-docs-system fail"
}
docs_commit = "e4be287c2"
Dir.chdir("docs/build") {
system "#{docker_build} -t samrhughes/rdb-docs-build:#{docs_commit} --build-arg commit=#{docs_commit} ." or raise "build rdb-docs-build fail"
}
end
if options[:support] == :yes
# Then do support builds
distros.each { |distro|
Dir.chdir("#{distro}") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-support:#{support_commit} #{support_args} -f Support ." or raise "build rdb-#{distro}-support fail"
}
}
# Then do checkouts
distros.each { |distro|
Dir.chdir("#{distro}") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-checkout:#{commit} #{checkout_args} -f Checkout ." or raise "build rdb-#{distro}-checkout fail"
}
}
if options[:builds]
# Then do builds, if we want that.
distros.each { |distro|
if distro == "centos6"
Dir.chdir("#{distro}/build") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-build:#{commit} #{build_args} ." or raise "build rdb-#{distro}-build fail"
}
else
Dir.chdir("build") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-build:#{commit} #{build_args} --build-arg distro=#{distro} ." or raise "build rdb-#{distro}-build fail"
}
end
}
end
if options[:dist]
# This focal build sequence is a (don't-repeat-yourself-violating)
# copy of the ordering logic above, instead of having some system
# to name dependencies and chase the graph.
Dir.chdir("focal") {
system "#{docker_build} -t samrhughes/rdb-focal-system -f System ." or raise "build rdb-focal-system fail"
system "#{docker_build} -t samrhughes/rdb-focal-support:#{support_commit} #{support_args} -f Support ." or raise "build rdb-focal-support fail"
system "#{docker_build} -t samrhughes/rdb-focal-checkout:#{commit} #{checkout_args} -f Checkout ." or raise "build rdb-focal-checkout fail"
}
Dir.chdir("dist") {
# We only need one dist file, it doesn't depend on OS. So we
# pick a recent LTS ubuntu, focal, whose dependencies are
# ensured immediately above.
system "#{docker_build} -t samrhughes/rdb-focal-dist:#{commit} #{build_args} ." or raise "build rdb-focal-dist fail"
}
puts "Copying dist file into one pkgs directory..."
FileUtils.mkdir_p("artifacts/pkgs")
cmd = "docker run --rm -v #{basedir}/artifacts:/artifacts samrhughes/rdb-focal-dist:#{commit} bash -c \"cp \\$(find /platform/rethinkdb/build/packages -name '*.tgz') /artifacts/pkgs\""
puts "Executing #{cmd}"
system cmd or raise "copy-dist fail"
puts "Done copying dist."
end
if options[:packages] == :yes
# And build packages, if we want that.
distros.each { |distro|
Dir.chdir("#{distro}") {
system "#{docker_build} -t samrhughes/rdb-#{distro}-package:#{commit} #{package_args} -f Package ." or raise "build rdb-#{distro}-package fail"
}
}
if options[:copy] == :dir
# TODO: Use rsync for --copy-dirs. We'd have to install it on
# the images though.
distros.each { |distro|
puts "Copying dir for distro #{distro}..."
FileUtils.mkdir_p("artifacts/#{distro}")
system "docker run --rm -v #{basedir}/artifacts:/artifacts samrhughes/rdb-#{distro}-package:#{commit} cp -R /platform/rethinkdb/build/packages /artifacts/#{distro}" or raise "copy-dirs #{distro}-package fail"
}
puts "Done copying dirs."
elsif options[:copy] == :pkgs
packages_map = {}
distros.each { |distro|
puts "Copying deb/rpms for distro #{distro} into one directory..."
FileUtils.mkdir_p("artifacts/pkgs")
FileUtils.mkdir("artifacts/pkg_stage")
cmd = "docker run --rm -v #{basedir}/artifacts:/artifacts samrhughes/rdb-#{distro}-package:#{commit} bash -c \"cp \\$(find /platform/rethinkdb/build/packages -name '*.deb' -or -name '*.rpm') /artifacts/pkg_stage\""
puts "Executing #{cmd}"
system cmd or raise "copy-pkgs #{distro}-package fail"
packages_map[distro] = []
Dir.glob("artifacts/pkg_stage/*").each { |ent|
newname = File.basename(ent).gsub(/\.rpm$/, ".#{distro}.rpm")
FileUtils.mv(ent, "artifacts/pkgs/#{newname}")
packages_map[distro].append(newname)
}
FileUtils.rmdir("artifacts/pkg_stage")
puts "Done copying packages."
}
if options[:test_packages]
distros.each { |distro|
packages_map[distro].each { |package_filename|
if package_filename !~ /-dbg/
puts "Testing package install for #{package_filename}"
system "#{docker_build} -t samrhughes/rdb-#{distro}-test:#{commit} --build-arg package_file='#{package_filename}' -f #{distro}/Test artifacts/pkgs" or raise "build rdb-#{distro}-test fail"
end
}
}
end
end
end
end