| #!/bin/bash |
| ############################################################################## |
| # |
| # Copyright (c) 2019 AT&T Intellectual Property. |
| # Copyright (c) 2022 Samsung Electronics Co., Ltd. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| ############################################################################## |
| # Verifies RIC helm charts |
| # Requires Linux with wget and tar. |
| # This script should be executed inside the ric-plt/ric-dep bin directory only. |
| set -eu |
| echo "--> verify-ric-charts" |
| |
| |
| # (Optional) provide HELMVERSION as first parameter. It selects the helm client version |
| # (Optional) provide OVERRIDEYAML as the second parameter. It allows us to specify an override file to replace values used to render the helm charts |
| if [[ "${1:-nope}" != "nope" ]]; then |
| HELMVERSION=$1 |
| else |
| HELMVERSION=3.9.0 |
| fi |
| if [[ "${2:-nope}" != "nope" ]]; then |
| OVERRIDEYAML=$2 |
| fi |
| |
| ROOT_DIR="$(pwd)" |
| HELM_COMMAND=helm |
| CHARTMUSEUM_COMMAND=chartmuseum |
| CHARTMUSEUM_VERSION=0.14.0 |
| |
| if ! $($HELM_COMMAND > /dev/null);then |
| echo "Download and install Helm" |
| if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then |
| wget -nv https://get.helm.sh/helm-v${HELMVERSION}-linux-amd64.tar.gz |
| fi |
| tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz |
| mv linux-amd64/helm ./ |
| HELM_COMMAND=./helm |
| fi |
| |
| # Set up ric common template |
| # Download it/dep common template charts |
| git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep |
| |
| # Start Helm local repo if there isn't one |
| # In Helm3, running local repo requires chartmuseum and helm-servecm plugin |
| if ! $($CHARTMUSEUM_COMMAND > /dev/null);then |
| echo "Download and install chartmuseum" |
| wget -nv https://get.helm.sh/chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz |
| tar -xvf ./chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz |
| mv linux-amd64/chartmuseum ./ |
| CHARTMUSEUM_COMMAND=./chartmuseum |
| |
| curl https://raw.githubusercontent.com/helm/chartmuseum/main/scripts/get-chartmuseum | bash |
| $HELM_COMMAND plugin install https://github.com/jdolitsky/helm-servecm |
| fi |
| |
| if [ ! -z $(pgrep servecm) ]; then |
| echo "Stopping existing local Helm server." |
| kill -9 "$(pgrep servecm)" |
| fi |
| |
| echo "Wait for installing servecm plugin" |
| timeout=10 |
| while [ "$timeout" -gt 0 ]; do |
| if $HELM_COMMAND servecm --help | grep "ChartMuseum"; then |
| break |
| fi |
| sleep 1s |
| ((timeout--)) |
| done |
| |
| rm -rf ./local-repo |
| mkdir ./local-repo |
| |
| echo "Starting local Helm server" |
| $HELM_COMMAND servecm --port=8879 --storage local --storage-local-rootdir ./local-repo --context-path=/charts & |
| |
| # Package ric-common and serve it using Helm local repo |
| $HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common" |
| $HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common" |
| |
| # Make sure that helm local repo is added |
| $HELM_COMMAND repo index ./local-repo |
| $HELM_COMMAND repo add local http://127.0.0.1:8879/charts |
| |
| # Remove it/dep charts |
| rm -rf ./dep |
| |
| # Create array of helm charts |
| echo "Finding all Helm charts" |
| CHART_ARRAY=() |
| while IFS= read -r -d $'\0'; do |
| CHART_ARRAY+=("$REPLY") |
| done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0') |
| |
| echo "***************************************" |
| for dir in "${CHART_ARRAY[@]}" |
| do |
| echo "Running helm lint and verification on chart $dir" |
| echo "Update chart dependency" |
| $HELM_COMMAND dep up "$dir" |
| # Lint clearly marks errors; e.g., [ERROR] |
| echo "Performing Helm lint" |
| if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
| $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir" |
| else |
| $HELM_COMMAND lint "$dir" |
| fi |
| echo "***************************************************************************************************************" |
| echo "Rendering Helm charts locally" |
| if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
| $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir" |
| else |
| $HELM_COMMAND template "$dir" |
| fi |
| echo "***************************************************************************************************************" |
| done |
| echo "--> verify-ric-charts ends" |
| exit 0 |
| |