summaryrefslogtreecommitdiffstats
path: root/components/congress/test-webapp/setup/install_congress_testserver.sh
blob: d4297111d2fb3700e4e09dbe8c62c6e86b4d8f16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Copyright 2015-2016 AT&T Intellectual Property, Inc
#  
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  
# http://www.apache.org/licenses/LICENSE-2.0
#  
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# What this is: script for installation of a test server for Congress.
# Status: this is a work in progress, under test.
#
# Prequisite: Devstack, or OPFNV installed per JOID or Apex installer
# On jumphost:
# - For Apex installs, on the jumphost, ssh to the undercloud VM and
#     $ su stack
#
# How to use:
#   Retrieve the copper install script as below, optionally specifying the 
#   branch to use as a URL parameter, e.g. ?h=stable%2Fbrahmaputra
# $ wget https://git.opnfv.org/cgit/copper/plain/components/congress/test-webapp/setup/install_congress_testserver.sh
# $ bash install_congress_testserver.sh <congress_ip> <keystone_ip> \
#     <admin-openrc.sh> [copper-branch]
#   where:
#     congress_ip: IP address of Congress service
#     keystone_ip: IP address of Keytone service
#     admin-openrc.sh: file location of admin-openrc.sh
#     copper-branch: optional copper git branch to install

set -x

CONGRESS_HOST=$1
KEYSTONE_HOST=$2

if [[ ! -z "$4" ]]; then cubranch=$4; fi

echo "Install prerequisites"
dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'`

if [ ! -d /tmp/copper ]; then mkdir /tmp/copper; fi
cp $3 /tmp/copper/admin-openrc.sh
source /tmp/copper/admin-openrc.sh

if [ "$dist" == "Ubuntu" ]; then
  if [[ ! $(dpkg -s docker-engine| grep Status) == "Status: install ok installed" ]]; then
    # Docker setup procedure from https://docs.docker.com/engine/installation/linux/ubuntulinux/
    echo "Install docker and prerequisites"
    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates
    sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    sudo tee /etc/apt/sources.list.d/docker.list <<- 'EOF'
deb https://apt.dockerproject.org/repo ubuntu-trusty main
EOF
    sudo apt-get update
    sudo apt-get purge lxc-docker
    apt-cache policy docker-engine
    sudo apt-get install -y linux-image-extra-$(uname -r)
    sudo apt-get install -y docker docker-engine
    sudo service docker start
  fi
else
  sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
  sudo yum install -y docker
  sudo service docker start
fi

echo "Clone copper"
if [ ! -d /tmp/copper/copper ]; then 
  cd /tmp/copper
  git clone https://gerrit.opnfv.org/gerrit/copper
  cd copper
  if [ $# -eq 1 ]; then git checkout $1; fi 
else
  echo "/tmp/copper exists: run 'rm -rf /tmp/copper' to start clean if needed"
fi


echo "Setup copper environment"
source /tmp/copper/env.sh

echo "Setup webapp files"
if [ ! -d /tmp/copper/log ]; then 
  mkdir /tmp/copper/log
  chmod 777 /tmp/copper/log
fi

echo "Point proxy.php to the Congress server"
sed -i -- "s/CONGRESS_HOST/$CONGRESS_HOST/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
echo "Add parameters for API authentication"
sed -i -- "s/KEYSTONE_HOST/$KEYSTONE_HOST/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
sed -i -- "s/OS_TENANT_NAME/$OS_TENANT_NAME/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
sed -i -- "s/OS_USERNAME/$OS_USERNAME/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
sed -i -- "s/OS_PASSWORD/$OS_PASSWORD/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php

echo "Start webapp container"
sudo docker build -t copper-webapp /tmp/copper/copper/components/congress/test-webapp/
sudo docker run -d -v /tmp/copper/log:/tmp -p 8257:80 --name copper copper-webapp 
CIP=$(sudo docker inspect copper | grep IPAddress | cut -d '"' -f 4 | tail -1)
echo "Copper Webapp IP address: $CIP"

set +x