-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate.rb
More file actions
executable file
·54 lines (45 loc) · 1.39 KB
/
update.rb
File metadata and controls
executable file
·54 lines (45 loc) · 1.39 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
49
50
51
52
53
54
#!/usr/bin/env ruby
require 'erb'
require 'ostruct'
require 'yaml'
# Run external command and test success.
def run(cmd)
puts cmd
success = system(cmd)
exit $?.exitstatus unless success
end
def status(msg)
puts "\n==> #{msg}"
end
# Update docker files for a version.
def update_version(branch, version, opts={})
tldir = File.join(branch, version)
status "Update version #{tldir}"
# initialize directory
run "rm -rf #{tldir}"
run "mkdir -p #{tldir}"
opts['version'] = version
# render Dockerfile for each build platform
opts["platforms"].each do |platform|
dir = File.join(tldir, platform)
run "mkdir -p #{dir}"
platformDockerfileName = 'Dockerfile.' + platform + '.erb'
platformDockerfile = ERB.new(File.read(platformDockerfileName), trim_mode:'-')
result = platformDockerfile.result(OpenStruct.new(opts).instance_eval { binding })
commonDockerFile = ERB.new(File.read('Dockerfile.common.erb'), trim_mode:'-')
result += commonDockerFile.result(OpenStruct.new(opts).instance_eval { binding })
File.write(File.join(dir, 'Dockerfile'), result)
end
end
def load_versions
versions = YAML.load_file('versions.yml')
versions.select! { |k, v| k === ENV['BRANCH'] } if ENV['BRANCH']
versions
end
if __FILE__ == $0
load_versions.each do |branch, versions|
versions.each do |version, opts|
update_version(branch, version, opts)
end
end
end