blob: 0c90dc66bd6ba6845eab2d7b2bf1de766bb59e16 [file] [log] [blame]
kishore0fdcc612017-10-09 08:19:36 -05001#!/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
8echo -e "Starting Xvfb on display ${DISPLAY} with res ${RES}"
9Xvfb ${DISPLAY} -ac -screen 0 ${RES} +extension RANDR &
10XVFBPID=$!
11# Get pid of this spawned process to make sure we kill the correct process later
12
13#Get current IP of VM
14HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}')
15export HOST_IP=${HOST_IP}
16
kishoreb24e8412017-10-12 15:44:40 -050017
18
kishore0fdcc612017-10-09 08:19:36 -050019if ! ifconfig docker0; then
20if ! ifconfig ens3; then
21echo "Could not determine IP address"
22exit 1
23fi
24export DOCKER_IP_IP=`ifconfig ens3 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
25else
26export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
27fi
28echo $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}
34ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP} -v IP:${IP} -v DOCKER_IP:${DOCKER_IP}"
35export DOCKER_IP=${DOCKER_IP}
36
37
kishoreb24e8412017-10-12 15:44:40 -050038
39
kishore0fdcc612017-10-09 08:19:36 -050040# be verbose
41set -x
42
43# Establish environment variables
44NEXUS_USERNAME=docker
45NEXUS_PASSWD=docker
46NEXUS_DOCKER_REPO=nexus3.onap.org:10003
47
48
49
50CURR="$(pwd)"
kishoref3bb7142017-10-31 13:56:36 -050051git clone http://gerrit.onap.org/r/portal -b "release-1.3.0"
kishore0fdcc612017-10-09 08:19:36 -050052
53# Refresh configuration and scripts
54cd portal
55git pull
56cd deliveries
57rm .env
kishore7a1888f2017-10-19 08:11:06 -050058#rm docker-compose.yml
kishore0fdcc612017-10-09 08:19:36 -050059cp $CURR/.env .
kishore7a1888f2017-10-19 08:11:06 -050060#cp $CURR/docker-compose.yml .
kishoreb24e8412017-10-12 15:44:40 -050061#cd properties_simpledemo/ECOMPPORTALAPP
kishore0fdcc612017-10-09 08:19:36 -050062#rm system.properties
63#cp $CURR/system.properties .
64#cd ../..
65# Get image names used below from docker-compose environment file
66source $CURR/.env
kishoreb24e8412017-10-12 15:44:40 -050067#source .env
68
69# Make inter-app communication work in CSIT
70export EXTRA_HOST_IP="-i ${HOST_IP}"
kishore7a1888f2017-10-19 08:11:06 -050071export EXTRA_HOST_NAME="-n portal.api.simpledemo.onap.org"
kishoreb24e8412017-10-12 15:44:40 -050072
kishore0fdcc612017-10-09 08:19:36 -050073
74# Copy property files to new directory
75mkdir -p $PROPS_DIR
kishoreb24e8412017-10-12 15:44:40 -050076cp -r properties_simpledemo/* $PROPS_DIR
kishore0fdcc612017-10-09 08:19:36 -050077# Also create logs directory
78mkdir -p $LOGS_DIR
79
80
81# Refresh images
82docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
83docker pull $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION
84docker pull $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION
85docker pull $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION
86docker pull $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION
87
88# Tag them as expected by docker-compose file
89docker tag $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION $DB_IMG_NAME:$PORTAL_TAG
90docker tag $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION $EP_IMG_NAME:$PORTAL_TAG
91docker tag $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION $WMS_IMG_NAME:$PORTAL_TAG
92docker tag $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION $CLI_IMG_NAME:$PORTAL_TAG
93
94
95# compose is not in /usr/bin
96docker-compose down
97docker-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
109ip_address=$HOST_IP
kishore7a1888f2017-10-19 08:11:06 -0500110host_name="portal.api.simpledemo.onap.org"
kishore0fdcc612017-10-09 08:19:36 -0500111# find existing instances in the host file and save the line numbers
112matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
113host_entry="${ip_address} ${host_name}"
114
115echo "$host_entry"
116
117if [ ! -z "$matches_in_hosts" ]
118then
119echo "Updating existing hosts entry."
120# iterate over the line numbers on which matches were found
121while read -r line_number; do
122# replace the text of each line with the desired host entry
123sudo sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
124echo "${line_number} ${host_entry}"
125done <<< "$matches_in_hosts"
126else
127echo "Adding new hosts entry."
128echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
129fi
130
kishoreb24e8412017-10-12 15:44:40 -0500131
132
kishore0fdcc612017-10-09 08:19:36 -0500133sleep 3m
134
135# WAIT 5 minutes maximum and test every 5 seconds if Portal up using HealthCheck API
136TIME_OUT=500
137INTERVAL=20
138TIME=0
139while [ "$TIME" -lt "$TIME_OUT" ]; do
kishore7a1888f2017-10-19 08:11:06 -0500140 response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/portalApi/healthCheck); echo $response
kishore0fdcc612017-10-09 08:19:36 -0500141
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))
150done
151
152if [ "$TIME" -ge "$TIME_OUT" ]; then
153 echo TIME OUT: Docker containers not started in $TIME_OUT seconds... Could cause problems for tests...
154fi
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
169HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}')
170export HOST_IP=${HOST_IP}
171
kishoreb24e8412017-10-12 15:44:40 -0500172#docker logs deliveries_portal-db_1
kishore0fdcc612017-10-09 08:19:36 -0500173docker logs deliveries_portal-apps_1
174docker logs deliveries_portal-wms_1
175
176
177
178