ONOS docker image is going on a diet.

Refactored the Dockerfile to use a multi-stage build which allows us to
separate build environment from runtime environment.
Also added labels.

Change-Id: I9bdf63d9224711c5b5ed342bbe233a26d51283a9
diff --git a/Dockerfile b/Dockerfile
index ed5242d..82085e7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,16 +1,9 @@
-FROM debian:jessie
-MAINTAINER Ali Al-Shabibi <ali@onlab.us>
-
-# 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
+# First stage is the build environment
+FROM sgrio/java-oracle:jdk_8 as builder
+MAINTAINER Jonathan Hart <jono@opennetworking.org>
 
 # Set the environment variables
 ENV HOME /root
-ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
 ENV BUILD_NUMBER docker
 ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
 
@@ -18,38 +11,45 @@
 COPY . /src/onos/
 
 # Build ONOS
+# We extract the tar in the build environment to avoid having to put the tar
+# in the runtime environment - this saves a lot of space
 # FIXME - dependence on ONOS_ROOT and git at build time is a hack to work around
 # build problems
-WORKDIR /src
-RUN     apt-get update && \
-        apt-get install -y python less zip curl oracle-java8-installer oracle-java8-set-default ssh git && \
-        cd onos && \
-        ONOS_ROOT=/src/onos && \
-        export ONOS_ROOT && \
+WORKDIR /src/onos
+RUN apt-get update && apt-get install -y zip python git && \
+        export ONOS_ROOT=/src/onos && \
         tools/build/onos-buck build onos && \
-        cp buck-out/gen/tools/package/onos-package/onos.tar.gz /tmp/ && \
-        cd .. && \
-        rm -rf onos && \
-        apt-get clean && apt-get purge -y && apt-get autoremove -y && \
-        rm -rf /var/lib/apt/lists/* && \
-        rm -rf /var/cache/oracle-jdk8-installer
+        mkdir -p /src/tar && \
+        cd /src/tar && \
+        tar -xf /src/onos/buck-out/gen/tools/package/onos-package/onos.tar.gz --strip-components=1 && \
+        rm -rf /src/onos/buck-out
+
+
+# Second stage is the runtime environment
+FROM anapsix/alpine-java:8_server-jre
 
 # Change to /root directory
-WORKDIR /root
+RUN apk update && \
+        apk add curl && \
+        mkdir -p /root/onos
+WORKDIR /root/onos
 
 # Install ONOS
-RUN mkdir onos && \
-   mv /tmp/onos.tar.gz . && \
-   tar -xf onos.tar.gz -C onos --strip-components=1 && \
-   rm -rf onos.tar.gz
+COPY --from=builder /src/tar/ .
 
+LABEL org.label-schema.name="ONOS" \
+      org.label-schema.description="SDN Controller" \
+      org.label-schema.usage="http://wiki.onosproject.org" \
+      org.label-schema.url="http://onosproject.org" \
+      org.label-scheme.vendor="Open Networking Foundation" \
+      org.label-schema.schema-version="1.0"
 
 # Ports
 # 6653 - OpenFlow
 # 6640 - OVSDB
 # 8181 - GUI
 # 8101 - ONOS CLI
-# 9876 - ONOS CLUSTER COMMUNICATION
+# 9876 - ONOS intra-cluster communication
 EXPOSE 6653 6640 8181 8101 9876
 
 # Get ready to run command