blob: 9aa9381951faf8c618eae57c9335e3a5f2de9f77 [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
46mydir=$(dirname $0)
47if [ 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
54onos_cloned=0
55
56#if onos package is not built, then exit
57if [ $onos_build -eq 1 ]; then
58 if [ ! -d $onos_src_dir ]; then
59 mkdir -p $onos_src_dir
60 onos_cloned=1
61 ( cd $onos_src_dir && git clone http://github.com/opennetworkinglab/onos.git . )
62 else
A R Karthickbff105f2016-12-07 15:32:15 -080063 if [ $onos_update -eq 1 ]; then
64 echo "Updating ONOS source"
65 ( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . )
66 fi
A R Karthick49bf8252016-12-07 14:11:51 -080067 fi
68 ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
69 echo "ONOS build failure. Exiting ..." && exit 1
70 }
71 onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
72fi
73
74if [ ! -f $onos_package ]; then
75 echo "ONOS package $onos_package does not exist. Exiting ..."
76 exit 1
77fi
78
79cp -v $onos_package $mydir
80
81function finish {
82 if [ $onos_cloned -eq 1 ]; then
83 rm -rf $onos_src_dir
84 fi
85 rm -f onos.tar.gz
86 rm -f Dockerfile.cord-tester
87}
88
89trap finish EXIT
90
91#create a ONOS docker file
92cat > $mydir/Dockerfile.cord-tester <<EOF
93FROM onosproject/onos:latest
94
95MAINTAINER Ali Al-Shabibi <ali@onlab.us>
96
97# Add Java 8 repository
98# Set the environment variables
99ENV HOME /root
100ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
101ENV ONOS_ROOT /src/onos
102ENV KARAF_VERSION 3.0.5
103ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5
104ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log
105ENV BUILD_NUMBER docker
106ENV PATH \$PATH:\$KARAF_ROOT/bin
107
108#Download and Build ONOS
109# Change to /root directory
110WORKDIR /root
111COPY ./onos.tar.gz /tmp
112#Install ONOS
113
114RUN rm -rf onos && mkdir onos && \
115 mv /tmp/onos.tar.gz . && \
116 tar -xf onos.tar.gz -C onos --strip-components=1 && \
117 rm -rf onos.tar.gz
118
119
120# Ports
121# 6653 - OpenFlow
122# 8181 - GUI
123# 8101 - ONOS CLI
124# 9876 - ONOS CLUSTER COMMUNICATION
125EXPOSE 6653 8181 8101 9876
126
127# Get ready to run command
128WORKDIR /root/onos
129ENTRYPOINT ["./bin/onos-service"]
130EOF
131
132#Now build the docker image
133
134docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir