forked from hoteltonight/ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rb
36 lines (30 loc) · 1014 Bytes
/
build.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
# frozen_string_literal: true
VERSIONS_TO_BUILD = %w[2.7 3.0 3.1 3.2]
TAG_TO_FIND = /ENV\s+RUBY_VERSION\s+(.+)/
NAME = "public.ecr.aws/b0v2c1c3/ruby-jemalloc"
require 'open3'
def run_command(cmd)
Open3.popen2e(cmd) do |stdin, stdout_stderr, wait_thread|
Thread.new do
stdout_stderr.each {|l| puts l }
end
wait_thread.value
end
end
path = File.expand_path(File.dirname(__FILE__))
VERSIONS_TO_BUILD.each do |version|
dockerfiles = Dir.glob("#{path}/#{version}/**/Dockerfile")
dockerfiles.each do |path|
next if path.match(/(onbuild|alpine)/)
contents = File.read(path)
tag = TAG_TO_FIND.match(contents)
full_version = tag[1]
base = path[path.index(version)..-1].gsub("/Dockerfile", "").gsub("#{version}/", "").gsub(/\//, "-")
final_tag = "#{full_version}-#{base}"
image_name = "#{NAME}:#{final_tag}"
Dir.chdir(File.dirname(path)) do
run_command("docker build -t #{image_name} .")
# run_command("docker push #{image_name}")
end
end
end