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:
parent
177bd4f40e
commit
e2ca1152f4
|
|
@ -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().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().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().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().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.UseCache, "use-cache", "", true, "Use cache when building image")
|
RootCmd.PersistentFlags().BoolVarP(&opts.Cache, "cache", "", false, "Use cache when building image")
|
||||||
}
|
}
|
||||||
|
|
||||||
// addHiddenFlags marks certain flags as hidden from the executor help text
|
// addHiddenFlags marks certain flags as hidden from the executor help text
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheFlag := "--use-cache=false"
|
|
||||||
// build kaniko image
|
// build kaniko image
|
||||||
additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
|
additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
|
||||||
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
|
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
|
||||||
|
|
@ -189,7 +188,6 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
|
||||||
ExecutorImage,
|
ExecutorImage,
|
||||||
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
|
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
|
||||||
"-d", kanikoImage, reproducibleFlag,
|
"-d", kanikoImage, reproducibleFlag,
|
||||||
cacheFlag,
|
|
||||||
contextFlag, contextPath},
|
contextFlag, contextPath},
|
||||||
additionalFlags...)...,
|
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
|
// 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)
|
_, ex, _, _ := runtime.Caller(0)
|
||||||
cwd := filepath.Dir(ex)
|
cwd := filepath.Dir(ex)
|
||||||
|
|
||||||
|
cacheFlag := "--cache=true"
|
||||||
|
|
||||||
for dockerfile := range d.TestCacheDockerfiles {
|
for dockerfile := range d.TestCacheDockerfiles {
|
||||||
kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version)
|
kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version)
|
||||||
kanikoCmd := exec.Command("docker",
|
kanikoCmd := exec.Command("docker",
|
||||||
|
|
@ -218,7 +218,8 @@ func (d *DockerFileBuilder) buildCachedImages(imageRepo, cache, dockerfilesPath
|
||||||
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
|
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
|
||||||
"-d", kanikoImage,
|
"-d", kanikoImage,
|
||||||
"-c", buildContextPath,
|
"-c", buildContextPath,
|
||||||
"--cache", cache})...,
|
cacheFlag,
|
||||||
|
"--cache-repo", cacheRepo})...,
|
||||||
)
|
)
|
||||||
|
|
||||||
if _, err := RunCommandWithoutTest(kanikoCmd); err != nil {
|
if _, err := RunCommandWithoutTest(kanikoCmd); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func RetrieveLayer(opts *config.KanikoOptions, cacheKey string) (v1.Image, error
|
||||||
// Destination returns the repo where the layer should be stored
|
// Destination returns the repo where the layer should be stored
|
||||||
// If no cache is specified, one is inferred from the destination provided
|
// If no cache is specified, one is inferred from the destination provided
|
||||||
func Destination(opts *config.KanikoOptions, cacheKey string) (string, error) {
|
func Destination(opts *config.KanikoOptions, cacheKey string) (string, error) {
|
||||||
cache := opts.Cache
|
cache := opts.CacheRepo
|
||||||
if cache == "" {
|
if cache == "" {
|
||||||
destination := opts.Destinations[0]
|
destination := opts.Destinations[0]
|
||||||
destRef, err := name.NewTag(destination, name.WeakValidation)
|
destRef, err := name.NewTag(destination, name.WeakValidation)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ type KanikoOptions struct {
|
||||||
Bucket string
|
Bucket string
|
||||||
TarPath string
|
TarPath string
|
||||||
Target string
|
Target string
|
||||||
Cache string
|
CacheRepo string
|
||||||
Destinations multiArg
|
Destinations multiArg
|
||||||
BuildArgs multiArg
|
BuildArgs multiArg
|
||||||
InsecurePush bool
|
InsecurePush bool
|
||||||
|
|
@ -32,5 +32,5 @@ type KanikoOptions struct {
|
||||||
SingleSnapshot bool
|
SingleSnapshot bool
|
||||||
Reproducible bool
|
Reproducible bool
|
||||||
NoPush bool
|
NoPush bool
|
||||||
UseCache bool
|
Cache bool
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (s *stageBuilder) build(opts *config.KanikoOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "getting key")
|
return errors.Wrap(err, "getting key")
|
||||||
}
|
}
|
||||||
if command.CacheCommand() && opts.UseCache {
|
if command.CacheCommand() && opts.Cache {
|
||||||
image, err := cache.RetrieveLayer(opts, cacheKey)
|
image, err := cache.RetrieveLayer(opts, cacheKey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := s.extractCachedLayer(image, command.String()); 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
|
return err
|
||||||
}
|
}
|
||||||
// Push layer to cache now along with new config file
|
// 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 {
|
if err := pushLayerToCache(opts, cacheKey, layer, command.String()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue