Rename flags and default caching to false

Rename --use-cache to --cache, and --cache to --cache-repo to clarify
what the flags are used for. Default caching to false.
This commit is contained in:
Priya Wadhwa 2018-09-24 13:18:42 -07:00
parent 177bd4f40e
commit e2ca1152f4
5 changed files with 12 additions and 11 deletions

View File

@ -92,8 +92,8 @@ func addKanikoOptionsFlags(cmd *cobra.Command) {
RootCmd.PersistentFlags().BoolVarP(&opts.Reproducible, "reproducible", "", false, "Strip timestamps out of the image to make it reproducible")
RootCmd.PersistentFlags().StringVarP(&opts.Target, "target", "", "", "Set the target build stage to build")
RootCmd.PersistentFlags().BoolVarP(&opts.NoPush, "no-push", "", false, "Do not push the image to the registry")
RootCmd.PersistentFlags().StringVarP(&opts.Cache, "cache", "", "", "Specify a registry to use as a cache, otherwise one will be inferred from the destination provided")
RootCmd.PersistentFlags().BoolVarP(&opts.UseCache, "use-cache", "", true, "Use cache when building image")
RootCmd.PersistentFlags().StringVarP(&opts.CacheRepo, "cache-repo", "", "", "Specify a repository to use as a cache, otherwise one will be inferred from the destination provided")
RootCmd.PersistentFlags().BoolVarP(&opts.Cache, "cache", "", false, "Use cache when building image")
}
// addHiddenFlags marks certain flags as hidden from the executor help text

View File

@ -178,7 +178,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
}
}
cacheFlag := "--use-cache=false"
// build kaniko image
additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
@ -189,7 +188,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
ExecutorImage,
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
"-d", kanikoImage, reproducibleFlag,
cacheFlag,
contextFlag, contextPath},
additionalFlags...)...,
)
@ -204,10 +202,12 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
}
// buildCachedImages builds the images for testing caching via kaniko where version is the nth time this image has been built
func (d *DockerFileBuilder) buildCachedImages(imageRepo, cache, dockerfilesPath string, version int) error {
func (d *DockerFileBuilder) buildCachedImages(imageRepo, cacheRepo, dockerfilesPath string, version int) error {
_, ex, _, _ := runtime.Caller(0)
cwd := filepath.Dir(ex)
cacheFlag := "--cache=true"
for dockerfile := range d.TestCacheDockerfiles {
kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version)
kanikoCmd := exec.Command("docker",
@ -218,7 +218,8 @@ func (d *DockerFileBuilder) buildCachedImages(imageRepo, cache, dockerfilesPath
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
"-d", kanikoImage,
"-c", buildContextPath,
"--cache", cache})...,
cacheFlag,
"--cache-repo", cacheRepo})...,
)
if _, err := RunCommandWithoutTest(kanikoCmd); err != nil {

2
pkg/cache/cache.go vendored
View File

@ -57,7 +57,7 @@ func RetrieveLayer(opts *config.KanikoOptions, cacheKey string) (v1.Image, error
// Destination returns the repo where the layer should be stored
// If no cache is specified, one is inferred from the destination provided
func Destination(opts *config.KanikoOptions, cacheKey string) (string, error) {
cache := opts.Cache
cache := opts.CacheRepo
if cache == "" {
destination := opts.Destinations[0]
destRef, err := name.NewTag(destination, name.WeakValidation)

View File

@ -24,7 +24,7 @@ type KanikoOptions struct {
Bucket string
TarPath string
Target string
Cache string
CacheRepo string
Destinations multiArg
BuildArgs multiArg
InsecurePush bool
@ -32,5 +32,5 @@ type KanikoOptions struct {
SingleSnapshot bool
Reproducible bool
NoPush bool
UseCache bool
Cache bool
}

View File

@ -153,7 +153,7 @@ func (s *stageBuilder) build(opts *config.KanikoOptions) error {
if err != nil {
return errors.Wrap(err, "getting key")
}
if command.CacheCommand() && opts.UseCache {
if command.CacheCommand() && opts.Cache {
image, err := cache.RetrieveLayer(opts, cacheKey)
if err == nil {
if err := s.extractCachedLayer(image, command.String()); err != nil {
@ -212,7 +212,7 @@ func (s *stageBuilder) build(opts *config.KanikoOptions) error {
return err
}
// Push layer to cache now along with new config file
if command.CacheCommand() && opts.UseCache {
if command.CacheCommand() && opts.Cache {
if err := pushLayerToCache(opts, cacheKey, layer, command.String()); err != nil {
return err
}