blob: cdf993e37d0c16014f3bcc65c41ea93fd7c1ebd2 [file] [log] [blame]
Lathish7e090012020-04-01 17:38:20 +01001#!/bin/bash
2################################################################################
3# Copyright (c) 2020 Nordix Foundation. #
4# #
5# Licensed under the Apache License, Version 2.0 (the "License"); #
6# you may not use this file except in compliance with the License. #
7# You may obtain a copy of the License at #
8# #
9# http://www.apache.org/licenses/LICENSE-2.0 #
10# #
11# Unless required by applicable law or agreed to in writing, software #
12# distributed under the License is distributed on an "AS IS" BASIS, #
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14# See the License for the specific language governing permissions and #
15# limitations under the License. #
16################################################################################
17
18# This script deploys NonRtRic components automatically
19
PatrikBuhr866a34f2021-04-12 17:02:21 +020020
21
Lathish7e090012020-04-01 17:38:20 +010022if [ "$#" -eq 1 ]; then
23 OVERRIDEYAML=$1
24else
25
26 while [ -n "$1" ]; do # while loop starts
27
28 case "$1" in
29
30 -f) OVERRIDEYAML=$2
31 shift
BjornMagnussonXA326fd8c2021-12-10 10:13:03 +010032 ;;
Lathish7e090012020-04-01 17:38:20 +010033 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
34
35 esac
36
37 shift
38
39 done
40fi
41
42
43if [ -z "$OVERRIDEYAML" ];then
44 echo "****************************************************************************************************************"
45 echo " ERROR "
46 echo "****************************************************************************************************************"
47 echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
48 echo "****************************************************************************************************************"
49 exit 1
50fi
51
52
53ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
54
PatrikBuhr866a34f2021-04-12 17:02:21 +020055echo "** $ROOT_DIR"
56rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz
57
58
Alok Bhatt2fcd3912020-12-04 10:40:36 +000059#Check for helm3
60IS_HELM3=$(helm version -c --short|grep -e "^v3")
61
62if [ $IS_HELM3 ]
63then
64 # Check for servcm plugin
65 helm plugin list | grep -q "^servecm"
66 if [ $? -eq "1" ]
67 then
68 helm plugin install https://github.com/jdolitsky/helm-servecm
69 fi
70fi
71
Lathish7e090012020-04-01 17:38:20 +010072# Start Helm local repo if there isn't one
73HELM_REPO_PID=$(ps -x | grep "helm serve" | grep -v "grep" | awk '{print $1}')
74if [ -z "$HELM_REPO_PID" ]; then
Alok Bhatt2fcd3912020-12-04 10:40:36 +000075 if [ -z $IS_HELM3 ]
76 then
77 nohup helm serve >& /dev/null &
78 else
79 echo EUID:$EUID
80 if [ $EUID -ne "0" ]
81 then
82 echo "Error: Please run the command with sudo as helm servecm needs to copy a file in location needing privilege"
83 exit;
84 fi
85 eval $(helm env |grep HELM_REPOSITORY_CACHE)
86 echo yes > /tmp/ric-yes
87 nohup sudo sh -c "helm servecm --port=8879 --context-path=/charts --storage local --storage-local-rootdir $HELM_REPOSITORY_CACHE/local/ < /tmp/ric-yes " &
88 fi
Lathish7e090012020-04-01 17:38:20 +010089fi
90
Alok Bhatt2fcd3912020-12-04 10:40:36 +000091
Alok Bhatt2fcd3912020-12-04 10:40:36 +000092# Package common templates and serve it using Helm local repo
93HELM_LOCAL_REPO=""
94if [ $IS_HELM3 ]
95then
96 eval $(helm env |grep HELM_REPOSITORY_CACHE)
97 HELM_LOCAL_REPO="${HELM_REPOSITORY_CACHE}/local/"
98else
99 HELM_HOME=$(helm home)
100 HELM_LOCAL_REPO="${HELM_HOME}/repository/local/"
101fi
Lathish7e090012020-04-01 17:38:20 +0100102
PatrikBuhr866a34f2021-04-12 17:02:21 +0200103
104rm $HELM_LOCAL_REPO/*
105
106helm repo remove local
107$ROOT_DIR/prepare-common-templates
108
ecaiyanlinuxf5c959c2021-12-15 15:06:42 +0100109COMPONENTS="controlpanel a1controller a1simulator policymanagementservice informationservice rappcatalogueservice nonrtricgateway dmaapadapterservice dmaapmediatorservice helmmanager oruclosedlooprecovery odusliceassurance"
Lathish7e090012020-04-01 17:38:20 +0100110for component in $COMPONENTS; do
PatrikBuhr866a34f2021-04-12 17:02:21 +0200111 echo "Packaging NONRTRIC component [$component]"
Lathish7e090012020-04-01 17:38:20 +0100112 helm dep up $ROOT_DIR/../nonrtric/helm/$component
113 VERSION=$(cat $ROOT_DIR/../nonrtric/helm/$component/Chart.yaml | grep version | awk '{print $2}')
114 helm package -d /tmp $ROOT_DIR/../nonrtric/helm/$component
Alok Bhatt2fcd3912020-12-04 10:40:36 +0000115 cp /tmp/$component-$VERSION.tgz ${HELM_LOCAL_REPO}
Lathish7e090012020-04-01 17:38:20 +0100116done
117
PatrikBuhr866a34f2021-04-12 17:02:21 +0200118helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric
119
Alok Bhatt2fcd3912020-12-04 10:40:36 +0000120helm repo index ${HELM_LOCAL_REPO}
Lathish7e090012020-04-01 17:38:20 +0100121
122# Make sure that helm local repo is added
PatrikBuhr866a34f2021-04-12 17:02:21 +0200123helm repo add local http://127.0.0.1:8879/charts --force-update
Lathish7e090012020-04-01 17:38:20 +0100124
125echo "Finished Packaging NONRTRIC components [$COMPONENTS]"
126
PatrikBuhr866a34f2021-04-12 17:02:21 +0200127
PatrikBuhrc5c107d2021-05-26 09:26:09 +0200128
129COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
130NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ .*|^ *$/) {print $0; if (getline == 0) {break}}}')
131NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
132RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
Lathishad832472021-05-26 15:52:08 +0100133INSTALL_KONG=$(cat $OVERRIDEYAML | awk '/^ installKong:/{print $2}')
134echo "Chart name- $PARENT_CHART"
PatrikBuhrc5c107d2021-05-26 09:26:09 +0200135
136if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
137 kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
138fi
139if ! kubectl get ns onap > /dev/null 2>&1; then
140 kubectl create ns onap
141fi
142
Lathishf041cac2021-06-21 12:49:43 +0100143echo "Install Kong- $INSTALL_KONG"
144
145if [ "$INSTALL_KONG" = true ];then
146 echo "Installing Kong"
147 helm repo add kong https://charts.konghq.com --force-update
148 helm repo update
149 helm install kong-nonrtric --namespace ${NONRTRIC_NAMESPACE:-nonrtric} kong/kong --set ingressController.installCRDs=false --set admin.enabled=true
150fi
151
PatrikBuhrc5c107d2021-05-26 09:26:09 +0200152kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
153
154echo "Deploying NONRTRIC"
155
156HELM_NAME_OPT=""
157if [ -z $IS_HELM3 ];then
158 HELM_NAME_OPT="--name"
159fi
160
161echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric"
162helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric"
163
164