2 ################################################################################
3 # Copyright (c) 2023 Nordix Foundation. #
4 # Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved. #
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 ################################################################################
19 # This script deploys NonRtRic components automatically
23 if [ "$#" -eq 1 ]; then
27 while [ -n "$1" ]; do # while loop starts
34 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
44 if [ -z "$OVERRIDEYAML" ];then
45 echo "****************************************************************************************************************"
47 echo "****************************************************************************************************************"
48 echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
49 echo "****************************************************************************************************************"
53 if ! command -v yq > /dev/null 2>&1; then
54 echo "yq is not installed. Installing yq..."
55 sudo snap install yq --channel=v3/stable
58 INSTALL_KONG=$(yq read "$OVERRIDEYAML" 'nonrtric.installKong')
59 if [ $? -ne 0 ] || [ -z "$INSTALL_KONG" ]; then
60 echo "Error: failed to parse installKong from YAML with yq. Aborting install."
64 INSTALL_CAPIF=$(yq read "$OVERRIDEYAML" 'nonrtric.installCapifcore')
65 if [ $? -ne 0 ] || [ -z "$INSTALL_CAPIF" ]; then
66 echo "Error: failed to parse installCapifcore from YAML with yq. Aborting install."
70 INSTALL_SERVICEMANAGER=$(yq read "$OVERRIDEYAML" 'nonrtric.installServicemanager')
71 if [ $? -ne 0 ] || [ -z "$INSTALL_SERVICEMANAGER" ]; then
72 echo "Error: failed to parse installServicemanager from YAML with yq. Aborting install."
76 if [ "$INSTALL_SERVICEMANAGER" == "true" ]; then
77 if [ "$INSTALL_KONG" == "false" ]; then
78 echo "Error: INSTALL_KONG must be true if INSTALL_SERVICEMANAGER is true. Aborting install."
81 if [ "$INSTALL_CAPIF" == "false" ]; then
82 echo "Error: INSTALL_CAPIF must be true if INSTALL_SERVICEMANAGER is true. Aborting install."
87 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
90 rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz
92 #ChartMuseum configuration
95 CM_BASE_URL="http://127.0.0.1:$CM_PORT"
96 CM_CHART_GET_URL="$CM_BASE_URL/charts"
97 CM_CHART_POST_URL="$CM_BASE_URL/charts/api/charts"
100 IS_HELM3=$(helm version -c --short|grep -e "^v3")
102 if ! command -v chartmuseum &> /dev/null
105 echo "Installing ChartMuseum binary..."
106 wget https://get.helm.sh/chartmuseum-$CM_VERSION-linux-amd64.tar.gz
107 tar xvfz chartmuseum-$CM_VERSION-linux-amd64.tar.gz
108 sudo mv /tmp/linux-amd64/chartmuseum /usr/local/bin/chartmuseum
111 echo "ChartMuseum is already installed."
114 # Package common templates and serve it using Helm local repo
115 HELM_LOCAL_REPO="./chartstorage"
116 rm $HELM_LOCAL_REPO/*
118 #Start Chart Museum server if there isn't one
119 CHART_MUSEUM_PID=$(lsof -i :"$CM_PORT" | grep "chartmus" | grep -v "grep" | awk '{print $2}')
120 if [ -z "$CHART_MUSEUM_PID" ]; then
121 echo "Starting ChartMuseum on port $CM_PORT..."
122 nohup chartmuseum --port=$CM_PORT --storage="local" --context-path=/charts --storage-local-rootdir=$HELM_LOCAL_REPO >/dev/null 2>&1 &
123 echo $! > $ROOT_DIR/CM_PID.txt
125 echo "ChartMuseum is already running..."
128 # Check if ChartMuseum is ready to serve request
129 command="curl --silent --output /dev/null $CM_BASE_URL"
131 do $command && s=0 && break || s=$? && echo "Failed to establish a connection with the ChartMuseum server. Retrying after 5s" && sleep 5;
136 echo "Cmd to test ChartMuseum failed with ($s): $command"
140 helm repo remove local
141 helm repo add local $CM_CHART_GET_URL
143 echo -e "\nPackaging NONRTRIC common [nonrtric-common]"
144 NONRTRIC_COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common/Chart.yaml | grep version | awk '{print $2}')
145 helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common
146 curl --data-binary @/tmp/nonrtric-common-$NONRTRIC_COMMON_CHART_VERSION.tgz $CM_CHART_POST_URL
148 charts_already_exists=()
155 dmaapadapterservice \
156 dmaapmediatorservice \
162 policymanagementservice \
164 rappcatalogueenhancedservice \
165 rappcatalogueservice \
170 for component in $COMPONENTS; do
171 echo "Packaging NONRTRIC component [$component]"
172 helm dep up $ROOT_DIR/../nonrtric/helm/$component
173 VERSION=$(cat $ROOT_DIR/../nonrtric/helm/$component/Chart.yaml | grep version | awk '{print $2}')
174 helm package -d /tmp $ROOT_DIR/../nonrtric/helm/$component
175 resp_code=$(curl -s -o /dev/null -w "%{http_code}" --data-binary @/tmp/$component-$VERSION.tgz $CM_CHART_POST_URL)
176 echo "Chart upload status of $component is $resp_code"
177 if [ "$resp_code" -eq 409 ]; then
178 charts_already_exists+=("$component")
182 if [ ${#charts_already_exists[@]} -gt 0 ]; then
183 echo "----------------------------------- WARNING!!! -------------------------------------------"
184 echo "The following charts already exists in ChartMuseum '${charts_already_exists[@]}'."
185 echo "The current build of the charts hasn't been updated because the charts already exist."
186 echo "It is recommended to delete the charts from ChartMuseum before the build."
187 echo "------------------------------------------------------------------------------------------"
190 helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric
192 helm repo index ${HELM_LOCAL_REPO}
194 # Make sure that helm local repo is added
195 helm repo add local $CM_CHART_GET_URL --force-update
197 echo "Finished Packaging NONRTRIC components [$COMPONENTS]"
200 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
201 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ .*|^ *$/) {print $0; if (getline == 0) {break}}}')
202 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
203 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
204 INSTALL_RANPM=$(cat $OVERRIDEYAML | awk '/^ installRanpm:/{print $2}')
206 if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
207 kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
210 if ! kubectl get ns onap > /dev/null 2>&1; then
211 kubectl create ns onap
215 if [ -z $IS_HELM3 ];then
216 HELM_NAME_OPT="--name"
219 echo "Install Kong- $INSTALL_KONG"
221 if [ "$INSTALL_KONG" = true ];then
222 echo "Install kongstorage through helm"
223 helm install kongstorage -n "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "$ROOT_DIR/../nonrtric/helm/kongstorage"
225 echo "Installing Kong"
226 helm repo add kong https://charts.konghq.com --force-update
228 helm install oran-nonrtric kong/kong -n ${NONRTRIC_NAMESPACE:-nonrtric} -f dep/nonrtric/helm/kongstorage/kongvalues.yaml
231 kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
233 echo "Deploying NONRTRIC"
235 echo "Install Ranpm- $INSTALL_RANPM"
237 if [ "$INSTALL_RANPM" = true ];then
238 echo "Running install-ranpm.sh"
239 chmod +x ${ROOT_DIR}/../ranpm/install/install-ranpm.sh
240 ${ROOT_DIR}/../ranpm/install/install-ranpm.sh
241 echo "install-ranpm.sh completed"
244 echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric"
245 helm install -f $OVERRIDEYAML -n "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric"