blob: 818181d9c53c9884c83d1eeddecb3c7cee834511 [file] [log] [blame]
Michael Lando451a3402017-02-19 10:28:42 +02001#!/bin/bash
2
3
Grinberg Motic3bda482017-02-23 11:24:34 +02004function usage {
Idan Amitdb3d5542017-12-07 11:33:32 +02005 echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -t|--runTests <Run-with-sanityDocker>] [ -h|--help ]"
Michael Lando451a3402017-02-19 10:28:42 +02006}
7
8
Grinberg Motic3bda482017-02-23 11:24:34 +02009function cleanup {
Idan Amitdb3d5542017-12-07 11:33:32 +020010 echo "performing old dockers cleanup"
11 docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
12 for X in ${docker_ids}
13 do
14 docker rm -f ${X}
15 done
Grinberg Motic3bda482017-02-23 11:24:34 +020016}
17
18
19function dir_perms {
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +020020 mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
21 mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
22 chmod -R 777 ${WORKSPACE}/data/logs
Grinberg Motic3bda482017-02-23 11:24:34 +020023}
24
Yuli Shlosberg5571a862017-10-03 18:18:51 +030025function monitor_docker {
26
Idan Amitdb3d5542017-12-07 11:33:32 +020027 echo monitor $1 Docker
28 sleep 5
29 TIME_OUT=900
30 INTERVAL=20
31 TIME=0
32 while [ "$TIME" -lt "$TIME_OUT" ]; do
Yuli Shlosberg5571a862017-10-03 18:18:51 +030033
Idan Amitdb3d5542017-12-07 11:33:32 +020034 MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
35 echo MATCH is -- $MATCH
Yuli Shlosberg5571a862017-10-03 18:18:51 +030036
Idan Amitdb3d5542017-12-07 11:33:32 +020037 if [ -n "$MATCH" ]; then
38 echo DOCKER start finished in $TIME seconds
39 break
40 fi
Yuli Shlosberg5571a862017-10-03 18:18:51 +030041
Idan Amitdb3d5542017-12-07 11:33:32 +020042 echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
43 sleep $INTERVAL
44 TIME=$(($TIME+$INTERVAL))
45 done
Yuli Shlosberg5571a862017-10-03 18:18:51 +030046
Idan Amitdb3d5542017-12-07 11:33:32 +020047 if [ "$TIME" -ge "$TIME_OUT" ]; then
48 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
49 fi
Yuli Shlosberg5571a862017-10-03 18:18:51 +030050
51}
52
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +020053function healthCheck {
54 curl localhost:9200/_cluster/health?pretty=true
55
56 echo "BE health-Check:"
57 curl http://localhost:8080/sdc2/rest/healthCheck
58
59 echo ""
60 echo ""
61 echo "FE health-Check:"
62 curl http://localhost:8181/sdc1/rest/healthCheck
63
64
65 echo ""
66 echo ""
67 healthCheck_http_code=$(curl -o out.html -w '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8080/sdc2/rest/v1/user/demo;)
68 if [[ ${healthCheck_http_code} != 200 ]]
69 then
70 echo "Error [${healthCheck_http_code}] while user existance check"
71 return ${healthCheck_http_code}
72 fi
73 echo "check user existance: OK"
74 return ${healthCheck_http_code}
75}
76
Grinberg Moti97246212017-02-21 19:30:31 +020077RELEASE=latest
Idan Amitc7f57ec2017-08-31 14:26:21 +030078LOCAL=false
Yuli Shlosberg0566f582017-11-26 19:05:23 +020079RUNTESTS=false
Tal Gitelman8e5fc512017-10-23 13:49:06 +030080DEBUG_PORT="--publish 4000:4000"
Tal Gitelmane224d0b2017-10-17 15:24:25 +030081
Idan Amitdb3d5542017-12-07 11:33:32 +020082while [ $# -gt 0 ]; do
Michael Lando451a3402017-02-19 10:28:42 +020083 case $1 in
Idan Amitdb3d5542017-12-07 11:33:32 +020084 # -r | --release - The specific docker version to pull and deploy
Yuli Shlosberg0566f582017-11-26 19:05:23 +020085 -r | --release )
86 shift 1 ;
87 RELEASE=$1;
88 shift 1;;
Idan Amitdb3d5542017-12-07 11:33:32 +020089 # -e | --environment - The environment name you want to deploy
Yuli Shlosberg0566f582017-11-26 19:05:23 +020090 -e | --environment )
91 shift 1;
92 DEP_ENV=$1;
93 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +020094 # -p | --port - The port from which to connect to the docker nexus
Yuli Shlosberg0566f582017-11-26 19:05:23 +020095 -p | --port )
96 shift 1 ;
97 PORT=$1;
98 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +020099 # -l | --local - Use this for deploying your local dockers without pulling them first
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200100 -l | --local )
101 LOCAL=true;
102 shift 1;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200103 # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200104 -t | --runTests )
105 RUNTESTS=true;
106 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200107 # -h | --help - Display the help message with all the available run options
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200108 -h | --help )
109 usage;
110 exit 0;;
111 * )
112 usage;
113 exit 1;;
Michael Lando451a3402017-02-19 10:28:42 +0200114 esac
Michael Lando451a3402017-02-19 10:28:42 +0200115done
116
Yuli Shlosberg3301bec2017-11-08 15:31:27 +0200117
Yuli Shlosberg316bb252017-11-14 11:47:17 +0200118[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
119[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
120[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
121[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
Michael Lando451a3402017-02-19 10:28:42 +0200122[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
123
124
Grinberg Motic3bda482017-02-23 11:24:34 +0200125cleanup
126
Michael Lando451a3402017-02-19 10:28:42 +0200127
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200128export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
Idan Amitdb3d5542017-12-07 11:33:32 +0200129export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
Idan Amitc7f57ec2017-08-31 14:26:21 +0300130
131if [ ${LOCAL} = true ]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200132 PREFIX='onap'
Idan Amitc7f57ec2017-08-31 14:26:21 +0300133fi
Michael Lando451a3402017-02-19 10:28:42 +0200134
135echo ""
136
137# Elastic-Search
138echo "docker run sdc-elasticsearch..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300139if [ ${LOCAL} = false ]; then
140 echo "pulling code"
141 docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
142fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200143docker run --detach --name sdc-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --memory 750m -e ES_JAVA_OPTS="-Xms512m -Xmx512m" --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro -e ES_HEAP_SIZE=1024M --volume ${WORKSPACE}/data/ES:/usr/share/elasticsearch/data --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9200:9200 --publish 9300:9300 ${PREFIX}/sdc-elasticsearch:${RELEASE}
144
Idan Amitc7f57ec2017-08-31 14:26:21 +0300145
146# cassandra
147echo "docker run sdc-cassandra..."
148if [ ${LOCAL} = false ]; then
149 docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
150fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200151docker run --detach --name sdc-cs --env RELEASE="${RELEASE}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/CS:/var/lib/cassandra --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9042:9042 --publish 9160:9160 ${PREFIX}/sdc-cassandra:${RELEASE}
152
Michael Lando451a3402017-02-19 10:28:42 +0200153
154echo "please wait while CS is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300155monitor_docker sdc-cs
Michael Lando451a3402017-02-19 10:28:42 +0200156
Michael Lando451a3402017-02-19 10:28:42 +0200157# kibana
158echo "docker run sdc-kibana..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300159if [ ${LOCAL} = false ]; then
160 docker pull ${PREFIX}/sdc-kibana:${RELEASE}
161fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200162docker run --detach --name sdc-kbn --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 5601:5601 ${PREFIX}/sdc-kibana:${RELEASE}
163
164
Michael Lando451a3402017-02-19 10:28:42 +0200165
Grinberg Motic3bda482017-02-23 11:24:34 +0200166dir_perms
Michael Lando451a3402017-02-19 10:28:42 +0200167
168# Back-End
169echo "docker run sdc-backend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300170if [ ${LOCAL} = false ]; then
171 docker pull ${PREFIX}/sdc-backend:${RELEASE}
Tal Gitelmane224d0b2017-10-17 15:24:25 +0300172else
Tal Gitelman8e5fc512017-10-23 13:49:06 +0300173 ADDITIONAL_ARGUMENTS=${DEBUG_PORT}
Idan Amitc7f57ec2017-08-31 14:26:21 +0300174fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200175docker run --detach --name sdc-BE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 4g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/BE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 8443:8443 --publish 8080:8080 ${ADDITIONAL_ARGUMENTS} ${PREFIX}/sdc-backend:${RELEASE}
176
177
Michael Lando451a3402017-02-19 10:28:42 +0200178
179echo "please wait while BE is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300180monitor_docker sdc-BE
Michael Lando451a3402017-02-19 10:28:42 +0200181
182
183# Front-End
184echo "docker run sdc-frontend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300185if [ ${LOCAL} = false ]; then
186 docker pull ${PREFIX}/sdc-frontend:${RELEASE}
187fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200188docker run --detach --name sdc-FE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/FE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9443:9443 --publish 8181:8181 ${PREFIX}/sdc-frontend:${RELEASE}
Michael Lando451a3402017-02-19 10:28:42 +0200189
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200190
191
192echo "please wait while FE is starting....."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300193monitor_docker sdc-FE
194
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200195# healthCheck
196healthCheck
Michael Lando451a3402017-02-19 10:28:42 +0200197
ml636r0649e652017-02-20 21:10:54 +0200198
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300199# sanityDocker
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200200if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200201 echo "docker run sdc-sanity..."
202 echo "Triger sanity docker, please wait..."
203
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300204 if [ ${LOCAL} = false ]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200205 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300206 fi
Yuli Shlosberg316bb252017-11-14 11:47:17 +0200207
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200208docker run --detach --name sdc-sanity --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 1500m --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/sdc-sanity/target:/var/lib/tests/target --volume ${WORKSPACE}/data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume ${WORKSPACE}/data/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
209echo "please wait while SANITY is starting....."
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200210monitor_docker sdc-sanity
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200211
Yuli Shlosberg316bb252017-11-14 11:47:17 +0200212fi