GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.23k stars 1.4k forks source link

Is there way to create local cache without running /kaniko/warmer command? #3186

Open IdeoG opened 1 month ago

IdeoG commented 1 month ago

Actual behavior Hey community, I have a multistage build, when I create a base layer with kaniko and then use it in three other images as the base image. We run kaniko build in gitlab ci using kubernetes executor.

Here is a source code of my job to build images:

build_and_push:
  needs:
    - job: tag
  image:
    name: gcr.io/kaniko-project/executor:v1.23.0-debug
    entrypoint: [ "" ]
  cache:
    paths:
       - /cache
  script:
    - >-
      /kaniko/executor
      --build-arg TAG=${TAG}
      --build-arg REGISTRY="${ECR_REGISTRY}"
      --cache=true
      --context "."
      --dockerfile "./deploy/base/Dockerfile"
      --destination "${ECR_REGISTRY}/backend:base-${TAG}"
    - >-
      /kaniko/executor
      --build-arg TAG=${TAG}
      --build-arg REGISTRY="${ECR_REGISTRY}"
      --cache=true
      --context "."
      --dockerfile "./deploy/backend/Dockerfile"
      --destination "${ECR_REGISTRY}/backend:${TAG}" &
      /kaniko/executor
      --build-arg TAG=${TAG}
      --build-arg REGISTRY="${ECR_REGISTRY}"
      --cache=true
      --context "."
      --dockerfile "./deploy/cron/Dockerfile"
      --destination "${ECR_REGISTRY}/backend:cron-${TAG}" &
      /kaniko/executor
      --build-arg TAG=${TAG}
      --build-arg REGISTRY="${ECR_REGISTRY}"
      --cache=true
      --context "."
      --dockerfile "./deploy/admin/Dockerfile"
      --destination "${ECR_REGISTRY}/backend:admin-${TAG}" &
      wait

Expected behavior

  1. /kaniko/executor command on the base image creates the local cache in /cache dir and 3 other images are using them.
  2. a simple restart of the job above will not build the base image again, but find it in /cache directory.

To Reproduce

  1. make the multistage build.
  2. run and restart the job.

Additional Information