Enable debug mode in BE
[sdc.git] / sdc-os-chef / scripts / docker_run.sh
1 #!/bin/bash
2
3
4 function usage {
5     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 ]"
6 }
7
8
9 function cleanup {
10     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
16 }
17
18
19 function dir_perms {
20     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
23 }
24
25 function monitor_docker {
26
27     echo monitor $1 Docker
28     sleep 5
29     TIME_OUT=900
30     INTERVAL=20
31     TIME=0
32     while [ "$TIME" -lt "$TIME_OUT" ]; do
33
34         MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
35         echo MATCH is -- $MATCH
36
37         if [ -n "$MATCH" ]; then
38             echo DOCKER start finished in $TIME seconds
39             docker logs $1 > ${WORKSPACE}/data/logs/dockerLogs_$1.log
40             break
41         fi
42
43         echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
44         sleep $INTERVAL
45         TIME=$(($TIME+$INTERVAL))
46     done
47
48     if [ "$TIME" -ge "$TIME_OUT" ]; then
49         echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
50     fi
51
52 }
53
54 function healthCheck {
55         curl localhost:9200/_cluster/health?pretty=true
56
57         echo "BE health-Check:"
58         #curl http://localhost:8080/sdc2/rest/healthCheck
59         curl -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8080/sdc2/rest/healthCheck
60
61         echo ""
62         echo ""
63         echo "FE health-Check:"
64         #curl http://localhost:8181/sdc1/rest/healthCheck
65         curl -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://localhost:8181/sdc1/rest/healthCheck
66
67
68
69         echo ""
70         echo ""
71         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;)
72         if [[ ${healthCheck_http_code} != 200 ]]
73         then
74                 echo "Error [${healthCheck_http_code}] while user existance check"
75                 return ${healthCheck_http_code}
76         fi
77         echo "check user existance: OK"
78         return ${healthCheck_http_code}
79 }
80
81 RELEASE=latest
82 LOCAL=false
83 RUNTESTS=false
84 DEBUG_PORT="--publish 4000:4000"
85
86 while [ $# -gt 0 ]; do
87     case $1 in
88         # -r | --release - The specific docker version to pull and deploy
89     -r | --release )
90           shift 1 ;
91           RELEASE=$1;
92           shift 1;;
93         # -e | --environment - The environment name you want to deploy
94     -e | --environment )
95           shift 1;
96           DEP_ENV=$1;
97           shift 1 ;;
98         # -p | --port - The port from which to connect to the docker nexus
99     -p | --port )
100           shift 1 ;
101           PORT=$1;
102           shift 1 ;;
103         # -l | --local - Use this for deploying your local dockers without pulling them first
104     -l | --local )
105           LOCAL=true;
106           shift 1;;
107         # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed
108     -t | --runTests )
109           RUNTESTS=true;
110           shift 1 ;;
111         # -h | --help - Display the help message with all the available run options
112     -h | --help )
113           usage;
114           exit  0;;
115          * )
116           usage;
117           exit  1;;
118     esac
119 done
120
121
122 [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
123 [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
124 [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
125 [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
126 [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
127
128
129 cleanup
130
131
132 export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
133 export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp'
134
135 if [ ${LOCAL} = true ]; then
136         PREFIX='openecomp'
137 fi
138
139 echo ""
140
141 # Elastic-Search
142 echo "docker run sdc-elasticsearch..."
143 if [ ${LOCAL} = false ]; then
144         echo "pulling code"
145         docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
146 fi
147 docker 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}
148
149
150 # cassandra
151 echo "docker run sdc-cassandra..."
152 if [ ${LOCAL} = false ]; then
153         docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
154 fi
155 docker 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}
156
157
158 echo "please wait while CS is starting..."
159 monitor_docker sdc-cs
160
161 # kibana
162 echo "docker run sdc-kibana..."
163 if [ ${LOCAL} = false ]; then
164         docker pull ${PREFIX}/sdc-kibana:${RELEASE}
165 fi
166 docker 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}
167
168
169
170 dir_perms
171
172 # Back-End
173 echo "docker run sdc-backend..."
174 if [ ${LOCAL} = false ]; then
175         docker pull ${PREFIX}/sdc-backend:${RELEASE}
176 else
177         ADDITIONAL_ARGUMENTS=${DEBUG_PORT}
178 fi
179 docker 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}
180
181
182
183 echo "please wait while BE is starting..."
184 monitor_docker sdc-BE
185
186
187 # Front-End
188 echo "docker run sdc-frontend..."
189 if [ ${LOCAL} = false ]; then
190         docker pull ${PREFIX}/sdc-frontend:${RELEASE}
191 fi
192 docker 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}
193
194
195
196 echo "please wait while FE is starting....."
197 monitor_docker sdc-FE
198
199 # healthCheck
200 healthCheck
201
202
203 # sanityDocker
204 if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
205     echo "docker run sdc-sanity..."
206     echo "Triger sanity docker, please wait..."
207         
208     if [ ${LOCAL} = false ]; then
209         docker pull ${PREFIX}/sdc-sanity:${RELEASE}
210     fi
211
212 docker 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}
213 echo "please wait while SANITY is starting....."
214 monitor_docker sdc-sanity
215
216 fi