A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function 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 | |
| 8 | OPTIND=1 |
| 9 | onos_src_dir="$HOME/onos" |
| 10 | onos_tag="test/onos:clustertest" |
| 11 | onos_package= |
| 12 | onos_build=0 |
| 13 | |
| 14 | while 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 |
| 35 | done |
| 36 | |
| 37 | shift $((OPTIND-1)) |
| 38 | if [ $# -gt 0 ]; then |
| 39 | echo "Invalid arguments" |
| 40 | show_help |
| 41 | fi |
| 42 | mydir=$(dirname $0) |
| 43 | if [ 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 |
| 48 | fi |
| 49 | |
| 50 | onos_cloned=0 |
| 51 | |
| 52 | #if onos package is not built, then exit |
| 53 | if [ $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 |
| 65 | fi |
| 66 | |
| 67 | if [ ! -f $onos_package ]; then |
| 68 | echo "ONOS package $onos_package does not exist. Exiting ..." |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | cp -v $onos_package $mydir |
| 73 | |
| 74 | function 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 | |
| 82 | trap finish EXIT |
| 83 | |
| 84 | #create a ONOS docker file |
| 85 | cat > $mydir/Dockerfile.cord-tester <<EOF |
| 86 | FROM onosproject/onos:latest |
| 87 | |
| 88 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 89 | |
| 90 | # Add Java 8 repository |
| 91 | # Set the environment variables |
| 92 | ENV HOME /root |
| 93 | ENV JAVA_HOME /usr/lib/jvm/java-8-oracle |
| 94 | ENV ONOS_ROOT /src/onos |
| 95 | ENV KARAF_VERSION 3.0.5 |
| 96 | ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5 |
| 97 | ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log |
| 98 | ENV BUILD_NUMBER docker |
| 99 | ENV PATH \$PATH:\$KARAF_ROOT/bin |
| 100 | |
| 101 | #Download and Build ONOS |
| 102 | # Change to /root directory |
| 103 | WORKDIR /root |
| 104 | COPY ./onos.tar.gz /tmp |
| 105 | #Install ONOS |
| 106 | |
| 107 | RUN 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 |
| 118 | EXPOSE 6653 8181 8101 9876 |
| 119 | |
| 120 | # Get ready to run command |
| 121 | WORKDIR /root/onos |
| 122 | ENTRYPOINT ["./bin/onos-service"] |
| 123 | EOF |
| 124 | |
| 125 | #Now build the docker image |
| 126 | |
| 127 | docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir |