initial revision.
[pipelinelib] / vars / buildcontainer.groovy
diff --git a/vars/buildcontainer.groovy b/vars/buildcontainer.groovy
new file mode 100644 (file)
index 0000000..69763ce
--- /dev/null
@@ -0,0 +1,28 @@
+// Builds a docker container. This requires the kaniko container to be included using agentsetup
+//
+// Mandatory arguments:
+// - context: the relative path in the source repository to the directory where the docker file is located
+// - container: the name of the container to build
+//
+// Optional arguments:
+// - cache: Whether to use the cache for building containers. Defaults to true
+// - dockerfile: Name of the docker file in the context directory. Defaults to Dockerfile
+// - repo: Repository to publish container to. Defaults to the CONTAINER_REGISTRY environment variable
+// - version: Container version to build. Default to the value of the BRANCH_NAME variable 
+//
+def call(Map args) { 
+  def defaults = [ 
+    cache: true, 
+    cachettl: "100000h",
+    dockerfile: 'Dockerfile', 
+    repo: env.CONTAINER_REGISTRY,
+    version: env.BRANCH_NAME
+  ]
+  args = defaults << args
+  container('kaniko') { 
+    sh """
+      echo "Building container with settings: ${args}"
+      /kaniko/executor --dockerfile ${args.dockerfile} --cache=${args.cache} --cache-ttl=${args.cachettl} --context \$(  pwd )/${args.context} --destination ${args.repo}/${args.container}:${args.version}
+    """
+  }
+}