-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup-sample-xapp.sh
executable file
·71 lines (55 loc) · 2.1 KB
/
setup-sample-xapp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# call as setup-sample-xapp.sh gnb_id
set -x
IMAGE_NAME=sample-xapp
MODEL_DIR=sample-xapp
CONNECTOR_DIR=xapp-sm-connector
DOCKER_FILE=Dockerfile
SETUP_DIR=../setup
export SRC=`dirname $0`
cd $SRC
. $SRC/setup-lib.sh
ENTRYPOINT=/bin/bash
GNB_ID=$1
# if changing xApp IP or ID, you need to define new RMR routes
# in the setup-ric.sh/setup-lib.sh scripts and restart the RIC
XAPP_IP=$XAPP_IP
XAPP_ID=$(echo $XAPP_IP | cut -d "." -f 4)
CONTAINER_NAME=${IMAGE_NAME}-${XAPP_ID}
# Build docker image
$SUDO docker image inspect ${IMAGE_NAME}:latest >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
tagvers=`git log --pretty=format:"%h" -n 1`
$SUDO docker image inspect ${IMAGE_NAME}:$tagvers >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
# copy Dockerfile out
cd ${SETUP_DIR}
cp ${MODEL_DIR}/${DOCKER_FILE} ./${DOCKER_FILE}_${IMAGE_NAME}
$SUDO docker build \
--build-arg DBAAS_SERVICE_HOST=$DBAAS_IP \
--build-arg DBAAS_SERVICE_PORT=$DBAAS_PORT \
-f ${DOCKER_FILE}_${IMAGE_NAME} -t ${IMAGE_NAME}:$tagvers .
# remove copied Dockerfile
rm ${DOCKER_FILE}_${IMAGE_NAME}
fi
$SUDO docker tag ${IMAGE_NAME}:$tagvers ${IMAGE_NAME}:latest
$SUDO docker rmi ${IMAGE_NAME}:$tagvers
fi
remove_container() {
$SUDO docker inspect $1 >/dev/null 2>&1
if [ $? -eq 0 ]; then
$SUDO docker kill $1
$SUDO docker rm $1
fi
}
# run containers
remove_container ${CONTAINER_NAME}
# replace parameters, recompile code and restart container
$SUDO docker run -d -it --entrypoint ${ENTRYPOINT} --network ric --ip ${XAPP_IP} \
-e DBAAS_SERVICE_HOST=$DBAAS_IP -e DBAAS_SERVICE_PORT=$DBAAS_PORT --name ${CONTAINER_NAME} ${IMAGE_NAME}:latest
if [ -n "${GNB_ID}" ]; then
docker exec ${CONTAINER_NAME} sed -i "s/^export GNB_ID.*/export GNB_ID=${GNB_ID}/g" /home/xapp-sm-connector/build_xapp.sh
fi
docker exec ${CONTAINER_NAME} sed -i "s/^export XAPP_ID.*/export XAPP_ID=${XAPP_ID}/g" /home/xapp-sm-connector/build_xapp.sh
docker exec ${CONTAINER_NAME} /home/xapp-sm-connector/build_xapp.sh clean
docker container restart ${CONTAINER_NAME}