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
28 -d) DOCKER_REGISTRY=$2
32 -p) CHART_DIRECTORY_PATH=$2
40 *) echo "Option $1 not recognized. Please specify the docker registry path with the -d option and specify the xApp directory path with the -p option."
41 ;; # In case you typed a different option other than -d or -p
49 if [ -z "$DOCKER_REGISTRY" ]; then
50 echo "Please specify the docker registry path with the -d option."
54 if [ -z "$CHART_DIRECTORY_PATH" ]; then
55 echo "Please specify the xApp directory path with the -p option."
59 if [ -z "$HELM_REPO" ]; then
60 echo "Please specify the helm repo uploading URL with the -h option."
65 echo "************************************************************"
67 for image in $CHART_DIRECTORY_PATH/docker_images/*/*; do
68 echo "Loading image $image"
69 OUTPUT=$(docker load -i $image)
70 IMAGE_PATH_ORIGINAL=$(echo $OUTPUT | grep image: | awk '{print $3}' )
71 IMAGENAME=$(echo $IMAGE_PATH_ORIGINAL | awk '{ n=split($0, a, "/"); print a[n] }')
72 echo "Pushing image $DOCKER_REGISTRY/$IMAGENAME"
73 docker tag $IMAGE_PATH_ORIGINAL $DOCKER_REGISTRY/$IMAGENAME
74 docker push $DOCKER_REGISTRY/$IMAGENAME || { echo "Failed to push the docker image." ; exit 1; }
78 rm -rf $CHART_DIRECTORY_PATH/chart_packages
79 mkdir -p $CHART_DIRECTORY_PATH/chart_packages
81 echo "************************************************************"
82 for chart in $CHART_DIRECTORY_PATH/helm_charts/*; do
83 echo "Onboard Helm Charts"
85 sed -i "s/^ repository: .*/ repository: $DOCKER_REGISTRY/" $chart/values.yaml
86 helm package $chart -d $CHART_DIRECTORY_PATH/chart_packages
92 echo "************************************************************"
93 for tarball in $CHART_DIRECTORY_PATH/chart_packages/*; do
94 TARBALL_FILE_NAME=$(echo $tarball | awk -F '/' '{print $NF}')
95 CHART_NAME=$(echo $TARBALL_FILE_NAME | awk -F '-' '{gsub($NF, ""); print substr($0,1,length($0)-1)}')
96 CHART_VERSION=$(echo $TARBALL_FILE_NAME | awk -F '-' '{print substr ($NF,1,length($NF)-4)}')
98 DELETE_MESSAGE=$(curl -X DELETE --connect-timeout 2 $HELM_REPO/api/charts/$CHART_NAME/$CHART_VERSION 2>/dev/null)
99 LOCATE_CHART=$(curl --connect-timeout 2 $HELM_REPO/index.yaml |& grep $TARBALL_FILE_NAME)
101 if [ ! -z "$LOCATE_CHART" ]; then
102 echo "ERROR: Helm chart delete fail."
107 UPLOAD_MESSAGE=$(curl --data-binary "@$tarball" --connect-timeout 2 $HELM_REPO/api/charts 2>/dev/null)
108 LOCATE_CHART=$(curl --connect-timeout 2 $HELM_REPO/index.yaml |& grep $TARBALL_FILE_NAME )
110 if [ -z "$LOCATE_CHART" ]; then
111 echo "ERROR: Helm chart upload failed."
116 echo "Helm chart $CHART_NAME version $CHART_VERSION uploaded successfully."