Yuli Shlosberg | 0566f58 | 2017-11-26 19:05:23 +0200 | [diff] [blame] | 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>] [ -s|--skipTests <Run-without-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-sanity|sdc-sanity|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 /data/logs/BE/SDC/SDC-BE |
| 21 | mkdir -p /data/logs/FE/SDC/SDC-FE |
| 22 | chmod -R 777 /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" ] |
| 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 | |
| 56 | |
| 57 | RELEASE=latest |
| 58 | LOCAL=false |
| 59 | SKIPTESTS=false |
| 60 | DEBUG_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 | |
| 67 | while [ "$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 | ;; |
| 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 |
| 97 | shift |
| 98 | done |
| 99 | |
| 100 | [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 101 | |
| 102 | export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
| 103 | export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp' |
| 104 | |
| 105 | if [ ${LOCAL} = true ]; then |
| 106 | PREFIX='openecomp' |
| 107 | fi |
| 108 | |
| 109 | ## sanityDocker |
| 110 | echo "docker run sdc-sanity..." |
| 111 | if [ ${SKIPTESTS} = false ]; then |
| 112 | echo "Triger sanity docker, please wait..." |
| 113 | if [ ${LOCAL} = false ]; then |
| 114 | docker pull ${PREFIX}/sdc-sanity:${RELEASE} |
| 115 | fi |
| 116 | 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/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume /data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE} |
| 117 | fi |