forked from phusion/traveling-ruby
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
113 lines (89 loc) · 3.62 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
IMAGE_VERSION = "1.0"
VERSION = File.read("../VERSION.txt").strip
RUBY_VERSIONS = File.read("../RUBY_VERSIONS.txt").strip.split(/\s+/)
ARCHITECTURES = [].push(ENV['ARCHITECTURES']) || ["x86_64","arm64"]
CONCURRENCY = `./internal/cpucount`.to_i + 1
task :default => :package
desc "Create packages for all Ruby versions (#{RUBY_VERSIONS.join(' ')}) and all architectures (#{ARCHITECTURES.join(' ')}"
task :package do
# Do nothing
end
desc "Build the Docker images"
task :image do
# Do nothing
end
desc "Build binaries for all Ruby versions (#{RUBY_VERSIONS.join(' ')}) and all architectures (#{ARCHITECTURES.join(' ')}"
task :build do
# Do nothing
end
desc "Test all Ruby versions (#{RUBY_VERSIONS.join(' ')})"
task :test do
# Do nothing
end
desc "Upload all packages to the server"
task :upload do
# Do nothing
end
desc "Clean all packages"
task :clean do
sh "rm -rf output"
end
ARCHITECTURES.each do |arch|
task :image => "image:#{arch}"
desc "Build the #{arch} Docker image"
task "image:#{arch}" do
sh "docker build --pull" \
" -t you54f/traveling-ruby-builder-#{arch}:#{IMAGE_VERSION}" \
" -f image/Dockerfile-#{arch} image"
end
desc "Open a shell for testing building the #{arch} Docker image"
task "image:buildtest:#{arch}" do
File.read("image/Dockerfile-#{arch}") =~ /FROM (.+)/
base_image = $1
sh "docker", "run", "-ti", "--rm",
"-v", File.absolute_path("image") + ":/tr_build:ro",
"-v", File.absolute_path("image") + ":/host:delegated",
base_image, "bash"
end
RUBY_VERSIONS.each do |ruby_version|
package = "traveling-ruby-#{VERSION}-#{ruby_version}-linux-#{arch}.tar.gz"
gem_dir = "traveling-ruby-gems-#{VERSION}-#{ruby_version}-linux-#{arch}"
task :package => "package:#{ruby_version}:#{arch}"
task :build => "build:#{ruby_version}:#{arch}"
task :test => "test:#{ruby_version}:#{arch}"
task :upload => "upload:#{ruby_version}:#{arch}"
task :clean => "clean:#{ruby_version}:#{arch}"
desc "Create packages for Ruby #{ruby_version} #{arch}"
task "package:#{ruby_version}:#{arch}" => [package, "#{gem_dir}/ok"]
desc "Build binaries for Ruby #{ruby_version} #{arch}"
task "build:#{ruby_version}:#{arch}" => "output/#{ruby_version}-#{arch}/bin"
file(package => "output/#{ruby_version}-#{arch}/bin") do
sh "./package -r #{package} output/#{ruby_version}-#{arch}"
end
file("#{gem_dir}/ok" => "output/#{ruby_version}-#{arch}/bin") do
sh "./package -E #{gem_dir} output/#{ruby_version}-#{arch}"
touch "#{gem_dir}/ok"
end
# We use 'file' instead of 'directory' here so that packages are updated
# whenever we update binaries.
file("output/#{ruby_version}-#{arch}/bin" => "cache/#{ruby_version}-#{arch}") do
sh "mkdir -p output/#{ruby_version}-#{arch}"
sh "./build-ruby -j #{CONCURRENCY} -i you54f/traveling-ruby-builder-#{arch}:#{IMAGE_VERSION}" \
" -r #{ruby_version} -c cache/#{ruby_version}-#{arch}" \
" output/#{ruby_version}-#{arch}"
end
directory("cache/#{ruby_version}-#{arch}")
desc "Test Ruby #{ruby_version} #{arch}"
task "test:#{ruby_version}:#{arch}" => "output/#{ruby_version}-#{arch}/bin" do
sh "./test-gems output/#{ruby_version}-#{arch}"
end
desc "Upload Ruby #{ruby_version} #{arch} packages to the server"
task "upload:#{ruby_version}:#{arch}" => [package, "#{gem_dir}/ok"] do
sh "env IMAGE_VERSION=#{IMAGE_VERSION} ./upload #{package} #{gem_dir}"
end
desc "Clean Ruby #{ruby_version} packages"
task "clean:#{ruby_version}:#{arch}" do
sh "rm -rf #{package} #{gem_dir} output/#{arch}"
end
end
end