blob: 339b538f7a0a976cf054ab5f2299b0cd128f5f70 [file] [log] [blame]
Yuli Shlosberg0566f582017-11-26 19:05:23 +02001#!/bin/bash
2
3
4function 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>] [ -s|--skipTests <Run-without-sanityDocker>] [ -h|--help ]"
6}
7
8
9function 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
19function dir_perms {
20 mkdir -p /data/logs/BE/SDC/SDC-BE
21 mkdir -p /data/logs/FE/SDC/SDC-FE
22 chmod -R 777 /data/logs
23}
24
25function monitor_docker {
26
27echo monitor $1 Docker
28sleep 10
29TIME_OUT=800
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
56
57RELEASE=latest
58LOCAL=false
59SKIPTESTS=false
60DEBUG_PORT="--publish 4000:4000"
61
62[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
63[ -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}
66
67while test $# -gt 0; 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 ;;
81 -l | --local )
82 shift
83 LOCAL=true
84 ;;
85 -s | --skipTests )
86 shift
87 SKIPTESTS=true
88 ;;
89 -h | --help )
90 usage
91 exit
92 ;;
93 * )
94 usage
95 exit 1
96 esac
97done
98
99[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
100
101
102
103
104export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
105export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp'
106
107if [ ${LOCAL} = true ]; then
108 PREFIX='openecomp'
109fi
110
111echo ""
112
113
114# sanityDocker
115echo "docker run sdc-frontend..."
116if [ ${SKIPTESTS} = false ]; then
117echo "Triger sanity docker, please wait..."
118 if [ ${LOCAL} = false ]; then
119 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
120 fi
121 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 1.2g --memory-swap=1.2g --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 8849:8849 --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
122fi