Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Kaniko w/ options --no-push=true --cache=true and --cache-dir="..." leads to error #2456

Open
stawr93 opened this issue Mar 30, 2023 · 6 comments
Labels
area/caching For all bugs related to cache issues area/cli bugs related to kaniko CLI area/documentation For all bugs related to documentation kind/friction kind/question Further information is requested needs-follow-up priority/p2 High impact feature/bug. Will get a lot of users happy

Comments

@stawr93
Copy link

stawr93 commented Mar 30, 2023

I'd like to use caching to directory without publishing layers to any repo/registry.

Actual behavior
Using --no-push=true --cache=true --cache-dir=/some-path options in combine leads to an error:

Error: cache flags invalid: if using cache with --no-push, specify cache repo with --cache-repo

Expected behavior
In case of --no-push=true --cache=true --cache-dir=/some-path Kaniko will cache layers into provided directory and will not push them into any repo.

To Reproduce
Steps to reproduce the behavior:

  1. Run /kaniko/executor --context "<context>" --dockerfile "<path>/Dockerfile" --destination "<some custom tag>" --no-push --cache=true --cache-dir=<some path>

Additional Information

  • Kaniko Image (fully qualified with digest): gcr.io/kaniko-project/executor:v1.9.0-debug

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
@tspearconquest
Copy link

Hi, I'm afraid that's not what --cache-dir= is for.

Flag --cache-dir
Set this flag to specify a local directory cache for base images. Defaults to /cache.

However, this is further clarified in the section on caching base images: https://github.com/GoogleContainerTools/kaniko#caching-base-images

kaniko can cache images in a local directory that can be volume mounted into the kaniko pod. To do so, the cache must first be populated, as it is read-only.

(bolding is mine)

Since the --cache-dir= path is read-only, it should already have a base image in it for use by kaniko, and is intended to avoid downloading an image from dockerhub repeatedly.

If you're simply trying to avoid downloading base images, I recommend you review the link above. If you're trying to build images into this cache directory, you'll want to play around with the kaniko warmer image by using it to retrieve some random images from dockerhub and figure out how the cache looks when it is populated by that tool, then configure your kaniko command line to output the image the same way.

@aaron-prindle aaron-prindle added kind/question Further information is requested needs-follow-up priority/p2 High impact feature/bug. Will get a lot of users happy area/cli bugs related to kaniko CLI area/caching For all bugs related to cache issues kind/friction area/documentation For all bugs related to documentation labels Jun 22, 2023
@aaron-prindle
Copy link
Collaborator

@stawr93 does the information @tspearconquest provided help clarify things? Is there still discussion needed or a possible kaniko bug here given this info? Currently I believe this is working as intended IIUC

@stawr93
Copy link
Author

stawr93 commented Jun 23, 2023

yeah, @tspearconquest 's answer been useful. It might have been my mistake. I think the issue can be closed/resolved.

In the end I decided to use the registry cache as it is the most simple way to share intermediate build artifacts between pipeline runs.

@Chococrok
Copy link

Chococrok commented Jan 3, 2024

Hello, I think the issue is still valid. I used the warmer to populate the cache then used:

docker run --rm -v $PWD:/workspace -it gcr.io/kaniko-project/executor:v1.19.2-debug \
  --context "/workspace" \
  --dockerfile "/workspace/Dockerfile" \
  --tar-path /workspace/result.tar \
  --destination=test \
  --no-push \
  --cache=true \
  --cache-dir "/workspace/cache"

But kaniko is still complaining that I should use --cache-repo

@Chococrok
Copy link

This update fix the thing:

// cacheFlagsValid makes sure the flags passed in related to caching are valid
func cacheFlagsValid() error {
	if !opts.Cache {
		return nil
	}
	// If --cache=true and --no-push=true, then cache repo must be provided
	// since cache can't be inferred from destination
	if opts.CacheRepo == "" && opts.CacheDir == "" && opts.NoPush {
		return errors.New("if using cache with --no-push, specify cache repo with --cache-repo or cache dir with --cache-dir")
	}
	return nil
}

@reitzig
Copy link

reitzig commented Apr 25, 2024

FWIW: For creating reproducible MWEs for issues such as #1246, an "offline" way to combine --no-push with --cache would be very helpful. In my mind, tying the MWE to a repository makes it both less minimal and less reproducible.

Actually, I for one don't even know which --cache-repo to set that both me and maintainers would be able to use without potentially introducing further problems. 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/caching For all bugs related to cache issues area/cli bugs related to kaniko CLI area/documentation For all bugs related to documentation kind/friction kind/question Further information is requested needs-follow-up priority/p2 High impact feature/bug. Will get a lot of users happy
Projects
None yet
Development

No branches or pull requests

5 participants