Parameterize the JDK distribution

Update to use modern docker image build targets

Change-Id: I487118f3dc6e1bb79ef67cb1dba9a3bf5dc32306
diff --git a/Dockerfile.make b/Dockerfile.make
index e03fcc0..dc448ea 100644
--- a/Dockerfile.make
+++ b/Dockerfile.make
@@ -29,7 +29,7 @@
 
 # Label image
 ARG org_label_schema_schema_version=1.0
-ARG org_label_schema_name=opencord/mavenrepo
+ARG org_label_schema_name=mavenrepo
 ARG org_label_schema_version=unknown
 ARG org_label_schema_vcs_url=unknown
 ARG org_label_schema_vcs_ref=unknown
diff --git a/Jenkinsfile b/Jenkinsfile
index 1145d63..2ba8d6f 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,3 +1,19 @@
+// 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.
+
+def jdkDistro = '${jdkDistro}'
+
 node ('ubuntu16.04-basebuild-1c-2g') {
   timeout (100) {
     try {
@@ -5,6 +21,13 @@
         checkout([$class: 'RepoScm', currentBranch: true, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true])
       }
       stage ('Build and Publish apps') {
+
+        // Set the JDK version
+        sh 'echo Using JDK distribution: ' + jdkDistro
+        sh 'sudo update-java-alternatives --set ' +jdkDistro
+        sh 'echo Java Version:'
+        sh 'java -version'
+
         configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) {
           sh 'export _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true && cd onos-apps/apps && mvn -s $MAVEN_SETTINGS -e clean deploy'
         }
diff --git a/Jenkinsfile.release b/Jenkinsfile.release
index 03eb0b9..5934ad1 100644
--- a/Jenkinsfile.release
+++ b/Jenkinsfile.release
@@ -16,6 +16,7 @@
 def version = '${version}'
 def nextVersion = '${nextVersion}'
 def branch = '${branch}'
+def jdkDistro = '${jdkDistro}'
 
 def changeVersion(def newVersion) {
     // TODO any other versions we need to account for?
@@ -23,22 +24,28 @@
 }
 
 node ('ubuntu16.04-basebuild-1c-2g') {
-    
+
     sh 'echo Releasing ' + app + ' repository on ' + branch + ' branch'
     sh 'echo Releasing version ' + version + ' and starting ' + nextVersion + '-SNAPSHOT'
-    
+
+    // Set the JDK version
+    sh 'echo Using JDK distribution: ' + jdkDistro
+    sh 'sudo update-java-alternatives --set ' +jdkDistro
+    sh 'echo Java Version:'
+    sh 'java -version'
+
     def userId = wrap([$class: 'BuildUser']) {
        return env.BUILD_USER_ID
     }
 
     stage ('Configure system') {
         echo "Release build triggered by " + userId
-        
+
         sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts'
-        
+
         sh 'git config --global user.name "Jenkins"'
         sh 'git config --global user.email "do-not-reply@opencord.org"'
-        
+
         // GPG key used to sign maven artifacts
         withCredentials([file(credentialsId: 'gpg-creds-maven', variable: 'GPUPG')]) {
             sh 'tar -xvf $GPUPG -C ~'
@@ -47,31 +54,31 @@
 
     stage ('Check out code') {
         cleanWs()
-        
+
         sshagent (credentials: ['gerrit-jenkins-user']) {
             git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user'
 
             sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
         }
     }
-        
+
     stage ('Move to release version') {
         changeVersion(version)
         sh 'git add -A && git commit -m "Release version ' + version + '"'
     }
-    
+
     stage ('Verify code') {
         def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true
-        
+
         if (found == 0) {
             timeout(time: 1, unit: 'HOURS') {
-                metadata = input id: 'manual-verify', 
+                metadata = input id: 'manual-verify',
                 message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?',
                         submitter: userId
             }
         }
     }
-    
+
     // This step is basically to test that everything still builds once the version has
     // been bumped up before we start pushing things publicly
     stage ('Build and Test') {
@@ -84,14 +91,14 @@
             sh 'git push origin HEAD:refs/for/' + branch
         }
     }
-    
+
     stage ('Wait for merge') {
         timeout(time: 1, unit: 'HOURS') {
-            metadata = input id: 'release-build', 
+            metadata = input id: 'release-build',
             message: 'Go to Gerrit and merge the release patch',
                     submitter: userId
         }
-        
+
     }
 
     stage ('Release artifacts') {
@@ -102,7 +109,7 @@
 
     stage ('Wait for release on Sonatype') {
         timeout(time: 1, unit: 'HOURS') {
-            metadata = input id: 'release-build', 
+            metadata = input id: 'release-build',
             message: 'Go to http://oss.sonatype.org and release the artifacts',
                     submitter: userId
         }
@@ -114,7 +121,7 @@
             sh 'git push origin ' + version
         }
     }
-    
+
     stage ('Move to next SNAPSHOT version') {
         def snapshot = nextVersion + '-SNAPSHOT'
         changeVersion(snapshot)
@@ -127,6 +134,6 @@
     stage ('Finish') {
         sh 'echo "Release done! Go to Gerrit and merge snapshot version bump"'
     }
-    
+
 }
 
diff --git a/Makefile b/Makefile
index 3435fb0..04e352b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,38 +1,56 @@
-ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+# Copyright 2019-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.
 
-IMAGE_NAME        ?= opencord/mavenrepo
-DOCKER_REGISTRY   ?= docker-registry:5000
-DEPLOY_DOCKER_TAG ?= candidate
+# Configure shell
+SHELL = bash -e -o pipefail
 
-MAKE_CONFIG       ?= config.mk
-ifeq ($(realpath $(MAKE_CONFIG)),)
-$(info Makefile configuration not found, defaults will be used.)
-else
-$(info Using makefile configuration "$(MAKE_CONFIG)")
-include $(MAKE_CONFIG)
-endif
+ROOT_DIR                 := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+
+VERSION                  ?= $(shell cat ./VERSION)
+
+DOCKER_REGISTRY          ?=
+DOCKER_REPOSITORY        ?=
+DOCKER_BUILD_ARGS        ?=
+DOCKER_TAG               ?= ${VERSION}
+DOCKER_IMAGENAME         := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}mavenrepo:${DOCKER_TAG}
+
+## Docker labels. Only set ref and commit date if committed
+DOCKER_LABEL_VCS_URL     ?= $(shell git remote get-url $(shell git remote))
+DOCKER_LABEL_VCS_REF     ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
+DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
+DOCKER_LABEL_BUILD_DATE  ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
 
 .PHONY: all
-all: build
+all: docker-build
 
-.PHONY: build
-build:
-	docker build -f Dockerfile.make -t $(IMAGE_NAME):$(DEPLOY_DOCKER_TAG) $(ROOT_DIR)
+docker-build:
+	docker build $(DOCKER_BUILD_ARGS) \
+    -t ${DOCKER_IMAGENAME} \
+    --build-arg org_label_schema_version="${VERSION}" \
+    --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+    --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+    --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+    --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+    -f Dockerfile.make ${ROOT_DIR}
+
+docker-push:
+	docker push ${DOCKER_IMAGENAME}
 
 .PHONY: onos
 onos:
 	docker build -t cord/onos:latest -f docker/Dockerfile.onos .
 
-.PHONY: publish
-publish:
-	docker tag $(IMAGE_NAME):$(DEPLOY_DOCKER_TAG) $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(DEPLOY_DOCKER_TAG)
-	docker push $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(DEPLOY_DOCKER_TAG)
-
-.PHONY: clean
-clean:
-	docker rmi $(IMAGE_NAME):$(DEPLOY_DOCKER_TAG) | true
-	docker rmi $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(DEPLOY_DOCKER_TAG) | true
-
 .PHONY: test
 test:
 	@echo "No unit tests at present"
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..0d4d124
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0-dev