2022-11-12 09:27:40 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# require go-yq
|
|
|
|
command -v go-yq >/dev/null 2>&1 || {
|
|
|
|
printf >&2 "%s\n" "❌ go-yq (https://github.com/mikefarah/yq) is not installed. Aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-11-12 09:33:27 -05:00
|
|
|
# define defaults
|
2022-11-12 10:32:22 -05:00
|
|
|
cache_path=${cache_path:-./tgz_cache}
|
2022-11-12 10:58:44 -05:00
|
|
|
charts_path=${charts_path:-./charts}
|
2022-11-12 09:27:40 -05:00
|
|
|
|
|
|
|
mkdir -p "$cache_path"
|
|
|
|
|
|
|
|
trains=(
|
|
|
|
"enterprise"
|
|
|
|
"stable"
|
|
|
|
"incubator"
|
|
|
|
"dependency"
|
|
|
|
)
|
|
|
|
|
2022-11-12 10:00:47 -05:00
|
|
|
download_deps() {
|
2022-11-12 10:58:44 -05:00
|
|
|
local train_chart="$1"
|
2022-11-12 09:27:40 -05:00
|
|
|
|
2022-11-12 11:02:16 -05:00
|
|
|
# Extract dependencies for the Chart
|
2022-11-12 10:58:44 -05:00
|
|
|
deps=$(go-yq '.dependencies' "$charts_path/$train_chart/Chart.yaml")
|
2022-11-12 11:02:16 -05:00
|
|
|
# Find how many deps exist, so we can loop through them
|
2022-11-12 10:00:47 -05:00
|
|
|
length=$(echo "$deps" | go-yq '. | length')
|
|
|
|
|
2022-11-12 10:58:44 -05:00
|
|
|
echo "🔨 Processing <$charts_path/$train_chart>... Dependencies: $length"
|
2022-11-12 10:00:47 -05:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
for idx in $(eval echo "{0..$length}"); do
|
2022-11-12 11:02:16 -05:00
|
|
|
# Retrieve info for the dep in the current index..
|
2022-11-12 10:00:47 -05:00
|
|
|
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"
|
2022-11-12 09:27:40 -05:00
|
|
|
echo ""
|
|
|
|
|
2022-11-12 10:00:47 -05:00
|
|
|
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..."
|
2022-11-12 11:02:16 -05:00
|
|
|
# At the time of writing this, only 1 url existed (.urls[0]) pointing to the actual tgz.
|
|
|
|
# Extract url from repo_url. It's under .entries.DEP_NAME.urls. We filter the specific version first (.version)
|
2022-11-12 10:00:47 -05:00
|
|
|
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..."
|
2022-11-12 10:58:44 -05:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || helm dependency update "$charts_path/$train_chart/Chart.yaml" || exit 1
|
2022-11-12 10:00:47 -05:00
|
|
|
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...
|
2022-11-12 10:58:44 -05:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || helm dependency update "$charts_path/$train_chart/Chart.yaml" || exit 1
|
2022-11-12 09:27:40 -05:00
|
|
|
fi
|
2022-11-12 10:00:47 -05:00
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
|
2022-11-12 10:58:44 -05:00
|
|
|
mkdir -p "$charts_path/$train_chart/charts"
|
|
|
|
echo "📝 Copying dependency <$name-$version.tgz> to <$charts_path/$train_chart/charts>..."
|
|
|
|
cp "$cache_path/$name-$version.tgz" "$charts_path/$train_chart/charts"
|
2022-11-12 10:00:47 -05:00
|
|
|
|
|
|
|
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...
|
2022-11-12 10:58:44 -05:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || helm dependency update "$charts_path/$train_chart/Chart.yaml" || exit 1
|
2022-11-12 10:00:47 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
export -f download_deps
|
|
|
|
|
2022-11-12 10:58:44 -05:00
|
|
|
if [ -z "$1" ]; then
|
2022-11-12 10:00:47 -05:00
|
|
|
for train in "${trains[@]}"; do
|
2022-11-12 10:58:44 -05:00
|
|
|
for chart in $(ls "$charts_path/$train"); do
|
2022-11-12 10:00:47 -05:00
|
|
|
download_deps "${train}/${chart}"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
|
|
|
download_deps "$1"
|
2022-11-12 10:22:44 -05:00
|
|
|
fi
|