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