From a304278d5064e34f4c1ceb25492c7074e3d14260 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Sat, 12 Nov 2022 15:48:08 +0100 Subject: [PATCH] Update build-catalog.sh Signed-off-by: Kjeld Schouten-Lebbing --- .github/scripts/build-catalog.sh | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/.github/scripts/build-catalog.sh b/.github/scripts/build-catalog.sh index 36e79866e14..878425daf70 100755 --- a/.github/scripts/build-catalog.sh +++ b/.github/scripts/build-catalog.sh @@ -105,12 +105,83 @@ copy_apps() { } export -f copy_apps +download_deps() { +local chart="$1" +local chartname="$2" +local train="$3" +local chartversion="$4" + +deps=$(go-yq '.dependencies' "$chart/Chart.yaml") +length=$(echo "$deps" | go-yq '. | length') + +echo "🔨 Processing <$chartname>... Dependencies: $length" +echo "" + +for idx in $(eval echo "{0..$length}"); do + curr_dep=$(echo "$deps" | pos="$idx" go-yq '.[env(pos)]') + + if [ ! "$curr_dep" == null ]; then + name=$(echo "$curr_dep" | go-yq '.name') + version=$(echo "$curr_dep" | go-yq '.version') + repo=$(echo "$curr_dep" | go-yq '.repository') + + echo "**********" + echo "🔗 Dependency: $name" + echo "🆚 Version: $version" + echo "🏠 Repository: $repo" + echo "" + + if [ -f "$cache_path/$name-$version.tgz" ]; then + echo "✅ Dependency exists in cache..." + else + echo "🤷‍♂️ Dependency does not exists in cache..." + + repo_url="$repo/index.yaml" + echo "🤖 Calculating URL..." + dep_url=$(curl -s "$repo_url" | v="$version" n="$name" go-yq '.entries.[env(n)].[] | select (.version == env(v)) | .urls.[0]') + + echo "" + echo "⏬ Downloading dependency $name-$version from $dep_url..." + wget --quiet "$dep_url" -P "$cache_path/" + if [ ! $? ]; then + echo "❌ wget encountered an error..." + helm dependency build "$chart/Chart.yaml" || helm dependency update "$chart/Chart.yaml" || exit 1 + fi + + if [ -f "$cache_path/$name-$version.tgz" ]; then + echo "✅ Dependency Downloaded!" + else + echo "❌ Failed to download dependency" + # Try helm dependency build/update or otherwise fail fast if a dep fails to download... + helm dependency build "$chart/Chart.yaml" || helm dependency update "$chart/Chart.yaml" || exit 1 + fi + fi + echo "" + + mkdir -p "$chart/charts" + echo "📝 Copying dependency <$name-$version.tgz> to <$chart/charts>..." + cp "$cache_path/$name-$version.tgz" "$chart/charts" + + if [ -f "$cache_path/$name-$version.tgz" ]; then + echo "✅ Dependency copied!" + echo "" + else + echo "❌ Failed to copy dependency" + # Try helm dependency build/update or otherwise fail fast if a dep fails to copy... + ehelm dependency build "$chart/Chart.yaml" || helm dependency update "$chart/Chart.yaml" || exit 1 + fi + fi +done +} +export -f download_deps + if [[ -d "charts/${1}" ]]; then echo "Start processing charts/${1} ..." chartversion=$(cat charts/${1}/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }') chartname=$(basename charts/${1}) train=$(basename $(dirname "charts/${1}")) SCALESUPPORT=$(cat charts/${1}/Chart.yaml | yq '.annotations."truecharts.org/SCALE-support"' -r) + download_deps "charts/${1}" "${chartname}" "$train" "${chartversion}" helm dependency build "charts/${1}" --skip-refresh || (sleep 10 && helm dependency build "charts/${1}" --skip-refresh) || (sleep 10 && helm dependency build "charts/${1}" --skip-refresh) if [[ "${SCALESUPPORT}" == "true" ]]; then clean_apps "charts/${1}" "${chartname}" "$train" "${chartversion}"