2 ################################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property. #
4 # Copyright (c) 2019 Nokia. #
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. #
17 ################################################################################
20 while [ -n "$1" ]; do # while loop starts
31 ;; # Message for -b option
35 ;; # Message for -c option
41 -d) DESCRIPTOR_PATH=$2
45 -c) CONFIG_JSON_PATH=$2
49 -h) HELM_REPO_USERNAME=$2
53 -p) HELM_REPO_PASSWORD=$2
57 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
68 if [ -z $CHART_NAME ]; then
69 echo "Please specify chart name using -n option."
72 if [ -z $CHART_VERSION ]; then
73 echo "Please specify chart version using -v option."
76 if [ -z $FULLIMAGE ]; then
77 echo "Please specify image using -i option."
80 if [ -z $DESCRIPTOR_PATH ]; then
81 echo "Please specify descriptor file using -d option."
84 if [ -z $CONFIG_JSON_PATH ]; then
85 echo "Please specify config json file using -c option."
90 if [ ! -f $DESCRIPTOR_PATH ]; then
91 echo "Descriptor file cannot be founded at $DESCRIPTOR_PATH"
94 if [ ! -f $CONFIG_JSON_PATH ]; then
95 echo "Config json file cannot be founded at $CONFIG_JSON_PATH"
100 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
103 source $DIR/../etc/xapp.conf
105 if [ -z $OVERRIDEYAML ]; then
106 HELM_REPO=$default_helm_repo
107 DOCKER_REGISTRY=$default_docker_registry
109 helm_repo_override=$(grep "^ *helmRepository:" $OVERRIDEYAML | awk '{gsub(/ /,""); gsub(/\"/,""); split($0, b, "tory:");split(b[2],c,"#"); print c[1]}')
110 docker_reg_override=$(grep "^ *repository:" $OVERRIDEYAML | awk '{ gsub(/ /,""); gsub(/\"/,""); split($0, b, "tory:");split(b[2],c,"#"); print c[1]}')
111 if [ -z $helm_repo_override ]; then
112 HELM_REPO=$default_helm_repo
114 HELM_REPO=$helm_repo_override
117 if [ -z $docker_reg_override ]; then
118 DOCKER_REGISTRY=$default_docker_registry
120 DOCKER_REGISTRY=$docker_reg_override
127 rm -rf /tmp/$CHART_NAME
129 cp -r $DIR/../helm/xapp-std/ /tmp/$CHART_NAME
133 sed -i "s/^name: xapp-std/name: $CHART_NAME/" /tmp/$CHART_NAME/Chart.yaml
134 sed -i "s/^version: 0.0.1/version: $CHART_VERSION/" /tmp/$CHART_NAME/Chart.yaml
137 registry_path=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); if(n>1) print a[1]}')
141 tag=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); split(a[n], b, ":"); print b[2]}')
143 image=$(echo $FULLIMAGE | awk -v head="$registry_path/" -v tail=":$tag" '{gsub (head, ""); gsub(tail,""); gsub(/\//,"\\/"); print $0}')
146 sed -i "s/^ name: xapp-std/ name: $CHART_NAME/" /tmp/$CHART_NAME/values.yaml
147 sed -i "s/^ name: xapp-std/ name: $image/" /tmp/$CHART_NAME/values.yaml
148 sed -i "s/^ tag: latest/ tag: $tag/" /tmp/$CHART_NAME/values.yaml
151 if [ -z $registry_path ]; then
152 sed -i "s/^ repository: xapp-std-reg/ repository: $DOCKER_REGISTRY/" /tmp/$CHART_NAME/values.yaml
154 sed -i "s/^ repository: xapp-std-reg/ repository: $registry_path/" /tmp/$CHART_NAME/values.yaml
158 mkdir /tmp/$CHART_NAME/config/
159 mkdir /tmp/$CHART_NAME/descriptors/
161 cp $CONFIG_JSON_PATH /tmp/$CHART_NAME/config/
162 cp $DESCRIPTOR_PATH /tmp/$CHART_NAME/descriptors/
165 helm package -d /tmp /tmp/$CHART_NAME
169 curl -k -u $HELM_REPO_USERNAME:$HELM_REPO_PASSWORD $HELM_REPO --upload-file /tmp/$CHART_NAME-$CHART_VERSION.tgz -v