blob: 6b4e6935e26f964782fbee33cdfc407b896fd5c3 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
A R Karthick49bf8252016-12-07 14:11:51 -080017#!/usr/bin/env bash
18
19function show_help {
A R Karthickbff105f2016-12-07 15:32:15 -080020 echo "Usage: ${0#*/} -h | this help -o <onos source path> -t <onos docker tag> -p <onos package> -b | build onos package -u |update onos source"
A R Karthick49bf8252016-12-07 14:11:51 -080021 exit 1
22}
23
24OPTIND=1
25onos_src_dir="$HOME/onos"
26onos_tag="test/onos:clustertest"
27onos_package=
28onos_build=0
A R Karthickbff105f2016-12-07 15:32:15 -080029onos_update=0
A R Karthick49bf8252016-12-07 14:11:51 -080030
A R Karthickbff105f2016-12-07 15:32:15 -080031while getopts "h?o:t:p:bu" opt; do
A R Karthick49bf8252016-12-07 14:11:51 -080032 case "$opt" in
33 h|\?)
34 show_help
35 ;;
36 o)
37 onos_src_dir=$OPTARG
38 ;;
39 p)
40 onos_package=$OPTARG
41 ;;
42 t)
43 onos_tag=$OPTARG
44 ;;
45 b)
46 onos_build=1
47 ;;
A R Karthickbff105f2016-12-07 15:32:15 -080048 u)
49 onos_update=1
50 ;;
A R Karthick49bf8252016-12-07 14:11:51 -080051 *)
52 show_help
53 ;;
54 esac
55done
56
57shift $((OPTIND-1))
58if [ $# -gt 0 ]; then
59 echo "Invalid arguments"
60 show_help
61fi
A.R Karthickcfe5ae92017-01-13 16:01:20 -080062mydir=$(dirname $(realpath $0))
A R Karthick49bf8252016-12-07 14:11:51 -080063if [ x"$onos_package" = "x" ]; then
64 if [ ! -d $onos_src_dir ]; then
65 onos_build=1
66 fi
67 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
68fi
69
A.R Karthickcfe5ae92017-01-13 16:01:20 -080070function build_onos {
71 if [ ! -f $mydir/Dockerfile.onos-builder ]; then
72 echo "Dockerfile.onos-builder not found. Copy this file from cord-tester project before resuming the build"
73 exit 127
74 fi
75 docker images | grep ^cord-tester-onos-builder || docker build -t cord-tester-onos-builder:latest -f $mydir/Dockerfile.onos-builder $mydir
76 docker run -v $mydir:/root/cord-tester --rm cord-tester-onos-builder:latest
77 return $?
78}
A R Karthick49bf8252016-12-07 14:11:51 -080079
80#if onos package is not built, then exit
81if [ $onos_build -eq 1 ]; then
82 if [ ! -d $onos_src_dir ]; then
A.R Karthickcfe5ae92017-01-13 16:01:20 -080083 build_onos
A.R Karthick5c5d32f2017-01-13 17:41:21 -080084 ret=$?
A.R Karthickcfe5ae92017-01-13 16:01:20 -080085 if [ $ret -ne 0 ]; then
86 echo "Failed to build ONOS. Exiting"
87 exit 127
88 fi
89 onos_package=$mydir/onos.tar.gz
A R Karthick49bf8252016-12-07 14:11:51 -080090 else
A R Karthickbff105f2016-12-07 15:32:15 -080091 if [ $onos_update -eq 1 ]; then
92 echo "Updating ONOS source"
93 ( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . )
94 fi
A.R Karthickcfe5ae92017-01-13 16:01:20 -080095 ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
96 echo "ONOS build failure. Exiting ..." && exit 1
97 }
98 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
A R Karthick49bf8252016-12-07 14:11:51 -080099 fi
A R Karthick49bf8252016-12-07 14:11:51 -0800100fi
101
102if [ ! -f $onos_package ]; then
103 echo "ONOS package $onos_package does not exist. Exiting ..."
104 exit 1
105fi
106
A.R Karthickcfe5ae92017-01-13 16:01:20 -0800107if [ $onos_package != $mydir/onos.tar.gz ]; then
108 cp -v $onos_package $mydir/onos.tar.gz
109fi
A R Karthick49bf8252016-12-07 14:11:51 -0800110
111function finish {
A R Karthick49bf8252016-12-07 14:11:51 -0800112 rm -f onos.tar.gz
113 rm -f Dockerfile.cord-tester
114}
115
116trap finish EXIT
117
118#create a ONOS docker file
119cat > $mydir/Dockerfile.cord-tester <<EOF
120FROM onosproject/onos:latest
121
122MAINTAINER Ali Al-Shabibi <ali@onlab.us>
123
124# Add Java 8 repository
125# Set the environment variables
126ENV HOME /root
127ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
128ENV ONOS_ROOT /src/onos
A.R Karthickdda22062017-02-09 14:39:20 -0800129ENV KARAF_VERSION 3.0.8
130ENV KARAF_ROOT /root/onos/apache-karaf-3.0.8
131ENV KARAF_LOG /root/onos/apache-karaf-3.0.8/data/log/karaf.log
A R Karthick49bf8252016-12-07 14:11:51 -0800132ENV BUILD_NUMBER docker
133ENV PATH \$PATH:\$KARAF_ROOT/bin
134
135#Download and Build ONOS
136# Change to /root directory
137WORKDIR /root
138COPY ./onos.tar.gz /tmp
139#Install ONOS
140
141RUN rm -rf onos && mkdir onos && \
142 mv /tmp/onos.tar.gz . && \
143 tar -xf onos.tar.gz -C onos --strip-components=1 && \
144 rm -rf onos.tar.gz
145
146
147# Ports
148# 6653 - OpenFlow
149# 8181 - GUI
150# 8101 - ONOS CLI
151# 9876 - ONOS CLUSTER COMMUNICATION
A.R Karthickdda22062017-02-09 14:39:20 -0800152EXPOSE 6653 8181 8101 9876 5005
A R Karthick49bf8252016-12-07 14:11:51 -0800153
154# Get ready to run command
155WORKDIR /root/onos
156ENTRYPOINT ["./bin/onos-service"]
157EOF
158
159#Now build the docker image
A R Karthick49bf8252016-12-07 14:11:51 -0800160docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir