Add setDockerLabels method

* Add mandatory LABEL to the end of the Dockerfile
* User can also add some custom properties

1. Simple usage, which adds mandatory properties to Dockerfile which
is located in current directory
   tools.setDockerfileLabels()

2. Extended usage, add Labels to calico ctl and node images
   def properties = [
     "CALICO_NODE_IMAGE_REPO=${calicoNodeImageRepo}",
     "CALICOCTL_IMAGE_REPO=${calicoCtlImageRepo}",
     "CALICO_VERSION=${calicoVersion}"
   ]
   tools.setDockerfileLabels("./calicoctl/Dockerfile", properties)
   tools.setDockerfileLabels("./calico_node/Dockerfile", properties)

Change-Id: I0f9e6b83d4ffe5fe6a5ff02da50658b9eded5824
diff --git a/src/ci/mcp/Tools.groovy b/src/ci/mcp/Tools.groovy
index fcf1dec..46e8ffb 100644
--- a/src/ci/mcp/Tools.groovy
+++ b/src/ci/mcp/Tools.groovy
@@ -27,6 +27,43 @@
 }
 
 /**
+* Add LABEL to the end of the Dockerfile
+* User can also add some custom properties
+*
+* @param dockerfilePath is the path to Dockerfile, the default is ./Dockerfile
+* @param customProperties a Array of Strings that should be added to mandatory props
+*        in format ["prop1=value1", "prop2=value2"]
+**/
+def setDockerfileLabels(String dockerfilePath = "./Dockerfile", ArrayList customProperties = null){
+
+  if (!fileExists(dockerfilePath)){
+    throw new RuntimeException("Unable to add LABEL to Dockerfile, ${dockerfilePath} doesn't exists")
+  }
+  echo "Updating ${dockerfilePath}"
+
+  def namespace = "com.mirantis.image-specs."
+  def properties = [
+    "gerritProject=${env.GERRIT_PROJECT}",
+    "gerritChangeNumber=${env.GERRIT_CHANGE_NUMBER}",
+    "gerritPatchsetNumber=${env.GERRIT_PATCHSET_NUMBER}",
+    "gerritChangeId=${env.GERRIT_CHANGE_ID}",
+    "gerritPatchsetRevision=${env.GERRIT_PATCHSET_REVISION}"
+  ]
+
+  if (customProperties != null){
+    properties.addAll(customProperties)
+  }
+
+  def metadata = constructString(properties, namespace, " ")
+  sh """
+      cat <<EOF>> ${dockerfilePath}
+      # Apply additional build metadata
+      LABEL ${metadata}
+  """
+  return metadata
+}
+
+/**
 * Return string of mandatory build properties for binaries
 * User can also add some custom properties
 *
diff --git a/src/ci/mcp/Tools.txt b/src/ci/mcp/Tools.txt
index 2c4c1d5..8229970 100644
--- a/src/ci/mcp/Tools.txt
+++ b/src/ci/mcp/Tools.txt
@@ -45,6 +45,24 @@
     server.publishBuildInfo buildInfo
 
 
+setDockerfileLabels
+-------------------
+// simple usage, which adds mandatory properties to Dockerfile which is
+// located in current directory
+tools.setDockerfileLabels()
+
+// extended usage
+// add Labels to calico ctl and node images
+  def properties = [
+    "CALICO_NODE_IMAGE_REPO=${calicoNodeImageRepo}",
+    "CALICOCTL_IMAGE_REPO=${calicoCtlImageRepo}",
+    "CALICO_VERSION=${calicoVersion}"
+  ]
+  tools.setDockerfileLabels("./calicoctl/Dockerfile", properties)
+  tools.setDockerfileLabels("./calico_node/Dockerfile", properties)
+
+
+
 uriByProperties
 ---------------