blob: 34df4247451659671302fced25e7d9e065f9b112 [file] [log] [blame]
Zhe Huangdccf4732019-09-11 13:59:35 -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
22
23
24while [ -n "$1" ]; do # while loop starts
25
26 case "$1" in
27
28 -f) OVERRIDEYAML=$2
29 shift
30 ;;
31 *) echo "Option $1 not recognized. Please use -f to specify the recipe path." ;; # In case you typed a different option other than a,b,c
32
33 esac
34
35 shift
36
37done
38
39if [ -z $OVERRIDEYAML ]; then
40 echo "Deploy recipe is missing. Please use -f to specify the recipe path."
41 exit 1
42fi
43
44
45ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
Zhe Huangdc00cdf2020-02-10 13:45:15 -050046
47
48# Start Helm local repo if there isn't one
49HELM_REPO_PID=$(ps -x | grep "helm serve" | grep -v "grep" | awk '{print $1}')
50if [ -z "$HELM_REPO_PID" ]; then
51 nohup helm serve >& /dev/null &
52fi
53
54# Package ric-common and serve it using Helm local repo
55HELM_HOME=$(helm home)
56COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/ric-common/Chart.yaml | grep version | awk '{print $2}')
57helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/ric-common
58cp /tmp/ric-common-$COMMON_CHART_VERSION.tgz $HELM_HOME/repository/local/
59helm repo index $HELM_HOME/repository/local/
60
61
62# Make sure that helm local repo is added
63helm repo remove local
64helm repo add local http://127.0.0.1:8879/charts
65
66
67
68
Zhe Huangdccf4732019-09-11 13:59:35 -040069TEMP_DIR=/tmp
70rm -rf $TEMP_DIR/imagelist
71touch $TEMP_DIR/imagelist
72CHART_ARRAY=()
73while IFS= read -r -d $'\0'; do
74 CHART_ARRAY+=("$REPLY")
75done < <(find $ROOT_DIR/../ -name Chart.yaml -printf '%h\0')
76
Zhe Huangdccf4732019-09-11 13:59:35 -040077
Zhe Huangdccf4732019-09-11 13:59:35 -040078echo "***************************************"
79
80
81
82for dir in "${CHART_ARRAY[@]}"
83do
84
Zhe Huangdccf4732019-09-11 13:59:35 -040085 echo "Analyzing Chart $(echo $dir | awk '{n=split($0, a, "/"); print a[n]}')"
86 echo $dir
Zhe Huangdccf4732019-09-11 13:59:35 -040087
Zhe Huangdc00cdf2020-02-10 13:45:15 -050088 #helm dep up $dir > /dev/null 2>&1
89 helm dep up $dir
Zhe Huangdccf4732019-09-11 13:59:35 -040090
91 IMAGE_ARRAY=$(helm template -f $OVERRIDEYAML $dir | grep "image:" | awk '{ gsub(/.*image: /, "", $0); gsub(/"/, "", $0); print $0}' )
92
93
94 for f in $IMAGE_ARRAY; do
95 if [ ! -z $f ]; then
96 FOUND=$(grep $f $TEMP_DIR/imagelist)
97 if [ -z $FOUND ]; then
98 echo "Found unique docker image $f."
99 echo $f >> $TEMP_DIR/imagelist
100 fi
101 fi
102 done
103
104 echo "***************************************"
105done
106
107
108
109echo "Your image list is available here: $TEMP_DIR/imagelist"