Support to build custom ONOS container images on hosts with no devel environment.
Builds a onos devel docker image that can build onos when run.
Change-Id: I00d012ecd085f80f1caad45df09a97c3291fe997
diff --git a/Dockerfile.onos-builder b/Dockerfile.onos-builder
new file mode 100644
index 0000000..6103ce9
--- /dev/null
+++ b/Dockerfile.onos-builder
@@ -0,0 +1,29 @@
+FROM debian:jessie
+MAINTAINER A R Karthick <kramanar@ciena.com>
+
+# Add Java 8 repository
+ENV DEBIAN_FRONTEND noninteractive
+RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
+ echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \
+ echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \
+ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
+
+# Set the environment variables
+ENV HOME /root
+ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
+ENV ONOS_ROOT /src/onos
+ENV KARAF_VERSION 3.0.5
+ENV KARAF_ROOT /root/onos/apache-karaf-3.0.5
+ENV KARAF_LOG /root/onos/apache-karaf-3.0.5/data/log/karaf.log
+ENV BUILD_NUMBER docker
+ENV PATH $PATH:$KARAF_ROOT/bin
+#Download and Build ONOS
+RUN apt-get update && apt-get install -y python git less zip curl oracle-java8-installer oracle-java8-set-default
+RUN mkdir -p /src
+WORKDIR /src
+CMD bash -c "git clone https://github.com/opennetworkinglab/onos.git && \
+ cd onos && \
+ tools/build/onos-buck build onos && \
+ cp buck-out/gen/tools/package/onos-package/onos.tar.gz /root/cord-tester && \
+ rm -rf /src/onos"
+
diff --git a/build-onos-docker.sh b/build-onos-docker.sh
index 9aa9381..5557544 100755
--- a/build-onos-docker.sh
+++ b/build-onos-docker.sh
@@ -43,7 +43,7 @@
echo "Invalid arguments"
show_help
fi
-mydir=$(dirname $0)
+mydir=$(dirname $(realpath $0))
if [ x"$onos_package" = "x" ]; then
if [ ! -d $onos_src_dir ]; then
onos_build=1
@@ -51,24 +51,36 @@
onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
fi
-onos_cloned=0
+function build_onos {
+ if [ ! -f $mydir/Dockerfile.onos-builder ]; then
+ echo "Dockerfile.onos-builder not found. Copy this file from cord-tester project before resuming the build"
+ exit 127
+ fi
+ docker images | grep ^cord-tester-onos-builder || docker build -t cord-tester-onos-builder:latest -f $mydir/Dockerfile.onos-builder $mydir
+ docker run -v $mydir:/root/cord-tester --rm cord-tester-onos-builder:latest
+ return $?
+}
#if onos package is not built, then exit
if [ $onos_build -eq 1 ]; then
if [ ! -d $onos_src_dir ]; then
- mkdir -p $onos_src_dir
- onos_cloned=1
- ( cd $onos_src_dir && git clone http://github.com/opennetworkinglab/onos.git . )
+ build_onos
+ local ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "Failed to build ONOS. Exiting"
+ exit 127
+ fi
+ onos_package=$mydir/onos.tar.gz
else
if [ $onos_update -eq 1 ]; then
echo "Updating ONOS source"
( cd $onos_src_dir && git pull --ff-only origin master || git clone http://github.com/opennetworkinglab/onos.git . )
fi
+ ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
+ echo "ONOS build failure. Exiting ..." && exit 1
+ }
+ onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
fi
- ( cd $onos_src_dir && tools/build/onos-buck build onos ) && echo "ONOS build success" || {
- echo "ONOS build failure. Exiting ..." && exit 1
- }
- onos_package=$onos_src_dir/buck-out/gen/tools/package/onos-package/onos.tar.gz
fi
if [ ! -f $onos_package ]; then
@@ -76,12 +88,11 @@
exit 1
fi
-cp -v $onos_package $mydir
+if [ $onos_package != $mydir/onos.tar.gz ]; then
+ cp -v $onos_package $mydir/onos.tar.gz
+fi
function finish {
- if [ $onos_cloned -eq 1 ]; then
- rm -rf $onos_src_dir
- fi
rm -f onos.tar.gz
rm -f Dockerfile.cord-tester
}
@@ -130,5 +141,4 @@
EOF
#Now build the docker image
-
docker build -t $onos_tag -f $mydir/Dockerfile.cord-tester $mydir