Use helm to index repo

pull/4/head
Alexander Matyushentsev 2017-10-11 11:20:19 -07:00
parent 81c0c105ff
commit a0959ed344
3 changed files with 16 additions and 15 deletions

View File

@ -12,12 +12,12 @@ steps:
- CHECKOUT: - CHECKOUT:
template: argo-checkout template: argo-checkout
- PREPARE: - PREPARE:
image: ruby image: hypnoglow/kubernetes-helm:v2.6.1
resources: resources:
mem_mib: 500 mem_mib: 500
cpu_cores: 0.1 cpu_cores: 0.1
command: ["sh", "-c"] command: ["sh", "-c"]
args: [ruby /src/scripts/publish.rb] args: [cd /src && helm init --client-only && ./scripts/publish.sh]
inputs: inputs:
artifacts: artifacts:
CODE: CODE:

View File

@ -2,25 +2,13 @@ require 'yaml'
require 'pathname' require 'pathname'
root_dir = Pathname.new("#{File.dirname(__FILE__)}/..").cleanpath root_dir = Pathname.new("#{File.dirname(__FILE__)}/..").cleanpath
output_index_path = "#{root_dir}/output/index.yaml"
`mkdir -p #{root_dir}/output` `mkdir -p #{root_dir}/output`
list = Dir.glob("#{root_dir}/charts/**/*Chart.yaml") list = Dir.glob("#{root_dir}/charts/**/*Chart.yaml")
repo_index = if File.exists?(output_index_path) then YAML.load_file(output_index_path) else { 'apiVersion' => 'v1', 'entries' => {}} end
list.each do |filename| list.each do |filename|
chart_name = File.basename(File.dirname(filename)) chart_name = File.basename(File.dirname(filename))
chart_versions = repo_index['entries'][chart_name] || []
repo_index['entries'][chart_name] = chart_versions
version_info = YAML.load_file(filename)
existing_info = chart_versions.find{ |item| item['version'] == version_info['version'] }
if existing_info then
chart_versions[chart_versions.index(existing_info)] = version_info
else
chart_versions.push version_info
end
`tar -cvzf #{root_dir}/output/#{chart_name}-#{version_info['version']}.tgz #{File.dirname(filename)} -C #{File.dirname(filename)} .` `tar -cvzf #{root_dir}/output/#{chart_name}-#{version_info['version']}.tgz #{File.dirname(filename)} -C #{File.dirname(filename)} .`
File.open(output_index_path, 'w') { |file| file.write(repo_index.to_yaml( :Indent => 4, :UseHeader => true, :UseVersion => true )) } `helm repo index #{root_dir}/output`
end end

13
scripts/publish.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
SRCROOT="$(cd "$(dirname "$0")/.." && pwd)"
mkdir -p $SRCROOT/output
for dir in $SRCROOT/charts/*;
do
echo "Processing $dir"
version=$(cat $dir/Chart.yaml | grep version: | awk '{print $2}')
tar -cvzf $SRCROOT/output/$(basename $dir)-$version.tgz $dir -C $dir .
cd $SRCROOT/output && helm repo index .
done