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