Caching for Building Spring Boot App Image with Kaniko

Zhimin Wen
4 min readAug 16, 2020

This paper explores the different cache options to speed up the Spring Boot app image build when using Kaniko with Tekton pipelines.

The sample Spring Boot app

Create a sample Spring Boot app with the Sprint Initializr. Select Maven, add the Spring Web dependency, generate, and download the project zip file.

Unzip it, and create the following Dockerfile to build the image.

FROM maven:3.6.3-jdk-11 AS builder
WORKDIR /workspace
RUN mvn clean install && ls -ltr target
FROM openjdk:11
WORKDIR /app
COPY --from=builder /workspace/target/demo-0.0.1-SNAPSHOT.jar .
CMD ["java", "-jar", "demo-0.0.1-SNAPSHOT.jar"]

Tekton build task

I am using Tekton pipelines with Kaniko to build the container image. The kubernetes environment is OpenShift 4.5.

The Tekton task to build the image is shown below,

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-image
namespace: springboot-app
spec:
params:
- name: pathToDockerFile
default: /workspace/Dockerfile
- name: pathToContext
default: /workspace
- name: imageUrl
default: image-registry.openshift-image-registry.svc:5000/springboot-app

--

--