Skip to content

GitLab, Kaniko and Kaniko's caching mechanism

https://docs.gitlab.com/ee/ci/docker/using_kaniko.html shows how to build images with Kaniko:

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
  only:
    - tags

If one uses the shared runners provided by GitLab, building images is quite slow since caching cannot be used. The documentation for Building Docker images with GitLab and dind shows a way to speed up caching. But this solution does not work with Kaniko.

According to the Kaniko documentations one should be able to cache layers by adding the flag cache=true. So the script tag would be changed to:

  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --cache=true --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG

Notice the extra --cache=true. The problem here is that it does not work. In my example the job ends in about 10 seconds with this text at the end of the log.

INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image python:3.6-alpine     
INFO[0001] Downloading base image p
Job's log exceeded limit of 4194304 bytes.

Any suggestions on how to solve this? Is it a bug?