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-23 12:14:16 +00:00
|
|
|
"operators"
|
2022-11-12 14:27:40 +00:00
|
|
|
)
|
|
|
|
|
2023-05-07 11:14:59 +00:00
|
|
|
load_gpg_key() {
|
|
|
|
echo ""
|
|
|
|
echo "⏬ Downloading and Loading TrueCharts pgp Public Key"
|
|
|
|
gpg_dir=.cr-gpg
|
2023-05-23 08:26:41 +00:00
|
|
|
mkdir -p "$gpg_dir"
|
|
|
|
curl --silent https://keybase.io/truecharts/pgp_keys.asc | gpg --dearmor > $gpg_dir/pubring.gpg || echo "❌ Couldn't load Public Key."
|
2023-07-15 17:22:49 +00:00
|
|
|
curl --silent https://cert-manager.io/public-keys/cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg > $gpg_dir/certman.gpg || echo "❌ Couldn't load certman 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
|
|
|
|
2023-07-15 17:22:49 +00:00
|
|
|
# tmp hotpatch for cert-manager
|
|
|
|
if [[ ! "$dep_url" == "https"* ]]; then
|
2023-12-05 18:57:48 +00:00
|
|
|
if [[ "$name" =~ "cert-manager" ]]; then
|
|
|
|
dep_url="https://charts.jetstack.io/${dep_url}"
|
|
|
|
fi
|
2023-07-15 17:22:49 +00:00
|
|
|
fi
|
|
|
|
|
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-07-15 17:22:49 +00:00
|
|
|
wget --quiet "$dep_url.prov" -P "$cache_path/$repo_dir" || echo "failed downloading .prov"
|
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-25 17:45:41 +00:00
|
|
|
if [[ "$train_chart" =~ incubator\/.* ]]; then
|
2023-05-24 18:22:33 +00:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-11-14 13:12:27 +00:00
|
|
|
elif [[ "$name" =~ "velero" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-11-15 14:39:03 +00:00
|
|
|
elif [[ "$name" =~ "metallb" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "cloudnative-pg" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "kube-prometheus-stack" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-12-05 18:39:08 +00:00
|
|
|
elif [[ "$name" =~ "openebs" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "csi-driver-smb" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "csi-driver-nfs" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-07-15 17:22:49 +00:00
|
|
|
elif [[ "$name" =~ "cert-manager" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/certman.gpg || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/certman.gpg || exit 1
|
2023-05-24 18:22:33 +00:00
|
|
|
else
|
|
|
|
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
|
|
|
|
fi
|
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-07-15 17:22:49 +00:00
|
|
|
if [[ "$name" =~ "cert-manager" ]]; then
|
|
|
|
helm verify $cache_path/$repo_dir/$name-$version.tgz --keyring $gpg_dir/certman.gpg || \
|
|
|
|
helm verify $cache_path/$repo_dir/$name-$version.tgz --keyring $gpg_dir/certman.gpg || exit 1
|
2023-11-14 13:12:27 +00:00
|
|
|
elif [[ "$name" =~ "velero" ]]; then
|
|
|
|
echo "Velero is not signed..."
|
2023-11-15 14:39:03 +00:00
|
|
|
elif [[ "$name" =~ "metallb" ]]; then
|
|
|
|
echo "metallb is not signed..."
|
|
|
|
elif [[ "$name" =~ "cloudnative-pg" ]]; then
|
|
|
|
echo "cloudnative-pg is not signed..."
|
|
|
|
elif [[ "$name" =~ "kube-prometheus-stack" ]]; then
|
|
|
|
echo "kube-prometheus-stack is not signed..."
|
2023-12-05 18:39:08 +00:00
|
|
|
elif [[ "$name" =~ "openebs" ]]; then
|
|
|
|
echo "openebs is not signed..."
|
|
|
|
elif [[ "$name" =~ "csi-driver-smb" ]]; then
|
2023-12-05 18:47:58 +00:00
|
|
|
echo "csi-driver-smb is not signed..."
|
2023-12-05 18:39:08 +00:00
|
|
|
elif [[ "$name" =~ "csi-driver-nfs" ]]; then
|
2023-12-05 18:47:58 +00:00
|
|
|
echo "csi-driver-nfs is not signed..."
|
2023-07-15 17:22:49 +00:00
|
|
|
elif [[ ! "$train_chart" =~ incubator\/.* ]]; then
|
2023-05-25 11:39:13 +00:00
|
|
|
echo "Validating dependency signature..."
|
2023-05-25 10:07:45 +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 || exit 1
|
2023-05-25 11:39:13 +00:00
|
|
|
else
|
2023-05-25 17:22:23 +00:00
|
|
|
echo "Skipping dependency signature verification for $train_chart..."
|
2023-05-25 10:07:45 +00:00
|
|
|
fi
|
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-25 17:45:41 +00:00
|
|
|
if [[ "$train_chart" =~ incubator\/.* ]]; then
|
2023-05-24 18:22:33 +00:00
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-11-14 13:12:27 +00:00
|
|
|
elif [[ "$name" =~ "velero" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-11-15 14:39:03 +00:00
|
|
|
elif [[ "$name" =~ "metallb" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "cloudnative-pg" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "kube-prometheus-stack" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-12-05 18:39:08 +00:00
|
|
|
elif [[ "$name" =~ "openebs" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "csi-driver-smb" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
|
|
|
elif [[ "$name" =~ "csi-driver-nfs" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml"|| exit 1
|
2023-07-15 17:22:49 +00:00
|
|
|
elif [[ "$name" =~ "cert-manager" ]]; then
|
|
|
|
helm dependency build "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/certman.gpg || \
|
|
|
|
helm dependency update "$charts_path/$train_chart/Chart.yaml" --verify --keyring $gpg_dir/certman.gpg || exit 1
|
2023-05-24 18:22:33 +00:00
|
|
|
else
|
|
|
|
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
|
|
|
|
fi
|
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...
|
2023-05-23 08:26:41 +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-23 08:26:41 +00:00
|
|
|
export -f download_deps
|
2023-05-07 11:14:59 +00:00
|
|
|
|
|
|
|
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
|