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
|
# File 'lib/kubes/compiler/shared/helpers/config_map_helper.rb', line 3
def config_map_files(options={})
indent = options[:indent] || 2
line = caller[0]
path = line.split(':').first
basename = File.basename(path).sub(/.erb$/,'').sub(/.yaml$/, '').sub(/.rb$/, '')
filename = options[:name] || basename
shared_config_map = "#{Kubes.root}/.kubes/resources/shared/#{filename}"
layers = [
[shared_config_map, "base.txt"],
[shared_config_map, "#{Kubes.env}.txt"],
]
if Kubes.app
layers += [
[shared_config_map, "#{Kubes.app}.txt"],
[shared_config_map, Kubes.app, "base.txt"],
[shared_config_map, Kubes.app, "#{Kubes.env}.txt"],
]
end
layers.map! { |layer| layer.compact.join('/') }
data = {}
layers.each do |path|
next unless File.exist?(path)
text = RenderMePretty.result(path, context: self)
lines = text.split("\n")
lines.each do |line|
key, value = parse_env_like_line(line)
data[key] = value
end
end
spacing = " " * indent
lines = data.map do |key,value|
"#{spacing}#{key}: #{value}"
end
lines.join("\n")
end
|