diff --git a/.argo/publish.yaml b/.argo/publish.yaml index e38a024f..7f15760c 100644 --- a/.argo/publish.yaml +++ b/.argo/publish.yaml @@ -12,12 +12,12 @@ steps: - CHECKOUT: template: argo-checkout - PREPARE: - image: ruby + image: hypnoglow/kubernetes-helm:v2.6.1 resources: mem_mib: 500 cpu_cores: 0.1 command: ["sh", "-c"] - args: [ruby /src/scripts/publish.rb] + args: [cd /src && helm init --client-only && ./scripts/publish.sh] inputs: artifacts: CODE: diff --git a/scripts/publish.rb b/scripts/publish.rb index a9240931..a00488f4 100644 --- a/scripts/publish.rb +++ b/scripts/publish.rb @@ -2,25 +2,13 @@ require 'yaml' require 'pathname' root_dir = Pathname.new("#{File.dirname(__FILE__)}/..").cleanpath -output_index_path = "#{root_dir}/output/index.yaml" `mkdir -p #{root_dir}/output` 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| 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)} .` - 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 diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 00000000..520d78b9 --- /dev/null +++ b/scripts/publish.sh @@ -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