why build when you can download

Change-Id: I1171418d892ad93b4d5c6d0eebcfd5941ec895aa
diff --git a/docker/Dockerfile.onos b/docker/Dockerfile.onos
index 8202767..bb12c15 100644
--- a/docker/Dockerfile.onos
+++ b/docker/Dockerfile.onos
@@ -1,87 +1,54 @@
-FROM sgrio/java-oracle:jdk_8 as build
-
-# Install and configure build tools
-ENV JAVA_OPTS="${JAVA_OPTS:--DenableOFTLS=true -Djavax.net.ssl.keyStore=/home/sdn/wiki/onos.jks -Djavax.net.ssl.keyStorePassword=222222 -Djavax.net.ssl.trustStore=/home/sdn/wiki/onos.jks -Djavax.net.ssl.trustStorePassword=222222}"
-
-RUN apt-get update && apt-get install -y git unzip maven curl python
-RUN curl -sSL http://commondatastorage.googleapis.com/git-repo-downloads/repo -o /bin/repo && chmod 755 /bin/repo
-
-# The ENV settings for ONOS, KARAF_VERSION, KARAF_ROOT, KARAF_M2, and APPS_ROOT
-# must be replicated below to the final image as they are shared between stages
-ENV ONOS=/root/onos
-ENV APPS_ROOT=${ONOS}/apps
-ENV KARAF_VERSION=3.0.8
-ENV KARAF_ROOT=${ONOS}/apache-karaf-${KARAF_VERSION}
-ENV KARAF_M2=${KARAF_ROOT}/system
-ENV MANIFEST_BRANCH=master
-ENV BUILD_ROOT=/build
-ENV APP_INSTALL_ROOT=/expand
-
-# Build the applications
-RUN mkdir -p ${BUILD_ROOT}
-WORKDIR ${BUILD_ROOT}
-RUN repo init -u http://gerrit.opencord.org/manifest -b ${MANIFEST_BRANCH} -g onos && repo sync
-WORKDIR ${BUILD_ROOT}/onos-apps/apps
-RUN mvn -DskipTests=true clean install
-
-FROM onosproject/onos:1.10.3 as integration
+FROM maven:3-jdk-8-alpine as download
 MAINTAINER Open Networking Foundation <info@opennetworking.org>
 
-# The ENV settings for ONOS, KARAF_VERSION, KARAF_ROOT, KARAF_M2, and APPS_ROOT
-# must be replicated below to the final image as they are shared between stages
+#RUN apt-get update && apt-get install -y maven
+
+# The ENV settings must be replicated below as they are not shared between stages
+ENV DOWNLOAD_ROOT=/download
+
+# Build the applications
+RUN mkdir -p ${DOWNLOAD_ROOT}
+WORKDIR ${DOWNLOAD_ROOT}
+ADD config/dependencies.xml .
+RUN mvn dependency:copy -Dmdep.useBaseVersion=true -DoutputDirectory=${DOWNLOAD_ROOT} -Dsilent=true -f dependencies.xml
+
+FROM onosproject/onos:1.10.3 as install
+MAINTAINER Open Networking Foundation <info@opennetworking.org>
+
+# The ENV settings must be replicated below as they are not shared between stages
 ENV ONOS=/root/onos
-ENV APPS_ROOT=${ONOS}/apps
 ENV KARAF_VERSION=3.0.8
 ENV KARAF_ROOT=${ONOS}/apache-karaf-${KARAF_VERSION}
+ENV APPS_ROOT=${ONOS}/apps
 ENV KARAF_M2=${KARAF_ROOT}/system
-ENV MANIFEST_BRANCH=master
-ENV BUILD_ROOT=/build
+ENV DOWNLOAD_ROOT=/download
 ENV APP_INSTALL_ROOT=/expand
 
-copy --from=build /build /build
-
-# Specify application versions to install
-ENV AAA_VERSION=1.3.0-SNAPSHOT \
-	CONFIG_VERSION=1.3.0-SNAPSHOT \
-	IGMP_VERSION=1.3.0-SNAPSHOT \
-	IGMP_PROXY_VERSION=1.1.0-SNAPSHOT \
-	MCAST_VERSION=1.3.0-SNAPSHOT \
-	OLT_VERSION=1.3.0-SNAPSHOT \
-	SADIS_VERSION=1.1.0-SNAPSHOT \
-	VTN_VERSION=1.3.0-SNAPSHOT \
-	L2_DHCP_RELAY_VERSION=1.1.0-SNAPSHOT
-
-ENV APPS="aaa-${AAA_VERSION} \
-	cord-config-${CONFIG_VERSION} \
-	igmp-${IGMP_VERSION} \
-	mcast-${MCAST_VERSION} \
-	olt-app-${OLT_VERSION} \
-	sadis-app-${SADIS_VERSION} \
-	vtn-${VTN_VERSION} \
-        aaa-${AAA_VERSION} \
-        onos-app-igmpproxy-${IGMP_PROXY_VERSION} \
-	dhcpl2relay-${L2_DHCP_RELAY_VERSION}"
+# Copy the downloaded artifact to the install stage container
+COPY --from=download ${DOWNLOAD_ROOT} ${DOWNLOAD_ROOT}
 
 # Install the applications
-COPY config/app-install.sh .
+COPY config/app-install.sh ./app-install.sh
 RUN chmod 755 ./app-install.sh
 RUN ./app-install.sh
 
 # Create the final image coping over the installed applications from the build stage
 FROM onosproject/onos:1.10.3
+MAINTAINER Open Networking Foundation <info@opennetworking.org>
 
 # Install Key Store Options
 ENV JAVA_OPTS="${JAVA_OPTS:--DenableOFTLS=true -Djavax.net.ssl.keyStore=/home/sdn/wiki/onos.jks -Djavax.net.ssl.keyStorePassword=222222 -Djavax.net.ssl.trustStore=/home/sdn/wiki/onos.jks -Djavax.net.ssl.trustStorePassword=222222}"
 
+# The ENV settings must be replicated below as they are not shared between stages
 ENV ONOS=/root/onos
 ENV KARAF_VERSION=3.0.8
 ENV KARAF_ROOT=${ONOS}/apache-karaf-${KARAF_VERSION}
 ENV KARAF_M2=${KARAF_ROOT}/system
 ENV APPS_ROOT=${ONOS}/apps
 
-COPY --from=integration ${KARAF_M2}/ ${KARAF_M2}/
+COPY --from=install ${KARAF_M2}/ ${KARAF_M2}/
 RUN echo "${KARAF_M2} ${APPS_ROOT}"
-COPY --from=integration ${APPS_ROOT}/ ${APPS_ROOT}/
+COPY --from=install ${APPS_ROOT}/ ${APPS_ROOT}/
 COPY config/netcfg.json $KARAF_ROOT/../config/network-cfg.json
 
 RUN touch $ONOS/apps/org.onosproject.hostprovider/active
diff --git a/docker/config/app-install.sh b/docker/config/app-install.sh
index ec39263..e33a411 100644
--- a/docker/config/app-install.sh
+++ b/docker/config/app-install.sh
@@ -1,14 +1,10 @@
 #!/bin/bash 
 
 HERE=$(pwd)
-for app in $APPS; do
+OARS=$(find $DOWNLOAD_ROOT -name "*.oar")
+for oar in $OARS; do
     cd $HERE
-    echo "Installing application '$app'"
-    oar=$(find $BUILD_ROOT -path "*/target/*" -name "$app*".oar)
-    if [ "$oar x" == " x" ]; then
-        echo "Required application, $app, not found."
-	exit 1
-    fi
+    echo "Installing application '$oar'"
     rm -rf $APP_INSTALL_ROOT
     mkdir -p $APP_INSTALL_ROOT
     cd $APP_INSTALL_ROOT
diff --git a/docker/config/dependencies.xml b/docker/config/dependencies.xml
new file mode 100644
index 0000000..53afdac
--- /dev/null
+++ b/docker/config/dependencies.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-present Open Networking Foundation
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+         <modelVersion>4.0.0</modelVersion>
+
+    <groupId>fake</groupId>
+    <artifactId>fake</artifactId>
+    <version>fake</version>
+
+    <properties>
+        <aaa.version>1.3.0-SNAPSHOT</aaa.version>
+        <config.version>1.3.0-SNAPSHOT</config.version>
+        <dhcpl2relay.version>1.1.0-SNAPSHOT</dhcpl2relay.version>
+        <igmp.version>1.3.0-SNAPSHOT</igmp.version>
+        <igmpproxy.version>1.1.0-SNAPSHOT</igmpproxy.version>
+        <mcast.version>1.3.0-SNAPSHOT</mcast.version>
+        <olt.version>1.3.0-SNAPSHOT</olt.version>
+        <sadis.version>1.1.0-SNAPSHOT</sadis.version>
+        <vtn.version>1.3.0-SNAPSHOT</vtn.version>
+
+        <!-- TODO onos-build-conf.version can be dropped when onos.version > 1.10.3 -->
+        <onos-build-conf.version>1.10.3-onf</onos-build-conf.version>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <version>3.0.1</version>
+                <configuration>
+                    <artifactItems>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>cord-config</artifactId>
+                            <version>${config.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>igmp</artifactId>
+                            <version>${igmp.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>mcast</artifactId>
+                            <version>${mcast.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>olt-app</artifactId>
+                            <version>${olt.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>sadis-app</artifactId>
+                            <version>${sadis.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>vtn</artifactId>
+                            <version>${vtn.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>aaa</artifactId>
+                            <version>${aaa.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>onos-app-igmpproxy</artifactId>
+                            <version>${igmpproxy.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                        <artifactItem>
+                            <groupId>org.opencord</groupId>
+                            <artifactId>dhcpl2relay</artifactId>
+                            <version>${dhcpl2relay.version}</version>
+                            <type>oar</type>
+                            <overWrite>true</overWrite>
+                        </artifactItem>
+                    </artifactItems>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>central</id>
+            <name>Central Repository</name>
+            <url>http://repo.maven.apache.org/maven2</url>
+            <layout>default</layout>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>always</updatePolicy>
+                <checksumPolicy>fail</checksumPolicy>
+            </releases>
+        </repository>
+
+        <repository>
+            <id>snapshots</id>
+            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>always</updatePolicy>
+                <checksumPolicy>fail</checksumPolicy>
+            </snapshots>
+        </repository>
+    </repositories>
+
+</project>