Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 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 | |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 20 | |
| 21 | |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 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 |
BjornMagnussonXA | 326fd8c | 2021-12-10 10:13:03 +0100 | [diff] [blame] | 32 | ;; |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 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 | |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 55 | echo "** $ROOT_DIR" |
| 56 | rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz |
| 57 | |
| 58 | |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 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 | |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 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 |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 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 |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 89 | fi |
| 90 | |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 91 | |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 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 |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 102 | |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 103 | |
| 104 | rm $HELM_LOCAL_REPO/* |
| 105 | |
| 106 | helm repo remove local |
| 107 | $ROOT_DIR/prepare-common-templates |
| 108 | |
ecaiyanlinux | f5c959c | 2021-12-15 15:06:42 +0100 | [diff] [blame^] | 109 | COMPONENTS="controlpanel a1controller a1simulator policymanagementservice informationservice rappcatalogueservice nonrtricgateway dmaapadapterservice dmaapmediatorservice helmmanager oruclosedlooprecovery odusliceassurance" |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 110 | for component in $COMPONENTS; do |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 111 | echo "Packaging NONRTRIC component [$component]" |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 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 |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 115 | cp /tmp/$component-$VERSION.tgz ${HELM_LOCAL_REPO} |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 116 | done |
| 117 | |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 118 | helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric |
| 119 | |
Alok Bhatt | 2fcd391 | 2020-12-04 10:40:36 +0000 | [diff] [blame] | 120 | helm repo index ${HELM_LOCAL_REPO} |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 121 | |
| 122 | # Make sure that helm local repo is added |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 123 | helm repo add local http://127.0.0.1:8879/charts --force-update |
Lathish | 7e09001 | 2020-04-01 17:38:20 +0100 | [diff] [blame] | 124 | |
| 125 | echo "Finished Packaging NONRTRIC components [$COMPONENTS]" |
| 126 | |
PatrikBuhr | 866a34f | 2021-04-12 17:02:21 +0200 | [diff] [blame] | 127 | |
PatrikBuhr | c5c107d | 2021-05-26 09:26:09 +0200 | [diff] [blame] | 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}') |
Lathish | ad83247 | 2021-05-26 15:52:08 +0100 | [diff] [blame] | 133 | INSTALL_KONG=$(cat $OVERRIDEYAML | awk '/^ installKong:/{print $2}') |
| 134 | echo "Chart name- $PARENT_CHART" |
PatrikBuhr | c5c107d | 2021-05-26 09:26:09 +0200 | [diff] [blame] | 135 | |
| 136 | if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then |
| 137 | kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric} |
| 138 | fi |
| 139 | if ! kubectl get ns onap > /dev/null 2>&1; then |
| 140 | kubectl create ns onap |
| 141 | fi |
| 142 | |
Lathish | f041cac | 2021-06-21 12:49:43 +0100 | [diff] [blame] | 143 | echo "Install Kong- $INSTALL_KONG" |
| 144 | |
| 145 | if [ "$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 |
| 150 | fi |
| 151 | |
PatrikBuhr | c5c107d | 2021-05-26 09:26:09 +0200 | [diff] [blame] | 152 | kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML |
| 153 | |
| 154 | echo "Deploying NONRTRIC" |
| 155 | |
| 156 | HELM_NAME_OPT="" |
| 157 | if [ -z $IS_HELM3 ];then |
| 158 | HELM_NAME_OPT="--name" |
| 159 | fi |
| 160 | |
| 161 | echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric" |
| 162 | helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric" |
| 163 | |
| 164 | |