blob: 08f45635149df1f6f3e9517a2fad7bb90e75f4f6 [file] [log] [blame]
Zhe Huang563da712019-07-03 09:14:09 -04001#!/bin/bash
2################################################################################
3# Copyright (c) 2019 AT&T Intellectual Property. #
4# Copyright (c) 2019 Nokia. #
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
20while [ -n "$1" ]; do # while loop starts
21
22 case "$1" in
23
24 -n)
25 CHART_NAME=$2
26 shift
27 ;;
28
29 -v) CHART_VERSION=$2
30 shift
31 ;; # Message for -b option
32
33 -f) OVERRIDEYAML=$2
34 shift
35 ;; # Message for -c option
36
37 -i) FULLIMAGE=$2
38 shift
39 ;;
40
41 -d) DESCRIPTOR_PATH=$2
42 shift
43 ;;
44
45 -c) CONFIG_JSON_PATH=$2
46 shift
47 ;;
48
49 -h) HELM_REPO_USERNAME=$2
50 shift
51 ;;
52
53 -p) HELM_REPO_PASSWORD=$2
54 shift
55 ;;
56
57 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
58
59 esac
60
61 shift
62
63done
64
65
66
67
68if [ -z $CHART_NAME ]; then
69 echo "Please specify chart name using -n option."
70 exit 1
71fi
72if [ -z $CHART_VERSION ]; then
73 echo "Please specify chart version using -v option."
74 exit 1
75fi
76if [ -z $FULLIMAGE ]; then
77 echo "Please specify image using -i option."
78 exit 1
79fi
80if [ -z $DESCRIPTOR_PATH ]; then
81 echo "Please specify descriptor file using -d option."
82 exit 1
83fi
84if [ -z $CONFIG_JSON_PATH ]; then
85 echo "Please specify config json file using -c option."
86 exit 1
87fi
88
89
90if [ ! -f $DESCRIPTOR_PATH ]; then
91 echo "Descriptor file cannot be founded at $DESCRIPTOR_PATH"
92 exit 1
93fi
94if [ ! -f $CONFIG_JSON_PATH ]; then
95 echo "Config json file cannot be founded at $CONFIG_JSON_PATH"
96 exit 1
97fi
98
99
100DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
101
102
103source $DIR/../etc/xapp.conf
104
105if [ -z $OVERRIDEYAML ]; then
106 HELM_REPO=$default_helm_repo
107 DOCKER_REGISTRY=$default_docker_registry
108else
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
113 else
114 HELM_REPO=$helm_repo_override
115 fi
116
117 if [ -z $docker_reg_override ]; then
118 DOCKER_REGISTRY=$default_docker_registry
119 else
120 DOCKER_REGISTRY=$docker_reg_override
121 fi
122fi
123
124
125
126
127rm -rf /tmp/$CHART_NAME
128
129cp -r $DIR/../helm/xapp-std/ /tmp/$CHART_NAME
130
131
132
133sed -i "s/^name: xapp-std/name: $CHART_NAME/" /tmp/$CHART_NAME/Chart.yaml
134sed -i "s/^version: 0.0.1/version: $CHART_VERSION/" /tmp/$CHART_NAME/Chart.yaml
135
136
137registry_path=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); if(n>1) print a[1]}')
138
139
140
141tag=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); split(a[n], b, ":"); print b[2]}')
142
143image=$(echo $FULLIMAGE | awk -v head="$registry_path/" -v tail=":$tag" '{gsub (head, ""); gsub(tail,""); gsub(/\//,"\\/"); print $0}')
144
145
146sed -i "s/^ name: xapp-std/ name: $CHART_NAME/" /tmp/$CHART_NAME/values.yaml
147sed -i "s/^ name: xapp-std/ name: $image/" /tmp/$CHART_NAME/values.yaml
148sed -i "s/^ tag: latest/ tag: $tag/" /tmp/$CHART_NAME/values.yaml
149
150
151if [ -z $registry_path ]; then
152 sed -i "s/^ repository: xapp-std-reg/ repository: $DOCKER_REGISTRY/" /tmp/$CHART_NAME/values.yaml
153else
154 sed -i "s/^ repository: xapp-std-reg/ repository: $registry_path/" /tmp/$CHART_NAME/values.yaml
155fi
156
157
158
159
160cp $CONFIG_JSON_PATH /tmp/$CHART_NAME/config/
161cp $DESCRIPTOR_PATH /tmp/$CHART_NAME/descriptors/
162
163
164helm package -d /tmp /tmp/$CHART_NAME
165
166
167echo $HELM_REPO
168curl -k -u $HELM_REPO_USERNAME:$HELM_REPO_PASSWORD $HELM_REPO --upload-file /tmp/$CHART_NAME-$CHART_VERSION.tgz -v
169
170