X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fdep.git;a=blobdiff_plain;f=bin%2Fdeploy-nonrtric;h=2125ef31b39d4131410f7fd7443b98fbe983710c;hp=fd7b85eedcd08c66af87b8adc82cfb0356674b12;hb=HEAD;hpb=0faae789812e0f84949d26c415e8cb2cce1d94d5 diff --git a/bin/deploy-nonrtric b/bin/deploy-nonrtric index fd7b85ee..2125ef31 100755 --- a/bin/deploy-nonrtric +++ b/bin/deploy-nonrtric @@ -1,6 +1,7 @@ #!/bin/bash ################################################################################ -# Copyright (c) 2020 Nordix Foundation. # +# Copyright (c) 2023 Nordix Foundation. # +# Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved. # # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you may not use this file except in compliance with the License. # @@ -17,6 +18,8 @@ # This script deploys NonRtRic components automatically + + if [ "$#" -eq 1 ]; then OVERRIDEYAML=$1 else @@ -50,34 +53,161 @@ fi ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" -# Start Helm local repo if there isn't one -HELM_REPO_PID=$(ps -x | grep "helm serve" | grep -v "grep" | awk '{print $1}') -if [ -z "$HELM_REPO_PID" ]; then - nohup helm serve >& /dev/null & +echo "** $ROOT_DIR" +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_CHART_POST_URL="$CM_BASE_URL/charts/api/charts" + +#Check for helm3 +IS_HELM3=$(helm version -c --short|grep -e "^v3") + +if ! command -v chartmuseum &> /dev/null +then + pushd /tmp + echo "Installing ChartMuseum binary..." + 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 + echo "ChartMuseum is already installed." fi -# Package nonrtric-common and serve it using Helm local repo -HELM_HOME=$(helm home) -COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common/Chart.yaml | grep version | awk '{print $2}') -helm package -d /tmp $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common -cp /tmp/nonrtric-common-$COMMON_CHART_VERSION.tgz $HELM_HOME/repository/local/ +# Package common templates and serve it using Helm local repo +HELM_LOCAL_REPO="./chartstorage" +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 + 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 & + echo $! > $ROOT_DIR/CM_PID.txt +else + echo "ChartMuseum is already running..." +fi + +# Check if ChartMuseum is ready to serve request +command="curl --silent --output /dev/null $CM_BASE_URL" +for i in $(seq 1 5) +do $command && s=0 && break || s=$? && echo "Failed to establish a connection with the ChartMuseum server. Retrying after 5s" && sleep 5; +done -COMPONENTS=${LIST_OF_COMPONENTS:-"controlpanel a1controller a1simulator policymanagementservice"} -echo "Packaging NONRTRIC components [$COMPONENTS]" +if [ $s -gt 0 ] +then + echo "Cmd to test ChartMuseum failed with ($s): $command" + exit $s +fi + +helm repo remove local +helm repo add local $CM_CHART_GET_URL + +echo -e "\nPackaging NONRTRIC common [nonrtric-common]" +NONRTRIC_COMMON_CHART_VERSION=$(cat $ROOT_DIR/../ric-common/Common-Template/helm/nonrtric-common/Chart.yaml | grep version | awk '{print $2}') +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 + +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 - cp /tmp/$component-$VERSION.tgz $HELM_HOME/repository/local/ + 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 -helm repo index $HELM_HOME/repository/local/ +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} # Make sure that helm local repo is added -helm repo remove local -helm repo add local http://127.0.0.1:8879/charts +helm repo add local $CM_CHART_GET_URL --force-update echo "Finished Packaging NONRTRIC components [$COMPONENTS]" -$ROOT_DIR/../nonrtric/bin/install -f $OVERRIDEYAML + +COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}') +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 + +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 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 + +echo "Deploying NONRTRIC" + +echo "Install Ranpm- $INSTALL_RANPM" + +if [ "$INSTALL_RANPM" = true ];then + echo "Running install-ranpm.sh" + chmod +x ${ROOT_DIR}/../ranpm/install/install-ranpm.sh + ${ROOT_DIR}/../ranpm/install/install-ranpm.sh + echo "install-ranpm.sh completed" +fi + +echo "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"