blob: cf7b7a927dd726bc04fe368d5fcbd7e394f654b2 [file] [log] [blame]
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -04001#!/bin/bash
2##############################################################################
3#
4# Copyright (c) 2019 AT&T Intellectual Property.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18##############################################################################
19
20# Installs well-known RIC charts then verifies specified helm chart
21# Requires chart tgz archives in /tmp
22OVERRIDEYAML=$1
23
24ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
Zhe Huangdc00cdf2020-02-10 13:45:15 -050025
26# Start Helm local repo if there isn't one
27HELM_REPO_PID=$(ps -x | grep "helm serve" | grep -v "grep" | awk '{print $1}')
28if [ -z "$HELM_REPO_PID" ]; then
29 nohup helm serve >& /dev/null &
30fi
31
32echo "Package ric-common and serve it using Helm local repo"
33HELM_HOME=$(helm home)
34COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/ric-common/Chart.yaml | grep version | awk '{print $2}')
35helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/ric-common
36cp /tmp/ric-common-$COMMON_CHART_VERSION.tgz $HELM_HOME/repository/local/
37
38AUX_COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/aux-common/Chart.yaml | grep version | awk '{print $2}')
39helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/aux-common
40cp /tmp/aux-common-$COMMON_CHART_VERSION.tgz $HELM_HOME/repository/local/
41
42helm repo index $HELM_HOME/repository/local/
43
44echo "Make sure that helm local repo is added"
45helm repo remove local
46helm repo add local http://127.0.0.1:8879/charts
47
48echo "Create array of helm charts"
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040049CHART_ARRAY=()
50while IFS= read -r -d $'\0'; do
51 CHART_ARRAY+=("$REPLY")
Zhe Huangdc00cdf2020-02-10 13:45:15 -050052done < <(find $ROOT_DIR/../ -maxdepth 5 -name Chart.yaml -printf '%h\0')
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040053
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040054echo "***************************************"
55
56
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040057for dir in "${CHART_ARRAY[@]}"
58do
Zhe Huangdc00cdf2020-02-10 13:45:15 -050059 echo "Update chart dependency for directory $dir"
60 helm dep up $dir
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040061 # Lint clearly marks errors; e.g., [ERROR]
62 if [ -z $OVERRIDEYAML ]; then
63 helm lint $dir > /tmp/output 2>&1
64 else
65 helm lint -f $OVERRIDEYAML $dir> /tmp/output 2>&1
66 fi
67 echo "***************************************************************************************************************"
Zhe Huangdc00cdf2020-02-10 13:45:15 -050068 cat /tmp/output
69
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040070 egrep -q '^Error: [0-9]* chart\(s\) linted, [0-9]* chart\(s\) failed' /tmp/output && exit 1
71 echo "***************************************************************************************************************"
72
73 if [ -z $OVERRIDEYAML ]; then
74 helm template $dir > /tmp/output 2>&1
75 else
76 helm template -f $OVERRIDEYAML $dir > /tmp/output 2>&1
77 fi
78 echo "***************************************************************************************************************"
Zhe Huangdc00cdf2020-02-10 13:45:15 -050079 cat /tmp/output
80 sleep 1
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040081 egrep -n '%!.\(.*=.*\)' /tmp/output && echo "Error: Type mismatch." && exit 1
82 echo "***************************************************************************************************************"
Lott, Christopher (cl778h)6f157d72019-07-25 06:32:02 -040083done