blob: 5307a9cd7aa472e49119ac53753f9e5d46c11828 [file] [log] [blame]
Michael Lando451a3402017-02-19 10:28:42 +02001#!/bin/bash
2
Yuli Shlosberg0875ce02018-01-25 13:53:36 +02003CS_PASSWORD="onap123#@!"
4SDC_USER="asdc_user"
5SDC_PASSWORD="Aa1234%^!"
Michael Lando451a3402017-02-19 10:28:42 +02006
Grinberg Motic3bda482017-02-23 11:24:34 +02007function usage {
Idan Amitdb3d5542017-12-07 11:33:32 +02008 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 +02009}
10
11
Grinberg Motic3bda482017-02-23 11:24:34 +020012function cleanup {
Idan Amitdb3d5542017-12-07 11:33:32 +020013 echo "performing old dockers cleanup"
14 docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
15 for X in ${docker_ids}
16 do
17 docker rm -f ${X}
18 done
Grinberg Motic3bda482017-02-23 11:24:34 +020019}
20
21
22function dir_perms {
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +020023 mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
24 mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
25 chmod -R 777 ${WORKSPACE}/data/logs
Grinberg Motic3bda482017-02-23 11:24:34 +020026}
Yuli Shlosberg0875ce02018-01-25 13:53:36 +020027function probe_cs {
Grinberg Motic3bda482017-02-23 11:24:34 +020028
Yuli Shlosberg0875ce02018-01-25 13:53:36 +020029cs_stat=false
30docker exec -it $1 /var/lib/ready-probe.sh > /dev/null 2>&1
31rc=$?
32if [[ $rc == 0 ]]; then
33 echo DOCKER start finished in $2 seconds
34 cs_stat=true
35fi
36
37}
38
39function probe_docker {
40
41match_result=false
42MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
43echo MATCH is -- $MATCH
44
45if [ -n "$MATCH" ]; then
46 echo DOCKER start finished in $2 seconds
47 match_result=true
48fi
49}
Yuli Shlosberg5571a862017-10-03 18:18:51 +030050function monitor_docker {
51
Idan Amitdb3d5542017-12-07 11:33:32 +020052 echo monitor $1 Docker
53 sleep 5
54 TIME_OUT=900
55 INTERVAL=20
56 TIME=0
57 while [ "$TIME" -lt "$TIME_OUT" ]; do
Yuli Shlosberg0875ce02018-01-25 13:53:36 +020058 if [ "$1" == "sdc-cs" ]; then
59 probe_cs $1 $TIME
60 if [[ $cs_stat == true ]]; then break; fi
61 else
62 probe_docker $1 $TIME
63 if [[ $match_result == true ]]; then break; fi
Idan Amitdb3d5542017-12-07 11:33:32 +020064 fi
Idan Amitdb3d5542017-12-07 11:33:32 +020065 echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
66 sleep $INTERVAL
67 TIME=$(($TIME+$INTERVAL))
68 done
Yuli Shlosberg5571a862017-10-03 18:18:51 +030069
Idan Amitdb3d5542017-12-07 11:33:32 +020070 if [ "$TIME" -ge "$TIME_OUT" ]; then
71 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
72 fi
Yuli Shlosberg5571a862017-10-03 18:18:51 +030073
74}
75
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +020076function healthCheck {
77 curl localhost:9200/_cluster/health?pretty=true
78
79 echo "BE health-Check:"
80 curl http://localhost:8080/sdc2/rest/healthCheck
81
82 echo ""
83 echo ""
84 echo "FE health-Check:"
85 curl http://localhost:8181/sdc1/rest/healthCheck
86
87
88 echo ""
89 echo ""
Tal Gitelmanf1927592018-01-29 17:24:56 +020090 healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8080/sdc2/rest/v1/user/demo;)
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +020091 if [[ ${healthCheck_http_code} != 200 ]]
92 then
93 echo "Error [${healthCheck_http_code}] while user existance check"
94 return ${healthCheck_http_code}
95 fi
96 echo "check user existance: OK"
97 return ${healthCheck_http_code}
98}
99
Tal Gitelmanf1927592018-01-29 17:24:56 +0200100function elasticHealthCheck {
101 echo "Elastic Health-Check:"
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200102
Tal Gitelmanf1927592018-01-29 17:24:56 +0200103 COUNTER=0
104 while [ $COUNTER -lt 20 ]; do
105 echo "Waiting ES docker to start"
106 health_Check_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
107 if [[ "$health_Check_http_code" -eq 200 ]]
108 then
109 break
110 fi
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200111 let COUNTER=COUNTER+1
Tal Gitelmanf1927592018-01-29 17:24:56 +0200112 sleep 4
113 done
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200114
Tal Gitelmanf1927592018-01-29 17:24:56 +0200115 healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
116 if [[ "$health_Check_http_code" != 200 ]]
117 then
118 echo "Error [${healthCheck_http_code}] ES NOT started correctly"
119 exit ${healthCheck_http_code}
120 fi
121 echo "ES started correctly"
122 curl localhost:9200/_cluster/health?pretty=true
123 return ${healthCheck_http_code}
124}
125
Grinberg Moti97246212017-02-21 19:30:31 +0200126RELEASE=latest
Idan Amitc7f57ec2017-08-31 14:26:21 +0300127LOCAL=false
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200128RUNTESTS=false
Tal Gitelman8e5fc512017-10-23 13:49:06 +0300129DEBUG_PORT="--publish 4000:4000"
Tal Gitelmane224d0b2017-10-17 15:24:25 +0300130
Idan Amitdb3d5542017-12-07 11:33:32 +0200131while [ $# -gt 0 ]; do
Michael Lando451a3402017-02-19 10:28:42 +0200132 case $1 in
Idan Amitdb3d5542017-12-07 11:33:32 +0200133 # -r | --release - The specific docker version to pull and deploy
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200134 -r | --release )
135 shift 1 ;
136 RELEASE=$1;
137 shift 1;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200138 # -e | --environment - The environment name you want to deploy
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200139 -e | --environment )
140 shift 1;
141 DEP_ENV=$1;
142 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200143 # -p | --port - The port from which to connect to the docker nexus
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200144 -p | --port )
145 shift 1 ;
146 PORT=$1;
147 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200148 # -l | --local - Use this for deploying your local dockers without pulling them first
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200149 -l | --local )
150 LOCAL=true;
151 shift 1;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200152 # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200153 -t | --runTests )
154 RUNTESTS=true;
155 shift 1 ;;
Idan Amitdb3d5542017-12-07 11:33:32 +0200156 # -h | --help - Display the help message with all the available run options
Yuli Shlosberg0566f582017-11-26 19:05:23 +0200157 -h | --help )
158 usage;
159 exit 0;;
160 * )
161 usage;
162 exit 1;;
Michael Lando451a3402017-02-19 10:28:42 +0200163 esac
Michael Lando451a3402017-02-19 10:28:42 +0200164done
165
Yuli Shlosberg3301bec2017-11-08 15:31:27 +0200166
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200167[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || echo ${DEP_ENV}
Yuli Shlosberg316bb252017-11-14 11:47:17 +0200168[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
169[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
170[ -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 +0200171[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
172
173
Grinberg Motic3bda482017-02-23 11:24:34 +0200174cleanup
175
Michael Lando451a3402017-02-19 10:28:42 +0200176
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200177export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
Idan Amitdb3d5542017-12-07 11:33:32 +0200178export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
Idan Amitc7f57ec2017-08-31 14:26:21 +0300179
180if [ ${LOCAL} = true ]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200181 PREFIX='onap'
Idan Amitc7f57ec2017-08-31 14:26:21 +0300182fi
Michael Lando451a3402017-02-19 10:28:42 +0200183
184echo ""
185
186# Elastic-Search
187echo "docker run sdc-elasticsearch..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300188if [ ${LOCAL} = false ]; then
189 echo "pulling code"
190 docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
191fi
Tal Gitelmanf1927592018-01-29 17:24:56 +0200192docker run -dit --name sdc-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --memory 750m --env ES_JAVA_OPTS="-Xms512m -Xmx512m" --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --env 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} /bin/sh
193
194elasticHealthCheck
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200195
Tal Gitelman38211c82018-01-24 17:59:53 +0200196# Init-Elastic-Search
197echo "docker run sdc-init-elasticsearch..."
198if [ ${LOCAL} = false ]; then
199 echo "pulling code"
200 docker pull ${PREFIX}/sdc-init-elasticsearch:${RELEASE}
201fi
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200202docker run --name sdc-init-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --memory 750m --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments ${PREFIX}/sdc-init-elasticsearch:${RELEASE}
Tal Gitelmanf1927592018-01-29 17:24:56 +0200203
204# Checking Elastic-Search-Init chef status
205if [ ! $? -eq 0 ]; then
206 echo "Elastic-Search Initialization failed"
207 exit $?
208fi
Idan Amitc7f57ec2017-08-31 14:26:21 +0300209
Tal Gitelman38211c82018-01-24 17:59:53 +0200210# Cassandra
Idan Amitc7f57ec2017-08-31 14:26:21 +0300211echo "docker run sdc-cassandra..."
212if [ ${LOCAL} = false ]; then
213 docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
214fi
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200215docker run -dit --name sdc-cs --env RELEASE="${RELEASE}" --env CS_PASSWORD="${CS_PASSWORD}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --env JVM_OPTS="-Xms1024m -Xmx1024m" --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} /bin/sh
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200216
Michael Lando451a3402017-02-19 10:28:42 +0200217
218echo "please wait while CS is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300219monitor_docker sdc-cs
Michael Lando451a3402017-02-19 10:28:42 +0200220
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200221
222# cassandra-init
223echo "docker run sdc-cassandra-init..."
224if [ ${LOCAL} = false ]; then
225 docker pull ${PREFIX}/sdc-cassandra-init:${RELEASE}
226fi
227docker run --name sdc-cs-init --env RELEASE="${RELEASE}" --env SDC_USER="${SDC_USER}" --env SDC_PASSWORD="${SDC_PASSWORD}" --env CS_PASSWORD="${CS_PASSWORD}" --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 --volume ${WORKSPACE}/data/CS-Init:/root/chef-solo/cache ${PREFIX}/sdc-cassandra-init:${RELEASE} > /dev/null 2>&1
228rc=$?
229if [[ $rc != 0 ]]; then exit $rc; fi
230
231
Michael Lando451a3402017-02-19 10:28:42 +0200232# kibana
233echo "docker run sdc-kibana..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300234if [ ${LOCAL} = false ]; then
235 docker pull ${PREFIX}/sdc-kibana:${RELEASE}
236fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200237docker 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}
238
239
Michael Lando451a3402017-02-19 10:28:42 +0200240
Grinberg Motic3bda482017-02-23 11:24:34 +0200241dir_perms
Michael Lando451a3402017-02-19 10:28:42 +0200242
243# Back-End
244echo "docker run sdc-backend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300245if [ ${LOCAL} = false ]; then
246 docker pull ${PREFIX}/sdc-backend:${RELEASE}
Tal Gitelmane224d0b2017-10-17 15:24:25 +0300247else
Tal Gitelman8e5fc512017-10-23 13:49:06 +0300248 ADDITIONAL_ARGUMENTS=${DEBUG_PORT}
Idan Amitc7f57ec2017-08-31 14:26:21 +0300249fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200250docker 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}
251
252
Michael Lando451a3402017-02-19 10:28:42 +0200253
254echo "please wait while BE is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300255monitor_docker sdc-BE
Michael Lando451a3402017-02-19 10:28:42 +0200256
257
258# Front-End
259echo "docker run sdc-frontend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300260if [ ${LOCAL} = false ]; then
261 docker pull ${PREFIX}/sdc-frontend:${RELEASE}
262fi
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200263docker 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 +0200264
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200265
266
267echo "please wait while FE is starting....."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300268monitor_docker sdc-FE
269
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200270# healthCheck
271healthCheck
Michael Lando451a3402017-02-19 10:28:42 +0200272
ml636r0649e652017-02-20 21:10:54 +0200273
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300274# sanityDocker
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200275if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200276 echo "docker run sdc-sanity..."
277 echo "Triger sanity docker, please wait..."
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200278
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300279 if [ ${LOCAL} = false ]; then
Idan Amitdb3d5542017-12-07 11:33:32 +0200280 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300281 fi
Yuli Shlosberg316bb252017-11-14 11:47:17 +0200282
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200283docker 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}
284echo "please wait while SANITY is starting....."
Yuli Shlosbergd1bb2e52018-01-15 11:51:21 +0200285monitor_docker sdc-sanity
Yuli Shlosberg137cf5c2018-01-15 17:32:30 +0200286
Yuli Shlosberg0875ce02018-01-25 13:53:36 +0200287fi