blob: 20cde17f574edeaaf45384e42f71c82f1a0cde65 [file] [log] [blame]
Michael Lando451a3402017-02-19 10:28:42 +02001#!/bin/bash
2
3
Grinberg Motic3bda482017-02-23 11:24:34 +02004function usage {
Yuli Shlosberg9dde9262017-09-12 14:11:48 +03005 echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -s|--skipTests <Run-without-sanityDocker>] [ -h|--help ]"
Michael Lando451a3402017-02-19 10:28:42 +02006}
7
8
Grinberg Motic3bda482017-02-23 11:24:34 +02009function cleanup {
10 echo "performing old dockers cleanup"
Idan Amitc7f57ec2017-08-31 14:26:21 +030011 docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
Grinberg Motic3bda482017-02-23 11:24:34 +020012 for X in ${docker_ids}
13 do
14 docker rm -f ${X}
15 done
16}
17
18
19function dir_perms {
20 mkdir -p /data/logs/BE/ASDC/ASDC-BE
21 mkdir -p /data/logs/FE/ASDC/ASDC-FE
Michael Lando33d78d82017-02-27 19:48:33 +020022 chmod -R 777 /data/logs
Grinberg Motic3bda482017-02-23 11:24:34 +020023}
24
Yuli Shlosberg5571a862017-10-03 18:18:51 +030025function monitor_docker {
26
27echo monitor $1 Docker
28
29TIME_OUT=180
30INTERVAL=20
31TIME=0
32while [ "$TIME" -lt "$TIME_OUT" ]; do
33
34MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
35echo MATCH is -- $MATCH
36
37if [ -n "$MATCH" ]
38 then
39 echo DOCKER start finished in $TIME seconds
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))
46done
47
48if [ "$TIME" -ge "$TIME_OUT" ]
49 then
50 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
51fi
52
53
54}
55
Grinberg Motic3bda482017-02-23 11:24:34 +020056
Grinberg Moti97246212017-02-21 19:30:31 +020057RELEASE=latest
Idan Amitc7f57ec2017-08-31 14:26:21 +030058LOCAL=false
Yuli Shlosberg9dde9262017-09-12 14:11:48 +030059SKIPTESTS=false
Tal Gitelmane224d0b2017-10-17 15:24:25 +030060DEBUG_PORT = "--publish 4000:4000"
61
Michael Lando451a3402017-02-19 10:28:42 +020062[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
Grinberg Moti53fbfb52017-02-21 14:22:40 +020063[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
64[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
65[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT}
Michael Lando451a3402017-02-19 10:28:42 +020066
67while [ "$1" != "" ]; do
68 case $1 in
69 -r | --release )
70 shift
71 RELEASE=${1}
72 ;;
73 -e | --environment )
74 shift
75 DEP_ENV=${1}
76 ;;
77 -p | --port )
78 shift
79 PORT=${1}
80 ;;
Idan Amitc7f57ec2017-08-31 14:26:21 +030081 -l | --local )
82 shift
83 LOCAL=true
84 ;;
Yuli Shlosberg9dde9262017-09-12 14:11:48 +030085 -s | --skipTests )
86 shift
87 SKIPTESTS=true
88 ;;
Michael Lando451a3402017-02-19 10:28:42 +020089 -h | --help )
90 usage
91 exit
92 ;;
Yuli Shlosberg5571a862017-10-03 18:18:51 +030093 * )
Michael Lando451a3402017-02-19 10:28:42 +020094 usage
95 exit 1
96 esac
97 shift
98done
99
Michael Lando451a3402017-02-19 10:28:42 +0200100[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
101
102
Grinberg Motic3bda482017-02-23 11:24:34 +0200103cleanup
104
Michael Lando451a3402017-02-19 10:28:42 +0200105
106export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
Idan Amitc7f57ec2017-08-31 14:26:21 +0300107export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp'
108
109if [ ${LOCAL} = true ]; then
110 PREFIX='openecomp'
111fi
Michael Lando451a3402017-02-19 10:28:42 +0200112
113echo ""
114
115# Elastic-Search
116echo "docker run sdc-elasticsearch..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300117if [ ${LOCAL} = false ]; then
118 echo "pulling code"
119 docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
120fi
121docker run --detach --name sdc-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --memory 1g --memory-swap=1g --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro -e ES_HEAP_SIZE=1024M --volume /data/ES:/usr/share/elasticsearch/data --volume /data/environments:/root/chef-solo/environments --publish 9200:9200 --publish 9300:9300 ${PREFIX}/sdc-elasticsearch:${RELEASE}
122
123
124# cassandra
125echo "docker run sdc-cassandra..."
126if [ ${LOCAL} = false ]; then
127 docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
128fi
Idan Amit9409da02017-09-03 14:46:10 +0300129docker 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 /data/CS:/var/lib/cassandra --volume /data/environments:/root/chef-solo/environments --publish 9042:9042 --publish 9160:9160 ${PREFIX}/sdc-cassandra:${RELEASE}
Michael Lando451a3402017-02-19 10:28:42 +0200130
131
132echo "please wait while CS is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300133monitor_docker sdc-cs
134#echo ""
135#c=120 # seconds to wait
136#REWRITE="\e[25D\e[1A\e[K"
137#while [ $c -gt 0 ]; do
138# c=$((c-1))
139# sleep 1
140# echo -e "${REWRITE}$c"
141#done
142#echo -e "
Michael Lando451a3402017-02-19 10:28:42 +0200143
Michael Lando451a3402017-02-19 10:28:42 +0200144# kibana
145echo "docker run sdc-kibana..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300146if [ ${LOCAL} = false ]; then
147 docker pull ${PREFIX}/sdc-kibana:${RELEASE}
148fi
149docker 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 --memory-swap=2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/environments:/root/chef-solo/environments --publish 5601:5601 ${PREFIX}/sdc-kibana:${RELEASE}
Michael Lando451a3402017-02-19 10:28:42 +0200150
Grinberg Motic3bda482017-02-23 11:24:34 +0200151dir_perms
Michael Lando451a3402017-02-19 10:28:42 +0200152
153# Back-End
154echo "docker run sdc-backend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300155if [ ${LOCAL} = false ]; then
156 docker pull ${PREFIX}/sdc-backend:${RELEASE}
Tal Gitelmane224d0b2017-10-17 15:24:25 +0300157else
158 ADDITIONAL_ARGUMENTS = ${DEBUG_PORT}
Idan Amitc7f57ec2017-08-31 14:26:21 +0300159fi
Tal Gitelmane224d0b2017-10-17 15:24:25 +0300160docker 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 --memory-swap=4g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/BE/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 8443:8443 --publish 8080:8080 ${ADDITIONAL_ARGUMENTS} ${PREFIX}/sdc-backend:${RELEASE}
Michael Lando451a3402017-02-19 10:28:42 +0200161
162echo "please wait while BE is starting..."
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300163monitor_docker sdc-BE
164#echo ""
165#c=45 # seconds to wait
166#REWRITE="\e[45D\e[1A\e[K"
167#while [ $c -gt 0 ]; do
168# c=$((c-1))
169# sleep 1
170# echo -e "${REWRITE}$c"
171#done
172#echo -e ""
173
174
Michael Lando451a3402017-02-19 10:28:42 +0200175
176
177# Front-End
178echo "docker run sdc-frontend..."
Idan Amitc7f57ec2017-08-31 14:26:21 +0300179if [ ${LOCAL} = false ]; then
180 docker pull ${PREFIX}/sdc-frontend:${RELEASE}
181fi
182docker 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 --memory 2g --memory-swap=2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/FE/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 9443:9443 --publish 8181:8181 ${PREFIX}/sdc-frontend:${RELEASE}
Michael Lando451a3402017-02-19 10:28:42 +0200183
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300184echo "docker run sdc-frontend..."
185monitor_docker sdc-FE
186
187
Michael Lando451a3402017-02-19 10:28:42 +0200188
189
190# running healthCheck scripts
191echo "Running health checks, please wait..."
192echo ""
Tal Gitelman0a921192017-10-03 15:03:25 +0300193c=30 # seconds to wait
Michael Lando451a3402017-02-19 10:28:42 +0200194REWRITE="\e[45D\e[1A\e[K"
195while [ $c -gt 0 ]; do
196 c=$((c-1))
197 sleep 1
198 echo -e "${REWRITE}$c"
199done
200echo -e ""
201
202/data/scripts/docker_health.sh
203
204if [ $? -ne 0 ]; then
205 exit 1
206fi
ml636r0649e652017-02-20 21:10:54 +0200207
Yuli Shlosberg9dde9262017-09-12 14:11:48 +0300208# sanityDocker
209echo "docker run sdc-frontend..."
210if [ ${SKIPTESTS} = false ]; then
211echo "Triger sanity docker, please wait..."
212 if [ ${LOCAL} = false ]; then
213 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
214 fi
Tal Gitelman15c2ce72017-10-18 19:47:40 +0300215 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 1g --memory-swap=1g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/sdc-sanity/target:/var/lib/tests/target --volume /data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume /data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
Yuli Shlosberg5571a862017-10-03 18:18:51 +0300216fi