RIC-919 Upgrade influxdb helm chart v1.8 > v2.2
[ric-plt/ric-dep.git] / bin / verify-ric-charts
1 #!/bin/bash
2 ##############################################################################
3 #
4 #   Copyright (c) 2019 AT&T Intellectual Property.
5 #   Copyright (c) 2022 Samsung Electronics Co., Ltd.
6 #
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18 #
19 ##############################################################################
20 # Verifies RIC helm charts
21 # Requires Linux with wget and tar.
22 # This script should be executed inside the ric-plt/ric-dep bin directory only.
23 set -eu
24 echo "--> verify-ric-charts"
25
26
27 # (Optional) provide HELMVERSION as first parameter. It selects the helm client version
28 # (Optional) provide OVERRIDEYAML as the second parameter. It allows us to specify an override file to replace values used to render the helm charts
29 if [[ "${1:-nope}" != "nope" ]]; then
30     HELMVERSION=$1
31 else
32     HELMVERSION=3.9.0
33 fi
34 if [[ "${2:-nope}" != "nope" ]]; then
35     OVERRIDEYAML=$2
36 fi
37
38 ROOT_DIR="$(pwd)"
39 HELM_COMMAND=helm
40 CHARTMUSEUM_COMMAND=chartmuseum
41 CHARTMUSEUM_VERSION=0.14.0
42
43 if ! $($HELM_COMMAND > /dev/null);then
44     echo "Download and install Helm"
45     if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
46       wget -nv https://get.helm.sh/helm-v${HELMVERSION}-linux-amd64.tar.gz
47     fi
48     tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
49     mv linux-amd64/helm ./
50     HELM_COMMAND=./helm
51 fi
52
53 # Set up ric common template
54 # Download it/dep common template charts
55 git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep
56
57 # Start Helm local repo if there isn't one
58 # In Helm3, running local repo requires chartmuseum and helm-servecm plugin
59 if ! $($CHARTMUSEUM_COMMAND > /dev/null);then
60     echo "Download and install chartmuseum"
61     wget -nv https://get.helm.sh/chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz
62     tar -xvf ./chartmuseum-v${CHARTMUSEUM_VERSION}-linux-amd64.tar.gz
63     mv linux-amd64/chartmuseum ./
64     CHARTMUSEUM_COMMAND=./chartmuseum
65
66     curl https://raw.githubusercontent.com/helm/chartmuseum/main/scripts/get-chartmuseum | bash
67     $HELM_COMMAND plugin install https://github.com/jdolitsky/helm-servecm
68 fi
69
70 if [ ! -z $(pgrep servecm) ]; then
71     echo "Stopping existing local Helm server."
72     kill -9 "$(pgrep servecm)"
73 fi
74
75 echo "Wait for installing servecm plugin"
76 timeout=10
77 while [ "$timeout" -gt 0 ]; do
78   if $HELM_COMMAND servecm --help | grep "ChartMuseum"; then
79     break
80   fi
81   sleep 1s
82   ((timeout--))
83 done
84
85 rm -rf ./local-repo
86 mkdir ./local-repo
87
88 echo "Starting local Helm server"
89 $HELM_COMMAND servecm --port=8879 --storage local --storage-local-rootdir ./local-repo --context-path=/charts &
90
91 # Package ric-common and serve it using Helm local repo
92 $HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common"
93 $HELM_COMMAND package --destination ./local-repo "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common"
94
95 # Make sure that helm local repo is added
96 $HELM_COMMAND repo index ./local-repo
97 $HELM_COMMAND repo add local http://127.0.0.1:8879/charts
98
99 # Remove it/dep charts
100 rm -rf ./dep
101
102 # Create array of helm charts
103 echo "Finding all Helm charts"
104 CHART_ARRAY=()
105 while IFS= read -r -d $'\0'; do
106     CHART_ARRAY+=("$REPLY")
107 done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0')
108
109 echo "***************************************"
110 for dir in "${CHART_ARRAY[@]}"
111 do
112     echo "Running helm lint and verification on chart $dir"
113     echo "Update chart dependency"
114     $HELM_COMMAND dep up "$dir"
115     # Lint clearly marks errors; e.g., [ERROR]
116     echo "Performing Helm lint"
117     if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
118         $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir"
119     else
120         $HELM_COMMAND lint "$dir" 
121     fi
122     echo "***************************************************************************************************************"
123     echo "Rendering Helm charts locally"
124     if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
125         $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir"
126     else
127         $HELM_COMMAND template "$dir"
128     fi
129     echo "***************************************************************************************************************"
130 done
131 echo "--> verify-ric-charts ends"
132 exit 0
133