content_image/858009.jpg
Example 25-4 demonstrates such a template for a build with three steps: 

1. Create a Java JAR file with mvn package . 

2. Create a Dockerfile that copies this JAR file into a container image and starts it with java -jar . 

3. Create and push a container image with a builder image using Kaniko. Kaniko is a tool created by Google for building container images from a Dockerfile inside a container with a local Docker daemon running in user space. 

A template is more or less the same as a Build with the exception that it supports parameters such as placeholders, which are filled in when the template is used. In this example, IMAGE  is the single parameter required to specify the target image to create. 

apiVersion : build.knative.dev/v1alpha1 kind : BuildTemplate metadata : name : maven-kaniko spec : parameters : - name : IMAGE description : steps : - name : maven-build image : gcr.io/cloud-builders/mvn args : - package workingDir : /workspace - name : prepare-docker-context image : alpine command : [ .... ] - name : image-build-and-push image : gcr.io/kaniko-project/executor args : - --context=/workspace - --destination=${IMAGE} 

A list of parameters to be provided when the template is used 

<img src='content_image/858009.jpg'>

Step for compiling and packaging a Java application by using Maven 

Step for creating a Dockerfile for copying and starting the generated JAR file. The details are left out here but can be found in our example GitHub repository. 

Step for calling Kaniko to build and push the Docker image 

