Closed DrMartiner closed 1 year ago
Hi, fellow user here. Hopefully I can help.
It appears that in the first job, you're using kaniko with --cache-dir=/cache
as though you're trying to populate the /cache directory with what's built.
The right way to populate the cache is by using kaniko warmer as documented here: https://github.com/GoogleContainerTools/kaniko#caching-base-images
Since you want to build your image and populate the cache with that image in one job, you'll probably want to play with kaniko warmer pulling down some dockerhub images to see how it populates the cache, and then replicate that process with your first build job, so that the PVC is properly setup with the files how kaniko expects them to be, as if kaniko warmer had been used to download it from your repo.
@DrMartiner were you able to get caching working here with the information in https://github.com/GoogleContainerTools/kaniko#caching-base-images and that @tspearconquest provided?
Closing this as I believe this is related to UX friction and not an issue with kaniko's caching directly. As @tspearconquest mentioned:
It appears that in the first job, you're using kaniko with --cache-dir=/cache as though you're trying to populate the /cache directory with what's built.
The right way to populate the cache is by using kaniko warmer as documented here: https://github.com/GoogleContainerTools/kaniko#caching-base-images
Actual behavior kaniko could't cache layers to
/cache
Expected behavior Kaniko will save layers to
/cache
and reuse the ones.To Reproduce Steps to reproduce the behavior:
PS: I run GitLab runner in k8s
Additional Information
.build_kaniko: image: name: gcr.io/kaniko-project/executor:debug entrypoint: [ "" ] services:
build_base: stage: build_base extends: .build_kaniko variables: DESTINATION: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}_base DOCKER_FILE_PATH: ".docker/Dockerfile.base"
build: stage: build extends: .build_kaniko variables: DESTINATION: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REFNAME}${CI_COMMIT_SHORT_SHA} BUILD_ARGS: --build-arg BASE_IMAGE=${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}_base CACHE_ARGS: --cache-repo ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}_base
ENV WORK_DIR "/application/src"
RUN mkdir -p ${WORK_DIR} WORKDIR ${WORK_DIR}
RUN pip install --no-cache-dir poetry &&\ poetry config virtualenvs.create false ADD poetry.lock . ADD pyproject.toml . RUN poetry install