blob: 71d110521f4e307625e40a25982688b1acddc74e [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
17if ! ifconfig docker0; then
18if ! ifconfig ens3; then
19echo "Could not determine IP address"
20exit 1
21fi
22export DOCKER_IP_IP=`ifconfig ens3 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
23else
24export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
25fi
26echo $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}
32ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP} -v IP:${IP} -v DOCKER_IP:${DOCKER_IP}"
33export DOCKER_IP=${DOCKER_IP}
34
35
36# be verbose
37set -x
38
39# Establish environment variables
40NEXUS_USERNAME=docker
41NEXUS_PASSWD=docker
42NEXUS_DOCKER_REPO=nexus3.onap.org:10003
43
44
45
46CURR="$(pwd)"
47git clone http://gerrit.onap.org/r/portal
48
49# Refresh configuration and scripts
50cd portal
51git pull
52cd deliveries
53rm .env
54rm docker-compose.yml
55cp $CURR/.env .
56cp $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
62source $CURR/.env
63
64# Copy property files to new directory
65mkdir -p $PROPS_DIR
66cp -r properties_rackspace/* $PROPS_DIR
67# Also create logs directory
68mkdir -p $LOGS_DIR
69
70
71# Refresh images
72docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
73docker pull $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION
74docker pull $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION
75docker pull $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION
76docker pull $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION
77
78# Tag them as expected by docker-compose file
79docker tag $NEXUS_DOCKER_REPO/${DB_IMG_NAME}:$DOCKER_IMAGE_VERSION $DB_IMG_NAME:$PORTAL_TAG
80docker tag $NEXUS_DOCKER_REPO/${EP_IMG_NAME}:$DOCKER_IMAGE_VERSION $EP_IMG_NAME:$PORTAL_TAG
81docker tag $NEXUS_DOCKER_REPO/${WMS_IMG_NAME}:$DOCKER_IMAGE_VERSION $WMS_IMG_NAME:$PORTAL_TAG
82docker tag $NEXUS_DOCKER_REPO/$CLI_IMG_NAME:$CLI_DOCKER_VERSION $CLI_IMG_NAME:$PORTAL_TAG
83
84
85# compose is not in /usr/bin
86docker-compose down
87docker-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
99ip_address=$HOST_IP
100host_name="portal.api.simpledemo.openecomp.org"
101# find existing instances in the host file and save the line numbers
102matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
103host_entry="${ip_address} ${host_name}"
104
105echo "$host_entry"
106
107if [ ! -z "$matches_in_hosts" ]
108then
109echo "Updating existing hosts entry."
110# iterate over the line numbers on which matches were found
111while read -r line_number; do
112# replace the text of each line with the desired host entry
113sudo sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
114echo "${line_number} ${host_entry}"
115done <<< "$matches_in_hosts"
116else
117echo "Adding new hosts entry."
118echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
119fi
120
121sleep 3m
122
123# WAIT 5 minutes maximum and test every 5 seconds if Portal up using HealthCheck API
124TIME_OUT=500
125INTERVAL=20
126TIME=0
127while [ "$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))
138done
139
140if [ "$TIME" -ge "$TIME_OUT" ]; then
141 echo TIME OUT: Docker containers not started in $TIME_OUT seconds... Could cause problems for tests...
142fi
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
157HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}')
158export HOST_IP=${HOST_IP}
159
160docker logs deliveries_portal-db_1
161docker logs deliveries_portal-apps_1
162docker logs deliveries_portal-wms_1
163
164
165
166