30386af2c03c45da44730dcd972cacdd3f056a73
[it/dep.git] / bin / gen-image-list
1 #!/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
24 while [ -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
37 done
38
39 if [ -z $OVERRIDEYAML ]; then
40    echo "Deploy recipe is missing. Please use -f to specify the recipe path."
41    exit 1
42 fi
43
44
45 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
46 TEMP_DIR=/tmp
47 rm -rf $TEMP_DIR/imagelist
48 touch $TEMP_DIR/imagelist
49 CHART_ARRAY=()
50 while IFS= read -r -d $'\0'; do
51     CHART_ARRAY+=("$REPLY")
52 done < <(find $ROOT_DIR/../ -name Chart.yaml -printf '%h\0')
53
54 rm -fr $TEMP_DIR/ric-common*.tgz
55
56 helm package -d $TEMP_DIR $ROOT_DIR/../ric-common/Common-Template/helm/ric-common
57 echo "***************************************"
58
59
60
61 for dir in "${CHART_ARRAY[@]}"
62 do
63   
64     #rm -rf $dir/charts
65     rm -rf $dir/tmpcharts
66     echo "Analyzing Chart $(echo $dir | awk '{n=split($0, a, "/"); print a[n]}')"    
67     echo $dir 
68     mkdir -p $dir/charts
69     cp $TEMP_DIR/ric-common*.tgz $dir/charts/
70
71     helm dep up $dir > /dev/null 2>&1
72     
73     IMAGE_ARRAY=$(helm template -f $OVERRIDEYAML $dir | grep "image:" | awk '{ gsub(/.*image: /, "", $0); gsub(/"/, "", $0); print $0}' )
74     
75
76     for f in $IMAGE_ARRAY; do
77         if [ ! -z $f ]; then
78             FOUND=$(grep $f $TEMP_DIR/imagelist)
79             if [ -z $FOUND ]; then
80                 echo "Found unique docker image $f."
81                 echo $f >> $TEMP_DIR/imagelist
82             fi
83         fi
84     done
85
86     echo "***************************************"
87 done
88
89
90
91 echo "Your image list is available here: $TEMP_DIR/imagelist"