initial revision.
[pipelinelib] / vars / buildcontainer.groovy
1 // Builds a docker container. This requires the kaniko container to be included using agentsetup
2 //
3 // Mandatory arguments:
4 // - context: the relative path in the source repository to the directory where the docker file is located
5 // - container: the name of the container to build
6 //
7 // Optional arguments:
8 // - cache: Whether to use the cache for building containers. Defaults to true
9 // - dockerfile: Name of the docker file in the context directory. Defaults to Dockerfile
10 // - repo: Repository to publish container to. Defaults to the CONTAINER_REGISTRY environment variable
11 // - version: Container version to build. Default to the value of the BRANCH_NAME variable 
12 //
13 def call(Map args) { 
14   def defaults = [ 
15     cache: true, 
16     cachettl: "100000h",
17     dockerfile: 'Dockerfile', 
18     repo: env.CONTAINER_REGISTRY,
19     version: env.BRANCH_NAME
20   ]
21   args = defaults << args
22   container('kaniko') { 
23     sh """
24       echo "Building container with settings: ${args}"
25       /kaniko/executor --dockerfile ${args.dockerfile} --cache=${args.cache} --cache-ttl=${args.cachettl} --context \$(  pwd )/${args.context} --destination ${args.repo}/${args.container}:${args.version}
26     """
27   }
28 }