blob: 039d047a8a6c8c5cd514cde7e91a7159c7e221c7 [file] [log] [blame]
A R Karthick49bf8252016-12-07 14:11:51 -08001#!/usr/bin/env bash
2
3function show_help {
A R Karthickbff105f2016-12-07 15:32:15 -08004 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 -08005 exit 1
6}
7
8OPTIND=1
9onos_src_dir="$HOME/onos"
10onos_tag="test/onos:clustertest"
11onos_package=
12onos_build=0
A R Karthickbff105f2016-12-07 15:32:15 -080013onos_update=0
A R Karthick49bf8252016-12-07 14:11:51 -080014
A R Karthickbff105f2016-12-07 15:32:15 -080015while getopts "h?o:t:p:bu" opt; do
A R Karthick49bf8252016-12-07 14:11:51 -080016 case "$opt" in
17 h|\?)
18 show_help
19 ;;
20 o)
21 onos_src_dir=$OPTARG
22 ;;
23 p)
24 onos_package=$OPTARG
25 ;;
26 t)
27 onos_tag=$OPTARG
28 ;;
29 b)
30 onos_build=1
31 ;;
A R Karthickbff105f2016-12-07 15:32:15 -080032 u)
33 onos_update=1
34 ;;
A R Karthick49bf8252016-12-07 14:11:51 -080035 *)
36 show_help
37 ;;
38 esac
39done
40
41shift $((OPTIND-1))
42if [ $# -gt 0 ]; then
43 echo "Invalid arguments"
44 show_help
45fi
A.R Karthickcfe5ae92017-01-13 16:01:20 -080046mydir=$(dirname $(realpath $0))
A R Karthick49bf8252016-12-07 14:11:51 -080047if [ x"$onos_package" = "x" ]; then
48 if [ ! -d $onos_src_dir ]; then
49 onos_build=1
50 fi
51 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
52fi
53
A.R Karthickcfe5ae92017-01-13 16:01:20 -080054function build_onos {
55 if [ ! -f $mydir/Dockerfile.onos-builder ]; then
56 echo "Dockerfile.onos-builder not found. Copy this file from cord-tester project before resuming the build"
57 exit 127
58 fi
59 docker images | grep ^cord-tester-onos-builder || docker build -t cord-tester-onos-builder:latest -f $mydir/Dockerfile.onos-builder $mydir
60 docker run -v $mydir:/root/cord-tester --rm cord-tester-onos-builder:latest
61 return $?
62}
A R Karthick49bf8252016-12-07 14:11:51 -080063
64#if onos package is not built, then exit
65if [ $onos_build -eq 1 ]; then
66 if [ ! -d $onos_src_dir ]; then
A.R Karthickcfe5ae92017-01-13 16:01:20 -080067 build_onos
A.R Karthick5c5d32f2017-01-13 17:41:21 -080068 ret=$?
A.R Karthickcfe5ae92017-01-13 16:01:20 -080069 if [ $ret -ne 0 ]; then
70 echo "Failed to build ONOS. Exiting"
71 exit 127
72 fi
73 onos_package=$mydir/onos.tar.gz
A R Karthick49bf8252016-12-07 14:11:51 -080074 else
A R Karthickbff105f2016-12-07 15:32:15 -080075 if [ $onos_update -eq 1 ]; then
76 echo "Updating ONOS source"
77 ( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . )
78 fi
A.R Karthickcfe5ae92017-01-13 16:01:20 -080079 ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
80 echo "ONOS build failure. Exiting ..." && exit 1
81 }
82 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
A R Karthick49bf8252016-12-07 14:11:51 -080083 fi
A R Karthick49bf8252016-12-07 14:11:51 -080084fi
85
86if [ ! -f $onos_package ]; then
87 echo "ONOS package $onos_package does not exist. Exiting ..."
88 exit 1
89fi
90
A.R Karthickcfe5ae92017-01-13 16:01:20 -080091if [ $onos_package != $mydir/onos.tar.gz ]; then
92 cp -v $onos_package $mydir/onos.tar.gz
93fi
A R Karthick49bf8252016-12-07 14:11:51 -080094
95function finish {
A R Karthick49bf8252016-12-07 14:11:51 -080096 rm -f onos.tar.gz
97 rm -f Dockerfile.cord-tester
98}
99
100trap finish EXIT
101
102#create a ONOS docker file
103cat > $mydir/Dockerfile.cord-tester <<EOF
104FROM onosproject/onos:latest
105
106MAINTAINER Ali Al-Shabibi <ali@onlab.us>
107
108# Add Java 8 repository
109# Set the environment variables
110ENV HOME /root
111ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
112ENV ONOS_ROOT /src/onos
A.R Karthickdda22062017-02-09 14:39:20 -0800113ENV KARAF_VERSION 3.0.8
114ENV KARAF_ROOT /root/onos/apache-karaf-3.0.8
115ENV KARAF_LOG /root/onos/apache-karaf-3.0.8/data/log/karaf.log
A R Karthick49bf8252016-12-07 14:11:51 -0800116ENV BUILD_NUMBER docker
117ENV PATH \$PATH:\$KARAF_ROOT/bin
118
119#Download and Build ONOS
120# Change to /root directory
121WORKDIR /root
122COPY ./onos.tar.gz /tmp
123#Install ONOS
124
125RUN rm -rf onos && mkdir onos && \
126 mv /tmp/onos.tar.gz . && \
127 tar -xf onos.tar.gz -C onos --strip-components=1 && \
128 rm -rf onos.tar.gz
129
130
131# Ports
132# 6653 - OpenFlow
133# 8181 - GUI
134# 8101 - ONOS CLI
135# 9876 - ONOS CLUSTER COMMUNICATION
A.R Karthickdda22062017-02-09 14:39:20 -0800136EXPOSE 6653 8181 8101 9876 5005
A R Karthick49bf8252016-12-07 14:11:51 -0800137
138# Get ready to run command
139WORKDIR /root/onos
140ENTRYPOINT ["./bin/onos-service"]
141EOF
142
143#Now build the docker image
A R Karthick49bf8252016-12-07 14:11:51 -0800144docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir