forked from kufu/ruby-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
48 lines (43 loc) · 1.5 KB
/
Rakefile
File metadata and controls
48 lines (43 loc) · 1.5 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
namespace :docker do
def docker_hub_org
"rubylang"
end
def docker_image_name
"#{docker_hub_org}/ruby"
end
def ubuntu_version
"bionic"
end
def get_ruby_master_head_hash
`curl -H 'accept: application/vnd.github.v3.sha' https://api.github.com/repos/ruby/ruby/commits/master`.chomp
end
def make_tag_args(ruby_version)
ruby_ver2 = ruby_version.split('.')[0,2].join('.')
if /\Amaster(?::([\da-f]+))?\z/ =~ ruby_version
commit_hash = Regexp.last_match[1] || get_ruby_master_head_hash
ruby_version = "master:#{commit_hash}"
tags = ["master", "master-#{commit_hash}"]
else
tags = ["#{ruby_ver2}", "#{ruby_version}"]
end
tag_args = tags.map {|t| ["-t", "#{docker_image_name}:#{t}-#{ubuntu_version}"] }.flatten
return ruby_version, tag_args
end
task :build do
ruby_version = ENV['ruby_version'] || '2.6.1'
ruby_version, tag_args = make_tag_args(ruby_version)
unless File.directory?("tmp/ruby")
FileUtils.mkdir_p("tmp/ruby")
IO.write('tmp/ruby/.keep', '')
end
sh 'docker', 'build', *tag_args, '--build-arg', "RUBY_VERSION=#{ruby_version}", '.'
if ruby_version.start_with? 'master'
image_name = tag_args[3]
if ENV['nightly']
today = Time.now.getlocal("+09:00").strftime('%Y%m%d')
sh 'docker', 'tag', image_name, image_name.sub(/master-([\da-f]+)/, "master-nightly-#{today}")
sh 'docker', 'tag', image_name, image_name.sub(/master-([\da-f]+)/, "master-nightly")
end
end
end
end