caching tekton pipeline using kaniko image

12/25/2021

I want to cache Dockerfile layers in my local linux system using tekton. for that, I followed this link : https://zhimin-wen.medium.com/caching-for-building-spring-boot-app-image-with-kaniko-48563750bf3a

but ,for me it does not work. I am using two pv. one for maven dependencies and another for caching docker file layers. only maven dependencies are stored in pv. how can I cache docker file layers also ???

build task:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simplemaven-build-and-push
spec:
  resources:
    inputs:
      - name: repo
        type: git
  steps:
    - name: mvn-build-and-push
      image: gcr.io/kaniko-project/executor
      env:
        - name: DOCKER_CONFIG
          value: /tekton/home/.docker
      command:
        - /kaniko/executor
        - --dockerfile=Dockerfile
        - --context=/workspace/repo/
        - --destination=saiful31/smmaven
        - --cache=true
        - --cache-dir=/image-cache
      volumeMounts:
        - name: image-cache
          mountPath: /image-cache
        - name: m2-cache
          mountPath: /root/.m2
  volumes:
     - name: image-cache
       persistentVolumeClaim:
         claimName: kaniko-cache2
     - name: m2-cache
       persistentVolumeClaim:
         claimName: kanikomaven-cache2

log of taskrun:

TaskRun started: simplemaven-build-and-push-run-rzfz4
[mvn-build-and-push] INFO[0009] Resolved base name maven:3.6.0-jdk-11-slim to build
[mvn-build-and-push] INFO[0009] Retrieving image manifest maven:3.6.0-jdk-11-slim
[mvn-build-and-push] INFO[0009] Retrieving image maven:3.6.0-jdk-11-slim from registry index.docker.io
[mvn-build-and-push] INFO[0013] Retrieving image manifest maven:3.6.0-jdk-11-slim
[mvn-build-and-push] INFO[0013] Returning cached image manifest
[mvn-build-and-push] INFO[0014] Retrieving image manifest openjdk:11-jre-slim
[mvn-build-and-push] INFO[0014] Retrieving image openjdk:11-jre-slim from registry index.docker.io
[mvn-build-and-push] INFO[0016] Retrieving image manifest openjdk:11-jre-slim
[mvn-build-and-push] INFO[0016] Returning cached image manifest
[mvn-build-and-push] INFO[0017] Built cross stage deps: map[0:[/home/app/target/demo-0.0.1-SNAPSHOT.jar]]
[mvn-build-and-push] INFO[0017] Retrieving image manifest maven:3.6.0-jdk-11-slim
[mvn-build-and-push] INFO[0017] Returning cached image manifest
[mvn-build-and-push] INFO[0017] Retrieving image manifest maven:3.6.0-jdk-11-slim
[mvn-build-and-push] INFO[0017] Returning cached image manifest
[mvn-build-and-push] INFO[0017] Executing 0 build triggers
[mvn-build-and-push] INFO[0017] Checking for cached layer index.docker.io/saiful31/smmaven/cache:c4ceb0662bfab88e1ba01c026010b1c3e1cebaec7b505681b6f1e76e17cf8674...
[mvn-build-and-push] INFO[0021] No cached layer found for cmd RUN mvn -f /home/app/pom.xml clean package
[mvn-build-and-push] INFO[0021] Unpacking rootfs as cmd COPY src /home/app/src requires it.
[mvn-build-and-push] INFO[0066] COPY src /home/app/src
[mvn-build-and-push] INFO[0066] Taking snapshot of files...
[mvn-build-and-push] INFO[0066] COPY pom.xml /home/app
[mvn-build-and-push] INFO[0066] Taking snapshot of files...
[mvn-build-and-push] INFO[0066] RUN mvn -f /home/app/pom.xml clean package
[mvn-build-and-push] INFO[0066] Taking snapshot of full filesystem...
[mvn-build-and-push] INFO[0069] cmd: /bin/sh
[mvn-build-and-push] INFO[0069] args: [-c mvn -f /home/app/pom.xml clean package]
[mvn-build-and-push] INFO[0069] Running: [/bin/sh -c mvn -f /home/app/pom.xml clean package]
[mvn-build-and-push] [INFO] BUILD SUCCESS
[mvn-build-and-push] [INFO] ------------------------------------------------------------------------
[mvn-build-and-push] [INFO] Total time:  13.210 s
[mvn-build-and-push] [INFO] Finished at: 2021-12-25T16:16:37Z
[mvn-build-and-push] [INFO] ------------------------------------------------------------------------
[mvn-build-and-push] INFO[0092] Retrieving image manifest openjdk:11-jre-slim
[mvn-build-and-push] INFO[0092] Returning cached image manifest
[mvn-build-and-push] INFO[0092] Retrieving image manifest openjdk:11-jre-slim
[mvn-build-and-push] INFO[0092] Returning cached image manifest
[mvn-build-and-push] INFO[0092] Executing 0 build triggers
[mvn-build-and-push] INFO[0092] cmd: EXPOSE
[mvn-build-and-push] INFO[0092] Adding exposed port: 8080/tcp
[mvn-build-and-push] INFO[0092] cmd: EXPOSE
[mvn-build-and-push] INFO[0092] Adding exposed port: 8080/tcp
[mvn-build-and-push] INFO[0092] Unpacking rootfs as cmd COPY --from=build /home/app/target/demo-0.0.1-SNAPSHOT.jar /usr/local/lib/demo.jar requires it.
[mvn-build-and-push] INFO[0099] COPY --from=build /home/app/target/demo-0.0.1-SNAPSHOT.jar /usr/local/lib/demo.jar
[mvn-build-and-push] INFO[0099] Taking snapshot of files...
[mvn-build-and-push] INFO[0099] EXPOSE 8080
[mvn-build-and-push] INFO[0099] cmd: EXPOSE
[mvn-build-and-push] INFO[0099] Adding exposed port: 8080/tcp
[mvn-build-and-push] INFO[0099] No files changed in this command, skipping snapshotting.
[mvn-build-and-push] INFO[0099] ENTRYPOINT ["java","-jar","/usr/local/lib/demo.jar"]
[mvn-build-and-push] INFO[0099] No files changed in this command, skipping snapshotting.
[mvn-build-and-push] INFO[0099] Pushing image to saiful31/smmaven
-- tamjidul islam
continuous-integration
devops
kaniko
kubernetes
tekton

0 Answers