Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 17 | #!/usr/bin/env bash |
| 18 | |
| 19 | function show_help { |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 20 | 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] | 21 | exit 1 |
| 22 | } |
| 23 | |
| 24 | OPTIND=1 |
| 25 | onos_src_dir="$HOME/onos" |
| 26 | onos_tag="test/onos:clustertest" |
| 27 | onos_package= |
| 28 | onos_build=0 |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 29 | onos_update=0 |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 30 | |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 31 | while getopts "h?o:t:p:bu" opt; do |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 32 | case "$opt" in |
| 33 | h|\?) |
| 34 | show_help |
| 35 | ;; |
| 36 | o) |
| 37 | onos_src_dir=$OPTARG |
| 38 | ;; |
| 39 | p) |
| 40 | onos_package=$OPTARG |
| 41 | ;; |
| 42 | t) |
| 43 | onos_tag=$OPTARG |
| 44 | ;; |
| 45 | b) |
| 46 | onos_build=1 |
| 47 | ;; |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 48 | u) |
| 49 | onos_update=1 |
| 50 | ;; |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 51 | *) |
| 52 | show_help |
| 53 | ;; |
| 54 | esac |
| 55 | done |
| 56 | |
| 57 | shift $((OPTIND-1)) |
| 58 | if [ $# -gt 0 ]; then |
| 59 | echo "Invalid arguments" |
| 60 | show_help |
| 61 | fi |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 62 | mydir=$(dirname $(realpath $0)) |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 63 | if [ x"$onos_package" = "x" ]; then |
| 64 | if [ ! -d $onos_src_dir ]; then |
| 65 | onos_build=1 |
| 66 | fi |
| 67 | onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz |
| 68 | fi |
| 69 | |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 70 | function build_onos { |
| 71 | if [ ! -f $mydir/Dockerfile.onos-builder ]; then |
| 72 | echo "Dockerfile.onos-builder not found. Copy this file from cord-tester project before resuming the build" |
| 73 | exit 127 |
| 74 | fi |
| 75 | docker images | grep ^cord-tester-onos-builder || docker build -t cord-tester-onos-builder:latest -f $mydir/Dockerfile.onos-builder $mydir |
| 76 | docker run -v $mydir:/root/cord-tester --rm cord-tester-onos-builder:latest |
| 77 | return $? |
| 78 | } |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 79 | |
| 80 | #if onos package is not built, then exit |
| 81 | if [ $onos_build -eq 1 ]; then |
| 82 | if [ ! -d $onos_src_dir ]; then |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 83 | build_onos |
A.R Karthick | 5c5d32f | 2017-01-13 17:41:21 -0800 | [diff] [blame] | 84 | ret=$? |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 85 | if [ $ret -ne 0 ]; then |
| 86 | echo "Failed to build ONOS. Exiting" |
| 87 | exit 127 |
| 88 | fi |
| 89 | onos_package=$mydir/onos.tar.gz |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 90 | else |
A R Karthick | bff105f | 2016-12-07 15:32:15 -0800 | [diff] [blame] | 91 | if [ $onos_update -eq 1 ]; then |
| 92 | echo "Updating ONOS source" |
| 93 | ( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . ) |
| 94 | fi |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 95 | ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || { |
| 96 | echo "ONOS build failure. Exiting ..." && exit 1 |
| 97 | } |
| 98 | 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] | 99 | fi |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 100 | fi |
| 101 | |
| 102 | if [ ! -f $onos_package ]; then |
| 103 | echo "ONOS package $onos_package does not exist. Exiting ..." |
| 104 | exit 1 |
| 105 | fi |
| 106 | |
A.R Karthick | cfe5ae9 | 2017-01-13 16:01:20 -0800 | [diff] [blame] | 107 | if [ $onos_package != $mydir/onos.tar.gz ]; then |
| 108 | cp -v $onos_package $mydir/onos.tar.gz |
| 109 | fi |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 110 | |
| 111 | function finish { |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 112 | rm -f onos.tar.gz |
| 113 | rm -f Dockerfile.cord-tester |
| 114 | } |
| 115 | |
| 116 | trap finish EXIT |
| 117 | |
| 118 | #create a ONOS docker file |
| 119 | cat > $mydir/Dockerfile.cord-tester <<EOF |
| 120 | FROM onosproject/onos:latest |
| 121 | |
| 122 | MAINTAINER Ali Al-Shabibi <ali@onlab.us> |
| 123 | |
| 124 | # Add Java 8 repository |
| 125 | # Set the environment variables |
| 126 | ENV HOME /root |
| 127 | ENV JAVA_HOME /usr/lib/jvm/java-8-oracle |
| 128 | ENV ONOS_ROOT /src/onos |
A.R Karthick | dda2206 | 2017-02-09 14:39:20 -0800 | [diff] [blame] | 129 | ENV KARAF_VERSION 3.0.8 |
| 130 | ENV KARAF_ROOT /root/onos/apache-karaf-3.0.8 |
| 131 | ENV KARAF_LOG /root/onos/apache-karaf-3.0.8/data/log/karaf.log |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 132 | ENV BUILD_NUMBER docker |
| 133 | ENV PATH \$PATH:\$KARAF_ROOT/bin |
| 134 | |
| 135 | #Download and Build ONOS |
| 136 | # Change to /root directory |
| 137 | WORKDIR /root |
| 138 | COPY ./onos.tar.gz /tmp |
| 139 | #Install ONOS |
| 140 | |
| 141 | RUN rm -rf onos && mkdir onos && \ |
| 142 | mv /tmp/onos.tar.gz . && \ |
| 143 | tar -xf onos.tar.gz -C onos --strip-components=1 && \ |
| 144 | rm -rf onos.tar.gz |
| 145 | |
| 146 | |
| 147 | # Ports |
| 148 | # 6653 - OpenFlow |
| 149 | # 8181 - GUI |
| 150 | # 8101 - ONOS CLI |
| 151 | # 9876 - ONOS CLUSTER COMMUNICATION |
A.R Karthick | dda2206 | 2017-02-09 14:39:20 -0800 | [diff] [blame] | 152 | EXPOSE 6653 8181 8101 9876 5005 |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 153 | |
| 154 | # Get ready to run command |
| 155 | WORKDIR /root/onos |
| 156 | ENTRYPOINT ["./bin/onos-service"] |
| 157 | EOF |
| 158 | |
| 159 | #Now build the docker image |
A R Karthick | 49bf825 | 2016-12-07 14:11:51 -0800 | [diff] [blame] | 160 | docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir |