blob: efb413c9a872b775188c633f8d85de0e86e895d4 [file] [log] [blame]
A R Karthick49bf8252016-12-07 14:11:51 -08001#!/usr/bin/env bash
2
3function show_help {
4 echo "Usage: ${0#*/} -h | this help -o <onos source path> -t <onos docker tag> -p <onos package> -b | build onos package"
5 exit 1
6}
7
8OPTIND=1
9onos_src_dir="$HOME/onos"
10onos_tag="test/onos:clustertest"
11onos_package=
12onos_build=0
13
14while getopts "h?o:t:p:b" opt; do
15 case "$opt" in
16 h|\?)
17 show_help
18 ;;
19 o)
20 onos_src_dir=$OPTARG
21 ;;
22 p)
23 onos_package=$OPTARG
24 ;;
25 t)
26 onos_tag=$OPTARG
27 ;;
28 b)
29 onos_build=1
30 ;;
31 *)
32 show_help
33 ;;
34 esac
35done
36
37shift $((OPTIND-1))
38if [ $# -gt 0 ]; then
39 echo "Invalid arguments"
40 show_help
41fi
42mydir=$(dirname $0)
43if [ x"$onos_package" = "x" ]; then
44 if [ ! -d $onos_src_dir ]; then
45 onos_build=1
46 fi
47 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
48fi
49
50onos_cloned=0
51
52#if onos package is not built, then exit
53if [ $onos_build -eq 1 ]; then
54 if [ ! -d $onos_src_dir ]; then
55 mkdir -p $onos_src_dir
56 onos_cloned=1
57 ( cd $onos_src_dir && git clone http://github.com/opennetworkinglab/onos.git . )
58 else
59 ( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . )
60 fi
61 ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
62 echo "ONOS build failure. Exiting ..." && exit 1
63 }
64 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
65fi
66
67if [ ! -f $onos_package ]; then
68 echo "ONOS package $onos_package does not exist. Exiting ..."
69 exit 1
70fi
71
72cp -v $onos_package $mydir
73
74function finish {
75 if [ $onos_cloned -eq 1 ]; then
76 rm -rf $onos_src_dir
77 fi
78 rm -f onos.tar.gz
79 rm -f Dockerfile.cord-tester
80}
81
82trap finish EXIT
83
84#create a ONOS docker file
85cat > $mydir/Dockerfile.cord-tester <<EOF
86FROM onosproject/onos:latest
87
88MAINTAINER Ali Al-Shabibi <ali@onlab.us>
89
90# Add Java 8 repository
91# Set the environment variables
92ENV HOME /root
93ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
94ENV ONOS_ROOT /src/onos
95ENV KARAF_VERSION 3.0.5
96ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5
97ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log
98ENV BUILD_NUMBER docker
99ENV PATH \$PATH:\$KARAF_ROOT/bin
100
101#Download and Build ONOS
102# Change to /root directory
103WORKDIR /root
104COPY ./onos.tar.gz /tmp
105#Install ONOS
106
107RUN rm -rf onos && mkdir onos && \
108 mv /tmp/onos.tar.gz . && \
109 tar -xf onos.tar.gz -C onos --strip-components=1 && \
110 rm -rf onos.tar.gz
111
112
113# Ports
114# 6653 - OpenFlow
115# 8181 - GUI
116# 8101 - ONOS CLI
117# 9876 - ONOS CLUSTER COMMUNICATION
118EXPOSE 6653 8181 8101 9876
119
120# Get ready to run command
121WORKDIR /root/onos
122ENTRYPOINT ["./bin/onos-service"]
123EOF
124
125#Now build the docker image
126
127docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir