Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 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 )" |
Zhe Huang | dc00cdf | 2020-02-10 13:45:15 -0500 | [diff] [blame] | 46 | |
| 47 | |
| 48 | # Start Helm local repo if there isn't one |
| 49 | HELM_REPO_PID=$(ps -x | grep "helm serve" | grep -v "grep" | awk '{print $1}') |
| 50 | if [ -z "$HELM_REPO_PID" ]; then |
| 51 | nohup helm serve >& /dev/null & |
| 52 | fi |
| 53 | |
| 54 | # Package ric-common and serve it using Helm local repo |
| 55 | HELM_HOME=$(helm home) |
| 56 | COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/ric-common/Chart.yaml | grep version | awk '{print $2}') |
| 57 | helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/ric-common |
| 58 | cp /tmp/ric-common-$COMMON_CHART_VERSION.tgz $HELM_HOME/repository/local/ |
| 59 | helm repo index $HELM_HOME/repository/local/ |
| 60 | |
| 61 | |
| 62 | # Make sure that helm local repo is added |
| 63 | helm repo remove local |
| 64 | helm repo add local http://127.0.0.1:8879/charts |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 69 | TEMP_DIR=/tmp |
| 70 | rm -rf $TEMP_DIR/imagelist |
| 71 | touch $TEMP_DIR/imagelist |
| 72 | CHART_ARRAY=() |
| 73 | while IFS= read -r -d $'\0'; do |
| 74 | CHART_ARRAY+=("$REPLY") |
| 75 | done < <(find $ROOT_DIR/../ -name Chart.yaml -printf '%h\0') |
| 76 | |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 77 | |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 78 | echo "***************************************" |
| 79 | |
| 80 | |
| 81 | |
| 82 | for dir in "${CHART_ARRAY[@]}" |
| 83 | do |
| 84 | |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 85 | echo "Analyzing Chart $(echo $dir | awk '{n=split($0, a, "/"); print a[n]}')" |
| 86 | echo $dir |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 87 | |
Zhe Huang | dc00cdf | 2020-02-10 13:45:15 -0500 | [diff] [blame] | 88 | #helm dep up $dir > /dev/null 2>&1 |
| 89 | helm dep up $dir |
Zhe Huang | dccf473 | 2019-09-11 13:59:35 -0400 | [diff] [blame] | 90 | |
| 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 "***************************************" |
| 105 | done |
| 106 | |
| 107 | |
| 108 | |
| 109 | echo "Your image list is available here: $TEMP_DIR/imagelist" |