-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpusher.rb
53 lines (40 loc) · 1.29 KB
/
pusher.rb
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
# frozen_string_literal: true
require 'yaml'
class Pusher
PROJECT_PREFIX = 'jemalloc/ruby'
class << self
def list
lines = YAML.load_file('.travis.yml')['env']
lines.map do |line|
ruby_version = line.split[0].delete_prefix('VERSION=')
os_version = line.split[1].delete_prefix('VARIANT=').split('/')
[ruby_version, os_version].flatten
end
end
def version(image)
`docker run -i -t #{PROJECT_PREFIX}:#{image} bash -c 'echo "$RUBY_VERSION"'`.strip
end
def tag(source, tag)
puts "docker tag #{PROJECT_PREFIX}:#{source} #{PROJECT_PREFIX}:#{tag}"
end
def push(image)
puts "docker push #{PROJECT_PREFIX}:#{image}"
end
def call
images = list.flat_map do |version|
version_str = version.join('-')
ruby_version = version(version_str)
if ruby_version.split('.').size == 3
long_version = ruby_version
long_version_list = [long_version, *version[1..-1]]
tag(version_str, long_version_list.join('-'))
[version, long_version_list]
else
[version]
end
end
images.each{|image| push(image.join('-'))}
end
end
end
pp Pusher.call