Skip to content

Commit

Permalink
fetch addon helm charts from jihulab
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming committed Nov 16, 2023
1 parent 5d65b44 commit c394816
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions docker/custom-scripts/fetch-all-helm-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,58 @@
set -e

if [ $# -ne 2 ]; then
echo "Syntax: ./fetch-all-helm-charts.sh KB_CHART_DIR TARGET_DIR"
exit 1
echo "Syntax: ./fetch-all-helm-charts.sh KB_CHART_DIR TARGET_DIR"
exit 1
fi

KB_CHART_DIR=${1}
TARGET_DIR=${2:-"charts"}
MANIFESTS_DIR="/tmp/manifests"
GITHUB_HELM_CHARTS_URL=https://github.com/apecloud/helm-charts/releases/download
MANIFESTS_DIR="/tmp/manifests/"

# make directories
mkdir -p "${TARGET_DIR}"
mkdir -p "${MANIFESTS_DIR}"

# get all manifests
helm version
helm template "${KB_CHART_DIR}" --output-dir "${MANIFESTS_DIR}" --set addonChartLocationBase=$GITHUB_HELM_CHARTS_URL
ADDON_DIR="kubeblocks/templates/addons"
APP_DIR="kubeblocks/templates/applications"
ADDON_HELM_CHART_URL=https://jihulab.com/api/v4/projects/150246/packages/helm/stable/charts
APP_HELM_CHART_URL=https://jihulab.com/api/v4/projects/152630/packages/helm/stable/charts

# travel all addon manifests and get the helm charts
for f in "${MANIFESTS_DIR}/kubeblocks/templates/addons"/*; do
# fetch helm charts to target directory
# parameters:
# $1: helm repo url
# $2: addon CRs directory
fetch_helm_charts() {
helm template "${KB_CHART_DIR}" --output-dir "${MANIFESTS_DIR}" --set addonChartLocationBase="$1"
# travel all addon manifests and get the helm charts
for f in "${MANIFESTS_DIR}$2"/*; do
if [ -d "${f}" ]; then
continue
continue
fi

kind=$(yq eval '.kind' "${f}")
if [ "${kind}" != "Addon" ]; then
continue
continue
fi

# get helm chart location
chartURL=$(yq eval '.spec.helm.chartLocationURL' "${f}")
if [ -z "${chartURL}" ]; then
echo "chartLocationURL is empty in ${f}"
exit 1
echo "chartLocationURL is empty in ${f}"
exit 1
fi

# fetch the helm chart
echo "fetching helm chart from ${chartURL}"
helm fetch "$chartURL" -d "${TARGET_DIR}"
done
done
}

# make directories
mkdir -p "${TARGET_DIR}"
mkdir -p "${MANIFESTS_DIR}"

# get all manifests
helm version

echo "fetch addons helm charts, addon CRs directory: ${ADDON_DIR}, helm chart url: ${ADDON_HELM_CHART_URL}"
fetch_helm_charts "${ADDON_HELM_CHART_URL}" "${ADDON_DIR}"

echo "fetch applications helm charts, applications CRs directory: ${APP_DIR}, helm chart url: ${APP_HELM_CHART_URL}"
fetch_helm_charts "${APP_HELM_CHART_URL}" "${APP_DIR}"

0 comments on commit c394816

Please sign in to comment.