kishore | 0fdcc61 | 2017-10-09 08:19:36 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Starts docker containers for ONAP Portal |
| 3 | # This version for Amsterdam/R1 of Portal, uses docker-compose. |
| 4 | # Temporarily maintained in portal/deliveries area; |
| 5 | # replicated from the ONAP demo/boot area due to release concerns. |
| 6 | |
| 7 | # Start Xvfb |
| 8 | echo -e "Starting Xvfb on display ${DISPLAY} with res ${RES}" |
| 9 | Xvfb ${DISPLAY} -ac -screen 0 ${RES} +extension RANDR & |
| 10 | XVFBPID=$! |
| 11 | # Get pid of this spawned process to make sure we kill the correct process later |
| 12 | |
| 13 | #Get current IP of VM |
| 14 | HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}') |
| 15 | export HOST_IP=${HOST_IP} |
| 16 | |
| 17 | if ! ifconfig docker0; then |
| 18 | if ! ifconfig ens3; then |
| 19 | echo "Could not determine IP address" |
| 20 | exit 1 |
| 21 | fi |
| 22 | export DOCKER_IP_IP=`ifconfig ens3 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
| 23 | else |
| 24 | export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
| 25 | fi |
| 26 | echo $DOCKER_IP |
| 27 | |
| 28 | |
| 29 | # Pass any variables required by Robot test suites in ROBOT_VARIABLES |
| 30 | #ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP} -v IP:${IP} -v POLICY_IP:${POLICY_IP} -v DOCKER_IP:${DOCKER_IP}" |
| 31 | #export PORTAL_IP=${PORTAL_IP} |
| 32 | ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP} -v IP:${IP} -v DOCKER_IP:${DOCKER_IP}" |
| 33 | export DOCKER_IP=${DOCKER_IP} |
| 34 | |
| 35 | |
| 36 | # be verbose |
| 37 | set -x |
| 38 | |
| 39 | # Establish environment variables |
| 40 | NEXUS_USERNAME=docker |
| 41 | NEXUS_PASSWD=docker |
| 42 | NEXUS_DOCKER_REPO=nexus3.onap.org:10003 |
| 43 | |
| 44 | |
| 45 | |
| 46 | CURR="$(pwd)" |
| 47 | git clone http://gerrit.onap.org/r/portal |
| 48 | |
| 49 | # Refresh configuration and scripts |
| 50 | cd portal |
| 51 | git pull |
| 52 | cd deliveries |
| 53 | rm .env |
| 54 | rm docker-compose.yml |
| 55 | cp $CURR/.env . |
| 56 | cp $CURR/docker-compose.yml . |
| 57 | #cd properties_rackspace/ECOMPPORTALAPP |
| 58 | #rm system.properties |
| 59 | #cp $CURR/system.properties . |
| 60 | #cd ../.. |
| 61 | # Get image names used below from docker-compose environment file |
| 62 | source $CURR/.env |
| 63 | |
| 64 | # Copy property files to new directory |
| 65 | mkdir -p $PROPS_DIR |
| 66 | cp -r properties_rackspace/* $PROPS_DIR |
| 67 | # Also create logs directory |
| 68 | mkdir -p $LOGS_DIR |
| 69 | |
| 70 | |
| 71 | # Refresh images |
| 72 | docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 73 | docker pull $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION |
| 74 | docker pull $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION |
| 75 | docker pull $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION |
| 76 | docker pull $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION |
| 77 | |
| 78 | # Tag them as expected by docker-compose file |
| 79 | docker tag $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION $DB_IMG_NAME:$PORTAL_TAG |
| 80 | docker tag $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION $EP_IMG_NAME:$PORTAL_TAG |
| 81 | docker tag $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION $WMS_IMG_NAME:$PORTAL_TAG |
| 82 | docker tag $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION $CLI_IMG_NAME:$PORTAL_TAG |
| 83 | |
| 84 | |
| 85 | # compose is not in /usr/bin |
| 86 | docker-compose down |
| 87 | docker-compose up -d |
| 88 | |
| 89 | #${HOSTNAME}="portal.api.simpledemo.openecomp.org" |
| 90 | #echo "$HOST_IP ${HOSTNAME}" >> /etc/hosts |
| 91 | |
| 92 | #echo "$HOST_IP portal.api.simpledemo.openecomp.org" >> /etc/hosts |
| 93 | #sudo sed -i "2i$HOST_IP portal.api.simpledemo.openecomp.org" /etc/hosts |
| 94 | |
| 95 | #HOST="portal.api.simpledemo.openecomp.org" |
| 96 | #sudo sed -i "/$HOST/ s/.*/$HOST_IP\t$HOST/g" /etc/hosts |
| 97 | |
| 98 | # insert/update hosts entry |
| 99 | ip_address=$HOST_IP |
| 100 | host_name="portal.api.simpledemo.openecomp.org" |
| 101 | # find existing instances in the host file and save the line numbers |
| 102 | matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)" |
| 103 | host_entry="${ip_address} ${host_name}" |
| 104 | |
| 105 | echo "$host_entry" |
| 106 | |
| 107 | if [ ! -z "$matches_in_hosts" ] |
| 108 | then |
| 109 | echo "Updating existing hosts entry." |
| 110 | # iterate over the line numbers on which matches were found |
| 111 | while read -r line_number; do |
| 112 | # replace the text of each line with the desired host entry |
| 113 | sudo sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts |
| 114 | echo "${line_number} ${host_entry}" |
| 115 | done <<< "$matches_in_hosts" |
| 116 | else |
| 117 | echo "Adding new hosts entry." |
| 118 | echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null |
| 119 | fi |
| 120 | |
| 121 | sleep 3m |
| 122 | |
| 123 | # WAIT 5 minutes maximum and test every 5 seconds if Portal up using HealthCheck API |
| 124 | TIME_OUT=500 |
| 125 | INTERVAL=20 |
| 126 | TIME=0 |
| 127 | while [ "$TIME" -lt "$TIME_OUT" ]; do |
| 128 | response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://portal.api.simpledemo.openecomp.org:8989/ECOMPPORTAL/portalApi/healthCheck); echo $response |
| 129 | |
| 130 | if [ "$response" == "200" ]; then |
| 131 | echo Portal and its database well started in $TIME seconds |
| 132 | break; |
| 133 | fi |
| 134 | |
| 135 | echo Sleep: $INTERVAL seconds before testing if Portal is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds |
| 136 | sleep $INTERVAL |
| 137 | TIME=$(($TIME+$INTERVAL)) |
| 138 | done |
| 139 | |
| 140 | if [ "$TIME" -ge "$TIME_OUT" ]; then |
| 141 | echo TIME OUT: Docker containers not started in $TIME_OUT seconds... Could cause problems for tests... |
| 142 | fi |
| 143 | |
| 144 | #sleep 3m |
| 145 | |
| 146 | |
| 147 | |
| 148 | #if [ "$TIME" -ge "$TIME_OUT" ]; then |
| 149 | # echo TIME OUT: Docker containers not started in $TIME_OUT seconds... Could cause problems for tests... |
| 150 | #fi |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | #Get current IP of VM |
| 157 | HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}') |
| 158 | export HOST_IP=${HOST_IP} |
| 159 | |
| 160 | docker logs deliveries_portal-db_1 |
| 161 | docker logs deliveries_portal-apps_1 |
| 162 | docker logs deliveries_portal-wms_1 |
| 163 | |
| 164 | |
| 165 | |
| 166 | |