NONRTRIC - Selection of which components to include
[it/dep.git] / bin / deploy-nonrtric
1 #!/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
20
21
22 if [ "$#" -eq 1 ]; then
23     OVERRIDEYAML=$1
24 else
25
26     while [ -n "$1" ]; do # while loop starts
27
28         case "$1" in
29
30         -f) OVERRIDEYAML=$2
31             shift
32             ;; 
33         *) 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
40 fi
41
42
43 if [ -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
50 fi
51
52
53 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
54
55 echo "** $ROOT_DIR"
56 rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz
57
58
59 #Check for helm3
60 IS_HELM3=$(helm version -c --short|grep -e "^v3")
61
62 if [ $IS_HELM3 ]
63 then
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
70 fi
71
72 # Start Helm local repo if there isn't one
73 HELM_REPO_PID=$(ps -x | grep  "helm serve" | grep -v "grep" | awk '{print $1}')
74 if [ -z "$HELM_REPO_PID" ]; then
75     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
89 fi
90
91
92 # Package common templates and serve it using Helm local repo
93 HELM_LOCAL_REPO=""
94 if [ $IS_HELM3 ]
95 then
96   eval $(helm env |grep HELM_REPOSITORY_CACHE)
97   HELM_LOCAL_REPO="${HELM_REPOSITORY_CACHE}/local/"
98 else
99   HELM_HOME=$(helm home)
100   HELM_LOCAL_REPO="${HELM_HOME}/repository/local/"
101 fi
102
103
104 rm $HELM_LOCAL_REPO/*
105
106 helm repo remove local
107 $ROOT_DIR/prepare-common-templates
108
109 COMPONENTS="controlpanel a1controller a1simulator policymanagementservice enrichmentservice rappcatalogueservice nonrtricgateway"
110 for component in $COMPONENTS; do
111     echo "Packaging NONRTRIC component [$component]"
112     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
115     cp /tmp/$component-$VERSION.tgz ${HELM_LOCAL_REPO}
116 done
117
118 helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric
119
120 helm repo index ${HELM_LOCAL_REPO}
121
122 # Make sure that helm local repo is added
123 helm repo add local http://127.0.0.1:8879/charts --force-update
124
125 echo "Finished Packaging NONRTRIC components [$COMPONENTS]"
126
127
128
129 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
130 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
131 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
132 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
133
134 if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
135     kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
136 fi
137 if ! kubectl get ns onap > /dev/null 2>&1; then
138     kubectl create ns onap
139 fi
140
141 kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
142
143 echo "Deploying NONRTRIC"
144
145 HELM_NAME_OPT=""
146 if [ -z $IS_HELM3 ];then
147    HELM_NAME_OPT="--name"
148 fi
149
150 echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric"
151 helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric"
152
153