2 ##############################################################################
4 # Copyright (c) 2019 AT&T Intellectual Property.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 ##############################################################################
20 # Installs well-known RIC charts then verifies specified helm chart
21 # Requires chart tgz archives in /tmp
24 while [ -n "$1" ]; do # while loop starts
32 -d) CHART_DIRECTORY_PATH=$2
37 *) 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
45 if [ -z "$XAPPLISTFILE" ]; then
46 echo "xApp list file is missing. Please use -f to specify the path."
50 if [ -z "$CHART_DIRECTORY_PATH" ]; then
51 CHART_DIRECTORY_PATH=/tmp/xapp_charts
55 rm -rf $CHART_DIRECTORY_PATH
56 mkdir -p $CHART_DIRECTORY_PATH/helm_charts
57 mkdir -p $CHART_DIRECTORY_PATH/docker_images
60 while IFS= read -r chart
62 CHARTNAME=$(echo $chart | awk '{ n=split($0, a, "/"); split(a[n],b,":"); print b[1] }')
63 CHARTVERSION=$(echo $chart | awk '{ n=split($0, a, "/"); split(a[n],b,":"); print b[2] }')
64 HELM_REPO=$(echo $chart | awk -F'/' '{gsub($NF,""); print substr($0,1,length($0)-1)}')
66 echo "Fetching helm charts $CHARTNAME version $CHARTVERSION from repo $HELM_REPO"
67 helm repo add temp $HELM_REPO > /dev/null
68 helm fetch temp/$CHARTNAME --version $CHARTVERSION -d $CHART_DIRECTORY_PATH/helm_charts --untar
69 helm repo remove temp > /dev/null
72 done < "$XAPPLISTFILE"
74 echo "************************************************************"
75 for chart in $CHART_DIRECTORY_PATH/helm_charts/*; do
78 CHART_NAME=$(echo $chart | awk -F '/' '{print $NF}')
79 mkdir -p $CHART_DIRECTORY_PATH/docker_images/$CHART_NAME
81 IMAGE_ARRAY=$(helm template $chart | grep "image:" | awk '{ gsub(/.*image: /, "", $0); gsub(/"/, "", $0); print $0}' )
83 while read -r image; do
85 IMAGENAME=$(echo $image | awk '{ n=split($0, a, "/"); print a[n] }')
86 echo "Pulling image $image"
87 RESULT=$(docker pull $image |& grep "no basic auth credentials" )
88 if [ ! -z "$RESULT" ]; then
89 echo "You are not logined to docker registry. Please login by running \"docker login DOCKER_REGISTRY\""
93 echo "Saving image $image"
94 docker save $image -o $CHART_DIRECTORY_PATH/docker_images/$CHART_NAME/$IMAGENAME
99 done <<< "$IMAGE_ARRAY"
107 echo "************************************************************"
108 echo "xApp helm charts are downloaded to: $CHART_DIRECTORY_PATH"