CORD-421 added standard label schema to the image builds

Change-Id: Ie2110ac722bdca9f2b07ae21fe9e56a0a3066585
diff --git a/build.gradle b/build.gradle
index aa37a17..6533aa2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -65,8 +65,33 @@
 
 // Switch Configuration Image
 
+def getBuildTimestamp() {
+    def cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
+    def date = cal.getTime()
+    def formattedDate = date.format("yyyy-MM-dd'T'HH:mm:ss.ss'Z'")
+    return formattedDate
+}
+
+def getCommitHash = { ->
+    def hashStdOut = new ByteArrayOutputStream()
+    exec {
+        commandLine "git", "rev-parse", "HEAD"
+        standardOutput = hashStdOut
+    }
+    return hashStdOut.toString().trim()
+}
+
+def getBranchName = { ->
+    def branchStdOut = new ByteArrayOutputStream()
+    exec {
+        commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
+        standardOutput = branchStdOut
+    }
+    return branchStdOut.toString().trim()
+}
+ 
 task buildSwitchqImage(type: Exec) {
-    commandLine "docker", 'build', '-t', 'cord-maas-switchq', './switchq'
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', 'cord-maas-switchq', './switchq'
 }
 
 task tagSwitchqImage(type: Exec) {
@@ -82,7 +107,7 @@
 // Bootstrap Image
 
 task buildBootstrapImage(type: Exec) {
-    commandLine "docker", 'build', '-t', 'cord-maas-bootstrap', './bootstrap'
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', 'cord-maas-bootstrap', './bootstrap'
 }
 
 task tagBootstrapImage(type: Exec) {
@@ -98,7 +123,7 @@
 // IP Allocator Image
 
 task buildAllocationImage(type: Exec) {
-    commandLine "docker", 'build', '-t', 'cord-ip-allocator', './ip-allocator'
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', 'cord-ip-allocator', './ip-allocator'
 }
 
 task tagAllocationImage(type: Exec) {
@@ -114,7 +139,7 @@
 // Provisioner Image
 
 task buildProvisionerImage(type: Exec) {
-    commandLine "docker", 'build', '-t', 'cord-provisioner', './provisioner'
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', 'cord-provisioner', './provisioner'
 }
 
 task tagProvisionerImage(type: Exec) {
@@ -130,7 +155,7 @@
 // Config Generator Image
 
 task buildConfigGeneratorImage(type: Exec) {
-    commandLine "docker", 'build', '-t', 'config-generator', './config-generator'
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', 'config-generator', './config-generator'
 }
 
 task tagConfigGeneratorImage(type: Exec) {
@@ -146,7 +171,7 @@
 // Automation Image
 
 task buildAutomationImage(type: Exec) {
-    commandLine "docker", 'build', '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', "cord-maas-automation", "-f", "./automation/Dockerfile", "./automation"
 }
 
 task tagAutomationImage(type: Exec) {
@@ -162,7 +187,7 @@
 // DHCP Harvester Images
 
 task buildHarvesterImage(type: Exec) {
-    commandLine "docker", 'build', '-t', "cord-dhcp-harvester", "./harvester"
+    commandLine "docker", 'build', '--label', 'org.label-schema.build-date=' + getBuildTimestamp(), '--label', 'org.label-schema.vcs-ref=' + getCommitHash(), '--label', 'org.label-schema.version=' + getBranchName(), '-t', "cord-dhcp-harvester", "./harvester"
 }
 
 task tagHarvesterImage(type: Exec) {