-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-k8s.rb
More file actions
executable file
·39 lines (31 loc) · 922 Bytes
/
gen-k8s.rb
File metadata and controls
executable file
·39 lines (31 loc) · 922 Bytes
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
#!/usr/bin/env ruby
require 'fileutils'
require 'json'
require 'tmpdir'
jsonnet = system('jrsonnet', '--help', out: File::NULL, err: [:child, :out]) ? 'jrsonnet' : 'jsonnet'
Dir.chdir(__dir__)
tmpdir = Dir.mktmpdir
Dir["./k8s/**/*.jsonnet"].each do |src|
dst = File.join(tmpdir, src.sub(/\.jsonnet$/, '.yml'))
p [src => dst]
FileUtils.mkdir_p File.dirname(dst)
File.open(dst, 'w') do |io|
system(jsonnet, src, out: io, exception: true)
end
out = JSON.parse(File.read(dst))
if out.is_a?(Array)
File.open(dst, 'w') do |io|
out.each do |doc|
io.puts JSON.pretty_generate(doc)
io.puts "---"
end
end
end
end
Dir["./k8s/**/*.yml"].each do |src|
dst = File.join(tmpdir, src.sub(/^\.\/k8s\//, './gen/k8s'))
p [src => dst]
FileUtils.mkdir_p File.dirname(dst)
FileUtils.cp src, dst
end
system('rsync', '-av','--delete', File.join(tmpdir, 'k8s/'), './gen/k8s')