A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function show_help { |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 4 | 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 Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 5 | exit 1 |
| 6 | } |
| 7 | |
| 8 | OPTIND=1 |
| 9 | onos_src_dir="$HOME/onos" |
| 10 | onos_tag="test/onos:clustertest" |
| 11 | onos_package= |
| 12 | onos_build=0 |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 13 | onos_update=0 |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 14 | |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 15 | while getopts "h?o:t:p:bu" opt; do |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 16 | 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 Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 32 | u) |
| 33 | onos_update=1 |
| 34 | ;; |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 35 | *) |
| 36 | show_help |
| 37 | ;; |
| 38 | esac |
| 39 | done |
| 40 | |
| 41 | shift $((OPTIND-1)) |
| 42 | if [ $# -gt 0 ]; then |
| 43 | echo "Invalid arguments" |
| 44 | show_help |
| 45 | fi |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 46 | mydir=$(dirname $(realpath $0)) |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 47 | if [ 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 |
| 52 | fi |
| 53 | |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 54 | function 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 Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 63 | |
| 64 | #if onos package is not built, then exit |
| 65 | if [ $onos_build -eq 1 ]; then |
| 66 | if [ ! -d $onos_src_dir ]; then |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 67 | build_onos |
A.R Karthick | 5c5d32f | 2017-01-13 17:41:21 -0800 | [diff] [blame] | 68 | ret=$? |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 69 | 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 Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 74 | else |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 75 | 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 Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 79 | ( 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 Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 83 | fi |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 84 | fi |
| 85 | |
| 86 | if [ ! -f $onos_package ]; then |
| 87 | echo "ONOS package $onos_package does not exist. Exiting ..." |
| 88 | exit 1 |
| 89 | fi |
| 90 | |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 91 | if [ $onos_package != $mydir/onos.tar.gz ]; then |
| 92 | cp -v $onos_package $mydir/onos.tar.gz |
| 93 | fi |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 94 | |
| 95 | function finish { |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 96 | rm -f onos.tar.gz |
| 97 | rm -f Dockerfile.cord-tester |
| 98 | } |
| 99 | |
| 100 | trap finish EXIT |
| 101 | |
| 102 | #create a ONOS docker file |
| 103 | cat > $mydir/Dockerfile.cord-tester <<EOF |
| 104 | FROM onosproject/onos:latest |
| 105 | |
| 106 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 107 | |
| 108 | # Add Java 8 repository |
| 109 | # Set the environment variables |
| 110 | ENV HOME /root |
| 111 | ENV JAVA_HOME /usr/lib/jvm/java-8-oracle |
| 112 | ENV ONOS_ROOT /src/onos |
| 113 | ENV KARAF_VERSION 3.0.5 |
| 114 | ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5 |
| 115 | ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log |
| 116 | ENV BUILD_NUMBER docker |
| 117 | ENV PATH \$PATH:\$KARAF_ROOT/bin |
| 118 | |
| 119 | #Download and Build ONOS |
| 120 | # Change to /root directory |
| 121 | WORKDIR /root |
| 122 | COPY ./onos.tar.gz /tmp |
| 123 | #Install ONOS |
| 124 | |
| 125 | RUN 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 |
| 136 | EXPOSE 6653 8181 8101 9876 |
| 137 | |
| 138 | # Get ready to run command |
| 139 | WORKDIR /root/onos |
| 140 | ENTRYPOINT ["./bin/onos-service"] |
| 141 | EOF |
| 142 | |
| 143 | #Now build the docker image |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 144 | docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir |