Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 4 | function usage { |
Yuli Shlosberg | 9dde926 | 2017-09-12 14:11:48 +0300 | [diff] [blame] | 5 | 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 Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 9 | function cleanup { |
| 10 | echo "performing old dockers cleanup" |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 11 | docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'` |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 12 | for X in ${docker_ids} |
| 13 | do |
| 14 | docker rm -f ${X} |
| 15 | done |
| 16 | } |
| 17 | |
| 18 | |
| 19 | function dir_perms { |
Yuli Shlosberg | 1a9a041 | 2017-10-26 15:32:58 +0300 | [diff] [blame] | 20 | mkdir -p /data/logs/BE/SDC/SDC-BE |
| 21 | mkdir -p /data/logs/FE/SDC/SDC-FE |
Michael Lando | 33d78d8 | 2017-02-27 19:48:33 +0200 | [diff] [blame] | 22 | chmod -R 777 /data/logs |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 23 | } |
| 24 | |
Yuli Shlosberg | 5571a86 | 2017-10-03 18:18:51 +0300 | [diff] [blame] | 25 | function monitor_docker { |
| 26 | |
| 27 | echo monitor $1 Docker |
Yuli Shlosberg | 1a9a041 | 2017-10-26 15:32:58 +0300 | [diff] [blame] | 28 | sleep 5 |
Tal Gitelman | 0d3a3f8 | 2017-11-01 20:05:38 +0200 | [diff] [blame] | 29 | TIME_OUT=900 |
Yuli Shlosberg | 5571a86 | 2017-10-03 18:18:51 +0300 | [diff] [blame] | 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" ] |
| 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)) |
| 46 | done |
| 47 | |
| 48 | if [ "$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" |
| 51 | fi |
| 52 | |
| 53 | |
| 54 | } |
| 55 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 56 | |
Grinberg Moti | 9724621 | 2017-02-21 19:30:31 +0200 | [diff] [blame] | 57 | RELEASE=latest |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 58 | LOCAL=false |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 59 | RUNTESTS=false |
Tal Gitelman | 8e5fc51 | 2017-10-23 13:49:06 +0300 | [diff] [blame] | 60 | DEBUG_PORT="--publish 4000:4000" |
Tal Gitelman | e224d0b | 2017-10-17 15:24:25 +0300 | [diff] [blame] | 61 | |
Yuli Shlosberg | 316bb25 | 2017-11-14 11:47:17 +0200 | [diff] [blame] | 62 | while [ $# -gt 0 ] |
| 63 | do |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 64 | case $1 in |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 65 | -r | --release ) |
| 66 | shift 1 ; |
| 67 | RELEASE=$1; |
| 68 | shift 1;; |
| 69 | -e | --environment ) |
| 70 | shift 1; |
| 71 | DEP_ENV=$1; |
| 72 | shift 1 ;; |
| 73 | -p | --port ) |
| 74 | shift 1 ; |
| 75 | PORT=$1; |
| 76 | shift 1 ;; |
| 77 | -l | --local ) |
| 78 | LOCAL=true; |
| 79 | shift 1;; |
| 80 | -t | --runTests ) |
| 81 | RUNTESTS=true; |
| 82 | shift 1 ;; |
| 83 | -h | --help ) |
| 84 | usage; |
| 85 | exit 0;; |
| 86 | * ) |
| 87 | usage; |
| 88 | exit 1;; |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 89 | esac |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 90 | done |
| 91 | |
Yuli Shlosberg | 3301bec | 2017-11-08 15:31:27 +0200 | [diff] [blame] | 92 | |
Yuli Shlosberg | 316bb25 | 2017-11-14 11:47:17 +0200 | [diff] [blame] | 93 | [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__ |
| 94 | [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release |
| 95 | [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW |
| 96 | [ -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 Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 97 | [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 98 | |
| 99 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 100 | cleanup |
| 101 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 102 | |
| 103 | export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 104 | export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp' |
| 105 | |
| 106 | if [ ${LOCAL} = true ]; then |
| 107 | PREFIX='openecomp' |
| 108 | fi |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 109 | |
| 110 | echo "" |
| 111 | |
| 112 | # Elastic-Search |
| 113 | echo "docker run sdc-elasticsearch..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 114 | if [ ${LOCAL} = false ]; then |
| 115 | echo "pulling code" |
| 116 | docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE} |
| 117 | fi |
Yuli Shlosberg | 316bb25 | 2017-11-14 11:47:17 +0200 | [diff] [blame] | 118 | 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 --memory-swap=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 /data/ES:/usr/share/elasticsearch/data --volume /data/environments:/root/chef-solo/environments --publish 9200:9200 --publish 9300:9300 ${PREFIX}/sdc-elasticsearch:${RELEASE} |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 119 | |
| 120 | |
| 121 | # cassandra |
| 122 | echo "docker run sdc-cassandra..." |
| 123 | if [ ${LOCAL} = false ]; then |
| 124 | docker pull ${PREFIX}/sdc-cassandra:${RELEASE} |
| 125 | fi |
Idan Amit | 9409da0 | 2017-09-03 14:46:10 +0300 | [diff] [blame] | 126 | 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 /data/CS:/var/lib/cassandra --volume /data/environments:/root/chef-solo/environments --publish 9042:9042 --publish 9160:9160 ${PREFIX}/sdc-cassandra:${RELEASE} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 127 | |
| 128 | |
| 129 | echo "please wait while CS is starting..." |
Yuli Shlosberg | 5571a86 | 2017-10-03 18:18:51 +0300 | [diff] [blame] | 130 | monitor_docker sdc-cs |
| 131 | #echo "" |
| 132 | #c=120 # seconds to wait |
| 133 | #REWRITE="\e[25D\e[1A\e[K" |
| 134 | #while [ $c -gt 0 ]; do |
| 135 | # c=$((c-1)) |
| 136 | # sleep 1 |
| 137 | # echo -e "${REWRITE}$c" |
| 138 | #done |
| 139 | #echo -e " |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 140 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 141 | # kibana |
| 142 | echo "docker run sdc-kibana..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 143 | if [ ${LOCAL} = false ]; then |
| 144 | docker pull ${PREFIX}/sdc-kibana:${RELEASE} |
| 145 | fi |
| 146 | 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 --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 Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 147 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 148 | dir_perms |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 149 | |
| 150 | # Back-End |
| 151 | echo "docker run sdc-backend..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 152 | if [ ${LOCAL} = false ]; then |
| 153 | docker pull ${PREFIX}/sdc-backend:${RELEASE} |
Tal Gitelman | e224d0b | 2017-10-17 15:24:25 +0300 | [diff] [blame] | 154 | else |
Tal Gitelman | 8e5fc51 | 2017-10-23 13:49:06 +0300 | [diff] [blame] | 155 | ADDITIONAL_ARGUMENTS=${DEBUG_PORT} |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 156 | fi |
Tal Gitelman | e224d0b | 2017-10-17 15:24:25 +0300 | [diff] [blame] | 157 | 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 --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 Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 158 | |
| 159 | echo "please wait while BE is starting..." |
Yuli Shlosberg | 5571a86 | 2017-10-03 18:18:51 +0300 | [diff] [blame] | 160 | monitor_docker sdc-BE |
| 161 | #echo "" |
| 162 | #c=45 # seconds to wait |
| 163 | #REWRITE="\e[45D\e[1A\e[K" |
| 164 | #while [ $c -gt 0 ]; do |
| 165 | # c=$((c-1)) |
| 166 | # sleep 1 |
| 167 | # echo -e "${REWRITE}$c" |
| 168 | #done |
| 169 | #echo -e "" |
| 170 | |
| 171 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 172 | |
| 173 | |
| 174 | # Front-End |
| 175 | echo "docker run sdc-frontend..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 176 | if [ ${LOCAL} = false ]; then |
| 177 | docker pull ${PREFIX}/sdc-frontend:${RELEASE} |
| 178 | fi |
| 179 | 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 --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 Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 180 | |
Yuli Shlosberg | 5571a86 | 2017-10-03 18:18:51 +0300 | [diff] [blame] | 181 | echo "docker run sdc-frontend..." |
| 182 | monitor_docker sdc-FE |
| 183 | |
| 184 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 185 | |
| 186 | |
| 187 | # running healthCheck scripts |
| 188 | echo "Running health checks, please wait..." |
| 189 | echo "" |
Tal Gitelman | 0a92119 | 2017-10-03 15:03:25 +0300 | [diff] [blame] | 190 | c=30 # seconds to wait |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 191 | REWRITE="\e[45D\e[1A\e[K" |
| 192 | while [ $c -gt 0 ]; do |
| 193 | c=$((c-1)) |
| 194 | sleep 1 |
| 195 | echo -e "${REWRITE}$c" |
| 196 | done |
| 197 | echo -e "" |
| 198 | |
| 199 | /data/scripts/docker_health.sh |
| 200 | |
Tal Gitelman | 93c2e98 | 2017-10-30 20:18:11 +0200 | [diff] [blame] | 201 | #if [ $? -ne 0 ]; then |
| 202 | # exit 1 |
| 203 | #fi |
ml636r | 0649e65 | 2017-02-20 21:10:54 +0200 | [diff] [blame] | 204 | |
Yuli Shlosberg | 9dde926 | 2017-09-12 14:11:48 +0300 | [diff] [blame] | 205 | # sanityDocker |
Yuli Shlosberg | 905083e | 2017-11-01 14:44:44 +0200 | [diff] [blame] | 206 | echo "docker run sdc-sanity..." |
Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 207 | if [ ${RUNTESTS} = true ]; then |
Yuli Shlosberg | 9dde926 | 2017-09-12 14:11:48 +0300 | [diff] [blame] | 208 | echo "Triger sanity docker, please wait..." |
| 209 | if [ ${LOCAL} = false ]; then |
| 210 | docker pull ${PREFIX}/sdc-sanity:${RELEASE} |
| 211 | fi |
Yuli Shlosberg | 316bb25 | 2017-11-14 11:47:17 +0200 | [diff] [blame] | 212 | |
| 213 | 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 --memory-swap=1500m --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/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume /data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE} |
| 214 | fi |