-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_all.rb
60 lines (42 loc) · 1.21 KB
/
build_all.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
54
55
56
57
58
59
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
def parse_options
result = OpenStruct.new(:hgrev => 'HEAD', :images => Array.new)
parser = OptionParser.new
parser.banner = <<BANER
Build all Dockerfiles in the current directory.
Usage:
./build_all <options>
BANER
parser.on('--hgrev REV', "Revision to use (default: #{result.hgrev})") do |rev|
result.hgrev = rev
end
parser.on('--image Dockerfile-name', "A Dockerfile to be used for build" ) do |name|
result.images << name
end
parser.on('-h', '--help', 'Show this message') do
puts parser
exit(1)
end
parser.parse!
result
end
def run_docker(hgrev, files)
files.each do |dockerfile|
tag = "restinio-#{File.basename(dockerfile, '.Dockerfile')}"
log_file = "outputs/#{tag}.#{hgrev}.log"
cmdline = "docker build -t #{tag} -f #{dockerfile} " +
" --build-arg hgrev=#{hgrev} . | tee #{log_file} 2>&1"
r = system(cmdline)
if not r
raise "build failed!\ncmdline: #{cmdline}\nexit code: #{$?}"
end
end
end
opts = parse_options
if opts.images.empty?
opts.images = Dir['*.Dockerfile']
end
puts "Dockerfiles to process:\n#{opts.images.join('\n')}\n==="
run_docker(opts.hgrev, opts.images)