-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate
executable file
·48 lines (39 loc) · 1.05 KB
/
generate
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
#!/usr/bin/env ruby
# vi: ft=ruby
require "erb"
require "toml-rb"
require "pry-byebug"
TOOLS_FILE = File.join(__dir__, "Tools.toml")
DOCKERFILE_TEMPLATE_FILE = File.join(__dir__, "Dockerfile.erb")
ARTIFACTS_DIR = File.join(__dir__, "artifacts")
class Generator
attr_accessor :tools, :dockerfile_template
def initialize
@tools = TomlRB.load_file(TOOLS_FILE)
@dockerfile_template = ERB.new(File.read(DOCKERFILE_TEMPLATE_FILE), trim_mode: "-")
end
def run
File.write(
File.join(ARTIFACTS_DIR, "Dockerfile"),
dockerfile_template.result(binding),
)
File.write(
File.join(ARTIFACTS_DIR, "tool-versions"),
asdf_tool_versions,
)
end
def asdf_tool_versions
tools_for_source("asdf").map do |tool, config|
(Array(tool) + config["asdf"]["versions"]).join(" ")
end.join("\n")
end
def tools_for_source(source)
tools.filter { |_, config| config["source"] == source }
end
def package_configs
tools
.values
.filter_map { |config| config["packages"] }
end
end
Generator.new.run