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 |
| 46 | mydir=$(dirname $0) |
| 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 | |
| 54 | onos_cloned=0 |
| 55 | |
| 56 | #if onos package is not built, then exit |
| 57 | if [ $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 Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 63 | 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 Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 67 | 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 |
| 72 | fi |
| 73 | |
| 74 | if [ ! -f $onos_package ]; then |
| 75 | echo "ONOS package $onos_package does not exist. Exiting ..." |
| 76 | exit 1 |
| 77 | fi |
| 78 | |
| 79 | cp -v $onos_package $mydir |
| 80 | |
| 81 | function 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 | |
| 89 | trap finish EXIT |
| 90 | |
| 91 | #create a ONOS docker file |
| 92 | cat > $mydir/Dockerfile.cord-tester <<EOF |
| 93 | FROM onosproject/onos:latest |
| 94 | |
| 95 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 96 | |
| 97 | # Add Java 8 repository |
| 98 | # Set the environment variables |
| 99 | ENV HOME /root |
| 100 | ENV JAVA_HOME /usr/lib/jvm/java-8-oracle |
| 101 | ENV ONOS_ROOT /src/onos |
| 102 | ENV KARAF_VERSION 3.0.5 |
| 103 | ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5 |
| 104 | ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log |
| 105 | ENV BUILD_NUMBER docker |
| 106 | ENV PATH \$PATH:\$KARAF_ROOT/bin |
| 107 | |
| 108 | #Download and Build ONOS |
| 109 | # Change to /root directory |
| 110 | WORKDIR /root |
| 111 | COPY ./onos.tar.gz /tmp |
| 112 | #Install ONOS |
| 113 | |
| 114 | RUN 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 |
| 125 | EXPOSE 6653 8181 8101 9876 |
| 126 | |
| 127 | # Get ready to run command |
| 128 | WORKDIR /root/onos |
| 129 | ENTRYPOINT ["./bin/onos-service"] |
| 130 | EOF |
| 131 | |
| 132 | #Now build the docker image |
| 133 | |
| 134 | docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir |