-
Notifications
You must be signed in to change notification settings - Fork 28
/
Rakefile
66 lines (54 loc) · 1.52 KB
/
Rakefile
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
60
61
62
63
64
65
66
require 'open3'
require 'yaml'
task default: %i[lint validate package]
CHARTS = FileList["charts/*"].resolve
task :lint do
sh "helm repo add stable https://charts.helm.sh/stable"
CHARTS.each do |chart|
sh "helm dependency update #{chart}"
end
end
task :lint do
CHARTS.each do |chart|
sh "helm lint #{chart}"
end
end
task :package do
mkdir_p "dist"
Dir.chdir "dist" do
CHARTS.each do |chart|
sh "helm package -u ../#{chart}"
end
sh "helm repo index . --url https://charts.helm.sh/stable"
end
end
RELEASES = FileList["releases/**/*.yaml"]
task :validate do
RELEASES.each do |release|
next if validate_release(release) == 'skip'
end
end
def validate_release(release)
r = YAML.safe_load(File.read(release))
if r['kind'] != "HelmRelease" || r['spec']['chart']['git'] != "[email protected]:travis-ci/kubernetes-config.git"
puts "==> Skipping \`helm template\` for file #{release}"
return 'skip'
end
namespace = r['metadata']['namespace']
release_name = r['spec']['releaseName']
chart_path = r['spec']['chart']['path']
values = r['spec']['values']
Open3.popen2e('helm', 'template', chart_path, '-n', release_name, '--namespace', namespace, '-f', '-') do |stdin, output, wait|
stdin.write(YAML.dump(values))
stdin.close
out = output.read
status = wait.value
if status.success?
puts "Release #{release} rendered successfully."
else
puts "Release #{release} failed to render. Output from helm:"
puts out
exit 1
end
end
end