Merge "NONRTRIC-980: Service Manager - SMO deployment"
[it/dep.git] / bin / deploy-nonrtric
index b0f5816..651771b 100755 (executable)
@@ -50,6 +50,39 @@ if [ -z "$OVERRIDEYAML" ];then
     exit 1
 fi
 
     exit 1
 fi
 
+if ! command -v yq > /dev/null 2>&1; then
+    echo "yq is not installed. Installing yq..."
+    sudo snap install yq --channel=v3/stable
+fi
+
+INSTALL_KONG=$(yq read "$OVERRIDEYAML" 'nonrtric.installKong')
+if [ $? -ne 0 ] || [ -z "$INSTALL_KONG"  ]; then
+    echo "Error: failed to parse installKong from YAML with yq. Aborting install."
+    exit 1
+fi
+
+INSTALL_CAPIF=$(yq read "$OVERRIDEYAML" 'nonrtric.installCapifcore')
+if [ $? -ne 0 ] || [ -z "$INSTALL_CAPIF"  ]; then
+    echo "Error: failed to parse installCapifcore from YAML with yq. Aborting install."
+    exit 1
+fi
+
+INSTALL_SERVICEMANAGER=$(yq read "$OVERRIDEYAML" 'nonrtric.installServicemanager')
+if [ $? -ne 0 ] || [ -z "$INSTALL_SERVICEMANAGER"  ]; then
+    echo "Error: failed to parse installServicemanager from YAML with yq. Aborting install."
+    exit 1
+fi
+
+if [ "$INSTALL_SERVICEMANAGER" == "true" ]; then
+    if [ "$INSTALL_KONG" == "false" ]; then
+        echo "Error: INSTALL_KONG must be true if INSTALL_SERVICEMANAGER is true. Aborting install."
+        exit 1
+    fi
+    if [ "$INSTALL_CAPIF" == "false" ]; then
+        echo "Error: INSTALL_CAPIF must be true if INSTALL_SERVICEMANAGER is true. Aborting install."
+        exit 1
+    fi
+fi
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
 
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
 
@@ -57,6 +90,7 @@ echo "** $ROOT_DIR"
 rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz
 
 #ChartMuseum configuration
 rm $ROOT_DIR/../nonrtric/helm/*/charts/*.tgz
 
 #ChartMuseum configuration
+CM_VERSION="v0.16.1"
 CM_PORT="8879"
 CM_BASE_URL="http://127.0.0.1:$CM_PORT"
 CM_CHART_GET_URL="$CM_BASE_URL/charts"
 CM_PORT="8879"
 CM_BASE_URL="http://127.0.0.1:$CM_PORT"
 CM_CHART_GET_URL="$CM_BASE_URL/charts"
@@ -69,8 +103,8 @@ if ! command -v chartmuseum &> /dev/null
 then
   pushd /tmp
   echo "Installing ChartMuseum binary..."
 then
   pushd /tmp
   echo "Installing ChartMuseum binary..."
-  wget https://get.helm.sh/chartmuseum-v0.13.1-linux-amd64.tar.gz
-  tar xvfz chartmuseum-v0.13.1-linux-amd64.tar.gz
+  wget https://get.helm.sh/chartmuseum-$CM_VERSION-linux-amd64.tar.gz
+  tar xvfz chartmuseum-$CM_VERSION-linux-amd64.tar.gz
   sudo mv /tmp/linux-amd64/chartmuseum /usr/local/bin/chartmuseum
   popd
 else
   sudo mv /tmp/linux-amd64/chartmuseum /usr/local/bin/chartmuseum
   popd
 else
@@ -84,8 +118,9 @@ rm $HELM_LOCAL_REPO/*
 #Start Chart Museum server if there isn't one
 CHART_MUSEUM_PID=$(lsof -i :"$CM_PORT" | grep "chartmus" | grep -v "grep" | awk '{print $2}')
 if [ -z "$CHART_MUSEUM_PID" ]; then
 #Start Chart Museum server if there isn't one
 CHART_MUSEUM_PID=$(lsof -i :"$CM_PORT" | grep "chartmus" | grep -v "grep" | awk '{print $2}')
 if [ -z "$CHART_MUSEUM_PID" ]; then
-  echo "Starting ChartMuseum  on port $CM_PORT..."
+  echo "Starting ChartMuseum on port $CM_PORT..."
   nohup chartmuseum --port=$CM_PORT --storage="local" --context-path=/charts --storage-local-rootdir=$HELM_LOCAL_REPO >/dev/null 2>&1 &
   nohup chartmuseum --port=$CM_PORT --storage="local" --context-path=/charts --storage-local-rootdir=$HELM_LOCAL_REPO >/dev/null 2>&1 &
+  echo $! > $ROOT_DIR/CM_PID.txt
 else
   echo "ChartMuseum is already running..."
 fi
 else
   echo "ChartMuseum is already running..."
 fi
@@ -110,15 +145,48 @@ NONRTRIC_COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm
 helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common
 curl --data-binary @/tmp/nonrtric-common-$NONRTRIC_COMMON_CHART_VERSION.tgz $CM_CHART_POST_URL
 
 helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common
 curl --data-binary @/tmp/nonrtric-common-$NONRTRIC_COMMON_CHART_VERSION.tgz $CM_CHART_POST_URL
 
-COMPONENTS="controlpanel a1controller a1simulator policymanagementservice informationservice rappcatalogueservice rappcatalogueenhancedservice nonrtricgateway dmaapadapterservice dmaapmediatorservice helmmanager orufhrecovery ransliceassurance capifcore rappmanager dmeparticipant"
+charts_already_exists=()
+
+COMPONENTS="
+a1controller \
+a1simulator \
+capifcore \
+controlpanel \
+dmaapadapterservice \
+dmaapmediatorservice \
+dmeparticipant \
+helmmanager \
+informationservice \
+nonrtricgateway \
+orufhrecovery \
+policymanagementservice \
+ransliceassurance \
+rappcatalogueenhancedservice \
+rappcatalogueservice \
+rappmanager \
+servicemanager \
+"
+
 for component in $COMPONENTS; do
     echo "Packaging NONRTRIC component [$component]"
     helm dep up $ROOT_DIR/../nonrtric/helm/$component
     VERSION=$(cat $ROOT_DIR/../nonrtric/helm/$component/Chart.yaml | grep version | awk '{print $2}')
     helm package -d /tmp $ROOT_DIR/../nonrtric/helm/$component
 for component in $COMPONENTS; do
     echo "Packaging NONRTRIC component [$component]"
     helm dep up $ROOT_DIR/../nonrtric/helm/$component
     VERSION=$(cat $ROOT_DIR/../nonrtric/helm/$component/Chart.yaml | grep version | awk '{print $2}')
     helm package -d /tmp $ROOT_DIR/../nonrtric/helm/$component
-    curl --data-binary @/tmp/$component-$VERSION.tgz $CM_CHART_POST_URL
+    resp_code=$(curl -s -o /dev/null -w "%{http_code}" --data-binary @/tmp/$component-$VERSION.tgz $CM_CHART_POST_URL)
+    echo "Chart upload status of $component is $resp_code"
+    if [ "$resp_code" -eq 409 ]; then
+      charts_already_exists+=("$component")
+    fi
 done
 
 done
 
+if [ ${#charts_already_exists[@]} -gt 0 ]; then
+  echo "----------------------------------- WARNING!!! -------------------------------------------"
+  echo "The following charts already exists in ChartMuseum '${charts_already_exists[@]}'."
+  echo "The current build of the charts hasn't been updated because the charts already exist."
+  echo "It is recommended to delete the charts from ChartMuseum before the build."
+  echo "------------------------------------------------------------------------------------------"
+fi
+
 helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric
 
 helm repo index ${HELM_LOCAL_REPO}
 helm dep up $ROOT_DIR/../nonrtric/helm/nonrtric
 
 helm repo index ${HELM_LOCAL_REPO}
@@ -133,23 +201,31 @@ COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^
 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
-INSTALL_KONG=$(cat $OVERRIDEYAML | awk '/^  installKong:/{print $2}')
 INSTALL_RANPM=$(cat $OVERRIDEYAML | awk '/^  installRanpm:/{print $2}')
 
 if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
     kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
 fi
 INSTALL_RANPM=$(cat $OVERRIDEYAML | awk '/^  installRanpm:/{print $2}')
 
 if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
     kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
 fi
+
 if ! kubectl get ns onap > /dev/null 2>&1; then
     kubectl create ns onap
 fi
 
 if ! kubectl get ns onap > /dev/null 2>&1; then
     kubectl create ns onap
 fi
 
+HELM_NAME_OPT=""
+if [ -z $IS_HELM3 ];then
+   HELM_NAME_OPT="--name"
+fi
+
 echo "Install Kong- $INSTALL_KONG"
 
 if [ "$INSTALL_KONG" = true ];then
 echo "Install Kong- $INSTALL_KONG"
 
 if [ "$INSTALL_KONG" = true ];then
-   echo "Installing Kong"
-   helm repo add kong https://charts.konghq.com --force-update
-   helm repo update
-   helm install kong-nonrtric --namespace ${NONRTRIC_NAMESPACE:-nonrtric} kong/kong --set ingressController.installCRDs=false --set admin.enabled=true
+  echo "Install kongstorage through helm"
+  helm install kongstorage -n "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT}  "$ROOT_DIR/../nonrtric/helm/kongstorage"
+
+  echo "Installing Kong"
+  helm repo add kong https://charts.konghq.com --force-update
+  helm repo update
+  helm install kong-nonrtric kong/kong -n ${NONRTRIC_NAMESPACE:-nonrtric} -f dep/nonrtric/helm/kongstorage/kongvalues.yaml
 fi
 
 kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
 fi
 
 kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
@@ -165,10 +241,5 @@ if [ "$INSTALL_RANPM" = true ];then
    echo "install-ranpm.sh completed"
 fi
 
    echo "install-ranpm.sh completed"
 fi
 
-HELM_NAME_OPT=""
-if [ -z $IS_HELM3 ];then
-   HELM_NAME_OPT="--name"
-fi
-
 echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric"
 echo "helm install -f $OVERRIDEYAML --namespace ${NONRTRIC_NAMESPACE:-nonrtric} ${HELM_NAME_OPT} ${RELEASE_PREFIX} $ROOT_DIR/../nonrtric/helm/nonrtric"
-helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric"
+helm install -f $OVERRIDEYAML -n "${NONRTRIC_NAMESPACE:-nonrtric}" ${HELM_NAME_OPT} "${RELEASE_PREFIX}" "$ROOT_DIR/../nonrtric/helm/nonrtric"