wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ############################################################################## |
| 3 | # |
| 4 | # Copyright (c) 2019 AT&T Intellectual Property. |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 5 | # Copyright (c) 2022 Samsung Electronics Co., Ltd. |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 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 | ############################################################################## |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 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" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 25 | |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 26 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 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 |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 32 | HELMVERSION=3.9.0 |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 33 | fi |
| 34 | if [[ "${2:-nope}" != "nope" ]]; then |
| 35 | OVERRIDEYAML=$2 |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 36 | fi |
| 37 | |
Zhe Huang | 1c0c34b | 2020-04-07 16:50:52 -0400 | [diff] [blame] | 38 | ROOT_DIR="$(pwd)" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 39 | HELM_COMMAND=helm |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 40 | CHARTMUSEUM_COMMAND=chartmuseum |
| 41 | CHARTMUSEUM_VERSION=0.14.0 |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 42 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 43 | if ! $($HELM_COMMAND > /dev/null);then |
| 44 | echo "Download and install Helm" |
| 45 | if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then |
subhash kumar singh | ec2b8b6 | 2021-09-07 22:02:32 +0530 | [diff] [blame] | 46 | wget -nv https://get.helm.sh/helm-v${HELMVERSION}-linux-amd64.tar.gz |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 47 | fi |
| 48 | tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz |
| 49 | mv linux-amd64/helm ./ |
| 50 | HELM_COMMAND=./helm |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 51 | fi |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 52 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 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 |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 56 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 57 | # Start Helm local repo if there isn't one |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 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 |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 71 | echo "Stopping existing local Helm server." |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 72 | kill -9 "$(pgrep servecm)" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 73 | fi |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 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 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 88 | echo "Starting local Helm server" |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 89 | $HELM_COMMAND servecm --port=8879 --storage local --storage-local-rootdir ./local-repo --context-path=/charts & |
| 90 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 91 | # Package ric-common and serve it using Helm local repo |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 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 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 95 | # Make sure that helm local repo is added |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 96 | $HELM_COMMAND repo index ./local-repo |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 97 | $HELM_COMMAND repo add local http://127.0.0.1:8879/charts |
Youhwan Seol | 5b91760 | 2022-09-08 10:52:57 +0900 | [diff] [blame] | 98 | |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 99 | # Remove it/dep charts |
| 100 | rm -rf ./dep |
Zhe Huang | dbdd2b5 | 2020-03-26 16:50:33 -0400 | [diff] [blame] | 101 | |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 102 | # Create array of helm charts |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 103 | echo "Finding all Helm charts" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 104 | CHART_ARRAY=() |
| 105 | while IFS= read -r -d $'\0'; do |
| 106 | CHART_ARRAY+=("$REPLY") |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 107 | done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0') |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 108 | |
| 109 | echo "***************************************" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 110 | for dir in "${CHART_ARRAY[@]}" |
| 111 | do |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 112 | echo "Running helm lint and verification on chart $dir" |
| 113 | echo "Update chart dependency" |
| 114 | $HELM_COMMAND dep up "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 115 | # Lint clearly marks errors; e.g., [ERROR] |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 116 | echo "Performing Helm lint" |
| 117 | if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 118 | $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 119 | else |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 120 | $HELM_COMMAND lint "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 121 | fi |
| 122 | echo "***************************************************************************************************************" |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 123 | echo "Rendering Helm charts locally" |
| 124 | if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 125 | $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 126 | else |
Zhe Huang | 2a9da68 | 2020-04-07 17:33:19 -0400 | [diff] [blame] | 127 | $HELM_COMMAND template "$dir" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 128 | fi |
| 129 | echo "***************************************************************************************************************" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 130 | done |
Zhe Huang | faf7b36 | 2020-03-26 17:35:19 -0400 | [diff] [blame] | 131 | echo "--> verify-ric-charts ends" |
wrider | db365a7 | 2020-01-20 15:28:51 -0500 | [diff] [blame] | 132 | exit 0 |
| 133 | |