2022-11-12 14:27:40 +00: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 14:33:27 +00:00
|
|
|
# define defaults
|
2022-11-12 15:32:22 +00:00
|
|
|
cache_path=${cache_path:-./tgz_cache}
|
2022-11-12 15:58:44 +00:00
|
|
|
charts_path=${charts_path:-./charts}
|
2022-11-12 18:06:22 +00:00
|
|
|
# Do NOT persist this directory, in order to always have the latest index for this run.
|
|
|
|
index_cache=${index_cache:-./index_cache}
|
2022-11-12 14:27:40 +00:00
|
|
|
|
|
|
|
mkdir -p "$cache_path"
|
|
|
|
|
|
|
|
trains=(
|
|
|
|
"enterprise"
|
|
|
|
"stable"
|
|
|
|
"incubator"
|
|
|
|
"dependency"
|
|
|
|
)
|
|
|
|
|
2023-05-07 11:14:59 +00:00
|
|
|
load_gpg_key() {
|
|
|
|
echo ""
|
|
|
|
echo "⏬ Downloading and Loading TrueCharts pgp Public Key"
|
|
|
|
gpg_dir=.cr-gpg
|
|
|
|
mkdir "$gpg_dir"
|
2023-05-07 11:32:49 +00:00
|
|
|
curl https://keybase.io/truecharts/pgp_keys.asc | gpg --dearmor > $gpg_dir/pubring.gpg || echo "❌ Couldn't load Public Key."
|
2023-05-07 11:14:59 +00:00
|
|
|
echo "✅ Public Key loaded successfully..."
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
export -f load_gpg_key
|
|
|
|
|
2022-11-12 15:00:47 +00:00
|
|
|
download_deps() {
|
2022-11-12 15:58:44 +00:00
|
|
|
local train_chart="$1"
|
2022-11-12 14:27:40 +00:00
|
|
|
|
2022-11-12 16:02:16 +00:00
|
|
|
# Extract dependencies for the Chart
|
2022-11-12 15:58:44 +00:00
|
|
|
deps=$(go-yq '.dependencies' "$charts_path/$train_chart/Chart.yaml")
|
2022-11-12 16:02:16 +00:00
|
|
|
# Find how many deps exist, so we can loop through them
|
2022-11-12 15:00:47 +00:00
|
|
|
length=$(echo "$deps" | go-yq '. | length')
|
|
|
|
|
2022-11-12 18:06:22 +00:00
|
|
|
echo "🤖🔨 Processing <$charts_path/$train_chart>... Dependencies: $length"
|
2022-11-12 15:00:47 +00:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
for idx in $(eval echo "{0..$length}"); do
|
2022-11-12 16:02:16 +00:00
|
|
|
# Retrieve info for the dep in the current index..
|
2022-11-12 15:00:47 +00: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')
|
|
|
|
|
2022-11-12 18:06:22 +00:00
|
|
|
# Remove http:// or https:// from url to create a dir name
|
|
|
|
repo_dir="${repo#http://}"
|
|
|
|
repo_dir="${repo#https://}"
|
|
|
|
|
2022-11-12 15:00:47 +00:00
|
|
|
echo "**********"
|
|
|
|
echo "🔗 Dependency: $name"
|
|
|
|
echo "🆚 Version: $version"
|
|
|
|
echo "🏠 Repository: $repo"
|
2022-11-12 14:27:40 +00:00
|
|
|
echo ""
|
|
|
|
|
2022-11-12 18:06:22 +00:00
|
|
|
if [ -f "$cache_path/$repo_dir/$name-$version.tgz" ]; then
|
2022-11-12 15:00:47 +00:00
|
|
|
echo "✅ Dependency exists in cache..."
|
|
|
|
else
|
|
|
|
echo "🤷♂️ Dependency does not exists in cache..."
|
|
|
|
|
|
|
|
repo_url="$repo/index.yaml"
|
2022-11-12 18:06:22 +00:00
|
|
|
if [ -f "$index_cache/$repo_dir/index.yaml" ]; then
|
|
|
|
echo "✅ Index for <$repo> exists!"
|
|
|
|
else
|
|
|
|
echo "⏬ Index for <$repo> is missing. Downloading from <$repo_url>..."
|
|
|
|
|
|
|
|
mkdir -p $index_cache/$repo_dir
|
|
|
|
wget --quiet "$repo_url" -O "$index_cache/$repo_dir/index.yaml"
|
|
|
|
if [ ! $? ]; then
|
|
|
|
echo "❌ wget encountered an error..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$index_cache/$repo_dir/index.yaml" ]; then
|
|
|
|
echo "✅ Downloaded index for <$repo>!"
|
|
|
|
else
|
|
|
|
echo "❌ Failed to download index for <$repo> from <$repo_url>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-11-12 16:02:16 +00: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 18:06:22 +00:00
|
|
|
dep_url=$(v="$version" n="$name" go-yq '.entries.[env(n)].[] | select (.version == env(v)) | .urls.[0]' "$index_cache/$repo_dir/index.yaml")
|
2022-11-12 15:00:47 +00:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "⏬ Downloading dependency $name-$version from $dep_url..."
|
2022-11-12 18:06:22 +00:00
|
|
|
mkdir -p "$cache_path/$repo_dir"
|
|
|
|
wget --quiet "$dep_url" -P "$cache_path/$repo_dir"
|
2023-05-05 18:05:46 +00:00
|
|
|
wget --quiet "$dep_url.prov" -P "$cache_path/$repo_dir"
|
2023-05-07 11:14:59 +00:00
|
|
|
|
2022-11-12 15:00:47 +00:00
|
|
|
if [ ! $? ]; then
|
|
|
|
echo "❌ wget encountered an error..."
|
2023-05-07 11:14:59 +00:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/pubring.gpg || helm dependency update "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/pubring.gpg || exit 1
|
2022-11-12 15:00:47 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-12 18:06:22 +00:00
|
|
|
if [ -f "$cache_path/$repo_dir/$name-$version.tgz" ]; then
|
2022-11-12 15:00:47 +00:00
|
|
|
echo "✅ Dependency Downloaded!"
|
2023-05-05 18:05:46 +00:00
|
|
|
echo "Validating dependency signature..."
|
2023-05-07 11:14:59 +00:00
|
|
|
helm verify $cache_path/$repo_dir/$name-$version.tgz --keyring $gpg_dir/pubring.gpg || helm verify $cache_path/$repo_dir/$name-$version.tgz --keyring $gpg_dir/pubring.gpg || echo "❌ Failed to verify dependency chart signature" && exit 1
|
2022-11-12 15:00:47 +00:00
|
|
|
else
|
|
|
|
echo "❌ Failed to download dependency"
|
|
|
|
# Try helm dependency build/update or otherwise fail fast if a dep fails to download...
|
2023-05-07 11:14:59 +00:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/pubring.gpg || helm dependency update "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/pubring.gpg || exit 1
|
2022-11-12 14:27:40 +00:00
|
|
|
fi
|
2022-11-12 15:00:47 +00:00
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
|
2022-11-12 15:58:44 +00:00
|
|
|
mkdir -p "$charts_path/$train_chart/charts"
|
|
|
|
echo "📝 Copying dependency <$name-$version.tgz> to <$charts_path/$train_chart/charts>..."
|
2022-11-12 18:06:22 +00:00
|
|
|
cp "$cache_path/$repo_dir/$name-$version.tgz" "$charts_path/$train_chart/charts"
|
2022-11-12 15:00:47 +00:00
|
|
|
|
2022-11-12 16:09:02 +00:00
|
|
|
if [ -f "$charts_path/$train_chart/charts/$name-$version.tgz" ]; then
|
2022-11-12 15:00:47 +00:00
|
|
|
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 15:58:44 +00:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || helm dependency update "$charts_path/$train_chart/Chart.yaml" || exit 1
|
2022-11-12 15:00:47 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2023-05-07 11:14:59 +00:00
|
|
|
export -f
|
|
|
|
|
|
|
|
load_gpg_key
|
2022-11-12 15:00:47 +00:00
|
|
|
|
2022-11-12 15:58:44 +00:00
|
|
|
if [ -z "$1" ]; then
|
2022-11-12 15:00:47 +00:00
|
|
|
for train in "${trains[@]}"; do
|
2022-11-12 15:58:44 +00:00
|
|
|
for chart in $(ls "$charts_path/$train"); do
|
2022-11-12 15:00:47 +00:00
|
|
|
download_deps "${train}/${chart}"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
|
|
|
download_deps "$1"
|
2022-11-12 15:22:44 +00:00
|
|
|
fi
|